ãã㯠Ansible 2 Advent Calendar 2019 ã®5æ¥ç®ã®è¨äºã§ãã
ã¯ããã«
Ansible ã«ã¯ãå¤ã«å¯¾ãã¦æ§ã ãªå¦çããããã£ã«ã¿ã¼ãããã¾ãã
unique
ãã£ã«ã¿ã¼ã¯ããªã¹ãå
ã®è¦ç´ ã®éè¤ãæé¤ãã¦ã¦ãã¼ã¯ã«ãããã£ã«ã¿ã¼ã§ãã
ç°¡åãªãµã³ãã«ã§ãç´¹ä»ãã¾ãã
ãµã³ãã«
Playbook
ã¿ã¹ã¯ unique test 1
ã§ã¯ã 1
ã2ã¤ã3
ã3ã¤ããã¾ããããããã®éè¤ã¯æé¤ããã¾ãã
ã¿ã¹ã¯ unique test 2
ãä¼¼ã¦ãã¾ããã æ°åã® 1
ã¨ãã¯ã©ã¼ãã¼ã·ã§ã³ã§å²ã£ãæå '1'
ãããã¾ãã1
㨠'1'
ã¯å¥ç©ãªã®ã§ãéè¤æé¤ãããã«ç¹ã«å¤æ´ã¯å ãããã¾ããã
- hosts: localhost gather_facts: no tasks: - name: unique test 1 debug: msg: "{{ [1, 1, 2, 3, 3, 3, 4, 5] | unique }}" - name: unique test 2 debug: msg: "{{ [1, '1', 2, 3, 3, 3, 4, 5] | unique }}"
Playbook ã®å®è¡
Playbook ãå®è¡ãã¾ãã
$ ansible-playbook -i localhost, filter_test.yml PLAY [localhost] *************************************************************** TASK [unique test 1] *********************************************************** ok: [localhost] => { "msg": [ 1, 2, 3, 4, 5 ] } TASK [unique test 2] *********************************************************** ok: [localhost] => { "msg": [ 1, "1", 2, 3, 4, 5 ] } PLAY RECAP ********************************************************************* localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
unique test 1
ã§ã¯[1, 1, 2, 3, 3, 3, 4, 5]
ã[1, 2, 3, 4, 5]
ã«
unique test 2
ã§ã¯[1, '1', 2, 3, 3, 3, 4, 5]
ã[1, "1", 2, 3, 4, 5]
ã«
ã«ãªãã¾ããã
å°ãã ãå¿ç¨: count ãã£ã«ã¿ã¼ã¨çµã¿åããã
count
ã¨çµã¿åãããã¨ã éè¤æé¤ã®ä»¶æ°ãã«ã¦ã³ãåºæ¥ã¾ãã
SQL ã® distinct
㨠count
ã¨çµåããããããªã¤ã¡ã¼ã¸ã§ãã
å ·ä½çãªä¾ã¨ãã¦ã¯
msg: "{{ [1, 1, 2, 3, 3, 3, 4, 5] | unique | count }}"
ã®çµæã¯ã
"msg": "5"
ã«ãªãã¾ãã
ã¾ã¨ã
ãªã¹ãå
ã®è¦ç´ ã®éè¤ãæé¤ãã¦ã¦ãã¼ã¯ã«ãã unique
ãã£ã«ã¿ã¼ããç´¹ä»ãã¾ããã
ä»ã«ãè²ã ãªãã£ã«ã¿ã¼ãããã®ã§ãå ¬å¼ããã¥ã¡ã³ããçºãã¦ã¿ãã¨ãæ°ããªçºè¦ãããããããã¾ããã