ãã㯠Ansible 2 Advent Calendar 2019 ã®7æ¥ç®ã®è¨äºã§ãã
ã¯ããã«
Playbook 㯠YAML ã¨ãããã©ã¼ãããã§è¨è¿°ãã¾ããã¨ãã©ãããã¹ã«ãã£ã¦ YAML ã®ãã£ã¯ã·ã§ããªã®ãã¼ã®éè¤ãã¦æ¸ãã¦ãã¾ããã¨ããããã¨æãã¾ãã ããã¾ã§ã¯ãã¼ã®éè¤æã¯ãè¦åã表示ãããä¸ã§å¦çãç¶ç¶ããã¨ããä»æ§ã§åºå®ã§ãããããã®ããããã¨ããå®ç¾©ããå¤ãåªå ããã¦å®è¡ããããªã©ã®æ³å®å¤ã®çµæãå¼ãèµ·ããã¦ãã¾ãæããããã¾ãããå人çã«ã¯ããã£ãã®ãã¨ã¨ã©ã¼ã«ãã¦ã»ãããªã¨æã£ã¦ãã¾ããã
Ansible 2.9 ã§è¿½å ããããDUPLICATE_YAML_DICT_KEY
ã¨ããè¨å®ã§é¸ã¹ãããã«ãªãã¾ããã
ãã®è¨äºã§ã¯ãç°¡åãªä¾ããã¨ã«èª¬æãã¾ãã
- åä½ç¢ºèªç°å¢
- Ansible 2.9.1
â é¸ã¹ãè¦åé¡ã®ç¨®é¡
DUPLICATE_YAML_DICT_KEY
ã§ã¯ããã¼ã®éè¤æã®è¦åé¡ã3種é¡ã®ä¸ããé¸ã¹ã¾ã
è¨å®å¤ | åä½ |
---|---|
error |
ã¨ã©ã¼ã表示ãã¦ãPlaybook ã®å®è¡ãä¸æã |
warn |
è¦åï¼WARNINGï¼è¡¨ç¤ºãã¦ãPlaybook ã®å®è¡ãç¶è¡ãæå¾ã«å®ç¾©ããå¤ãå©ç¨ãããã©ã«ãã®è¨å®ã |
False |
ç¹ã«ä½ã表示ããã«ãPlaybook ã®å®è¡ãç¶è¡ãæå¾ã«å®ç¾©ããå¤ãå©ç¨ã |
â æ¤è¨¼
error
ãwarn
ãFalse
ãããããæ¤è¨¼ãã¾ãã
æ¤è¨¼ç¨ Playbook
以ä¸ã® 2 種é¡ã® Playbook ãæ¤è¨¼ã«å©ç¨ãã¾ãã
Playbook1: ã¢ã¸ã¥ã¼ã«ãªãã·ã§ã³ã®éè¤
debug
ã¢ã¸ã¥ã¼ã«ã® msg
ãªãã·ã§ã³ãæå³çã«éè¤ããã¦ãã¾ãã
- hosts: localhost gather_facts: no tasks: - name: debug test debug: msg: ryukin msg: demekin
Playbook2: å¤æ°å®ç¾©ã®éè¤
å¤æ° debug
ã®å®ç¾©ãæå³çã«éè¤ããã¦ãã¾ãã
- hosts: localhost gather_facts: no vars: kind: ryukin kind: demekin tasks: - name: debug test debug: msg: "{{ kind }}"
æ¤è¨¼1: error
ã®å ´å
DUPLICATE_YAML_DICT_KEY
ã error
ã«æå®ããå ´åã§ãã
ãã¼ã®éè¤ãæ¤åºããå ´åã¯ã¨ã©ã¼ã§å¦çãæ¢ã¾ãè¨å®ã§ãã
ansible.cfg
ã§ä»¥ä¸ã®æå®ãã¾ãã
[defaults] duplicate_dict_key = error
以ä¸ãå Playbook ã®å®è¡çµæã§ãã
- ãPlaybook1: ã¢ã¸ã¥ã¼ã«ãªãã·ã§ã³ã®éè¤ãã®å®è¡
$ ansible-playbook -i localhost, duplicate.yml ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object has no attribute 'line'
ã¡ãã£ã¨ãã³ã¨ããªãã¡ãã»ã¼ã¸ã§ãããERROR ã¨ããã° ERROR ã§ãã
- ãPlaybook2: å¤æ°å®ç¾©ã®éè¤ãã®å®è¡
$ ansible-playbook -i localhost, duplicate.yml ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object has no attribute 'line'
ãã¡ãã Playbook 1 ã¨åãã§ããã
è¨å®ãå¤æãã¦ãã®ã¯ãã®ãããã®ã³ã¼ãããã§ãã
ããã¾ã§ãã error
ã®æ¤è¨¼ã§ããã
æ¤è¨¼2: warn
ã®å ´åãï¼ããã©ã«ãï¼
DUPLICATE_YAML_DICT_KEY
ã warn
ã«æå®ããå ´åã§ããããã©ã«ãããããªã®ã§ãç¹ã«æå®ããªãã¦ãåãã§ãã
ãã¼ã®éè¤ãæ¤åºããå ´å㯠WARNING
ã表示ãããå¦çã¯ç¶ç¶ããè¨å®ã§ããæå¾ã«å®ç¾©ããå¤ãå©ç¨ããã¾ãã
ä»åã¯æ示çã« ansible.cfg
ã§ä»¥ä¸ã®æå®ãã¾ãã
[defaults] duplicate_dict_key = warn
- ãPlaybook1: ã¢ã¸ã¥ã¼ã«ãªãã·ã§ã³ã®éè¤ãã®å®è¡
$ ansible-playbook -i localhost, key_dup_option.yml [WARNING]: While constructing a mapping from /vagrant/a29/key_dup_option.yml, line 7, column 9, found a duplicate dict key (msg). Using last defined value only. PLAY [localhost] ********************************************************************************** TASK [debug test] ********************************************************************************* ok: [localhost] => { "msg": "demekin" â æå¾ã«å®ç¾©ãã msg ã®å¤ } PLAY RECAP **************************************************************************************** localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
msg
ãéè¤ãã¦ããã®ã§ãæå¾ã«å®ç¾©ããå¤ã使ãããã¨ãã WARNING
ã表示ãããå¦çèªä½ã¯å®è¡ããã¾ããã
- ãPlaybook2: å¤æ°å®ç¾©ã®éè¤ãã®å®è¡
]$ ansible-playbook -i localhost, key_dup_var.yml [WARNING]: While constructing a mapping from /vagrant/a29/key_dup_var.yml, line 6, column 5, found a duplicate dict key (kind). Using last defined value only. PLAY [localhost] ********************************************************************************** TASK [debug test] ********************************************************************************* ok: [localhost] => { "msg": "demekin" â æå¾ã«å®ç¾©ãã kind å¤æ°ã®å¤ } PLAY RECAP **************************************************************************************** localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ãã¡ãã Playbook 1 ã¨åãã§ããã
ããã¾ã§ãã warn
ï¼ããã©ã«ãï¼ ã®æ¤è¨¼ã§ããã
æ¤è¨¼3:False
ã®å ´å
æå¾ã«ãDUPLICATE_YAML_DICT_KEY
ã False
ã«æå®ããå ´åã§ãã
ãã¼ã®éè¤ãæ¤åºãã¦ããã¨ã©ã¼ã«ããªãã WARNING
ã表示ããããä½äºããªãã£ãããã«å¦çãããè¨å®ã§ããæå¾ã«å®ç¾©ããå¤ãå©ç¨ããã¾ãã
ansible.cfg
ã§ä»¥ä¸ã®æå®ãã¾ãã
[defaults] duplicate_dict_key = False
- ãPlaybook1: ã¢ã¸ã¥ã¼ã«ãªãã·ã§ã³ã®éè¤ãã®å®è¡
$ ansible-playbook -i localhost, key_dup_option.yml PLAY [localhost] ********************************************************************************** TASK [debug test] ********************************************************************************* ok: [localhost] => { "msg": "demekin" â æå¾ã«å®ç¾©ãã msg ã®å¤ } PLAY RECAP **************************************************************************************** localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ä½äºããªãã£ãããã«å®è¡ããã¾ãããæå¾ã«å®ç¾©ãã msg: demekin
ã表示ããã¾ããã
- ãPlaybook2: å¤æ°å®ç¾©ã®éè¤ãã®å®è¡
$ ansible-playbook -i localhost, key_dup_var.yml PLAY [localhost] ********************************************************************************** TASK [debug test] ********************************************************************************* ok: [localhost] => { "msg": "demekin" â æå¾ã«å®ç¾©ãã kind å¤æ°ã®å¤ } PLAY RECAP **************************************************************************************** localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ãã¡ãã Playbook 1 ã¨åãã§ããã
ãªããã³ã¼ããè¦ãæãã¯ãå®é㯠False
ã ãã§ãªãããerror
ã§ã warn
ã§ããªãå¤ããè¨å®ãããå ´åã«ãä½ã表示ããªãã¨ãã£ãä»æ§ã®ããã§ããããã¥ã¡ã³ãä¸ã¯
These warnings can be silenced by adjusting this setting to False. ã¨è¨è¼ããã£ãã®ã§
False
ã§æ¤è¨¼ãã¾ããã
ããã¾ã§ãã False
ã®æ¤è¨¼ã§ããã
â ã¾ã¨ã
YAML ã®ãã¼ãéè¤ãã¦ããå ´åã®ãæåãè¨å®ã§ãã DUPLICATE_YAML_DICT_KEY
ã«ã¤ãã¦æ¤è¨¼ãã¾ããã
-ï¼åæ²ï¼
è¨å®å¤ | åä½ |
---|---|
error |
ã¨ã©ã¼ã表示ãã¦ãPlaybook ã®å®è¡ãä¸æã |
warn |
è¦åï¼WARNINGï¼è¡¨ç¤ºãã¦ãPlaybook ã®å®è¡ãç¶è¡ãæå¾ã«å®ç¾©ããå¤ãå©ç¨ãããã©ã«ãã®è¨å®ã |
False |
ç¹ã«ä½ã表示ããã«ãPlaybook ã®å®è¡ãç¶è¡ãæå¾ã«å®ç¾©ããå¤ãå©ç¨ã |
è£è¶³
ã§ãããã¨ãªãããã®è¨å®ã«é ¼ãããYAML ã®ãã¼ã®éè¤ã¯å®è¡åã«æ°ã¥ãã¦ä¿®æ£ãã¦ãããããã®ã§ãã ãã¨ãã° VSCode ãªã©å¤æ©è½ãªã¨ãã£ã¿ãå©ç¨ããã°ã以ä¸ã®ããã«æ°ã¥ããã¦ããã¾ãã