Red Hat 㧠Ansible ã®ã½ãªã¥ã¼ã·ã§ã³ã¢ã¼ããã¯ãããã¦ããä¸å³¶ã§ãããã¾ãã
æ¬ã¨ã³ããªã¼ã¯ Ansible Advent Calendar 2024 ã®6æ¥ç®ã®è¨äºã¨ãªãã¾ãã Ansible Advent Calendar 2024 ã«ã¯Ansible é¢ããæ§ã ãªTIPSããã¬ãã¸ãæ稿ããã¦ããã¾ãã®ãAnsible ã触ã£ã¦ããæ¹ã¯ãä¸èªããã ãã¨ãèªååã®ã¹ãããã¢ããã®ãã£ãããå¾ãããããããã¾ããã
ãã¦ãç¾å¨ã® Red Hat Ansible Automation Platform(以ä¸AAP) 㯠Playbook ãå®è¡ããããã«ã³ã³ããç°å¢(Execution Environment: 以ä¸EE)ã使ã£ã¦ãã¾ããEEã使ããã¨ã§è¤éåããã¢ã¸ã¥ã¼ã«ã®ä¾åé¢ä¿ãOSæ¬ä½ã¨ã¯åãé¢ãããéçºç°å¢ã§ã¯åããã®ã«ï¼ãã¨ããç¶æ³ã極åæãããã¨ãã§ãã¾ããããã¦ãEEã使ã£ãPlaybookéçºã®ããã®ä»çµã¿ã¨ãã¦ãansible-navigator
ã³ãã³ããããã¾ãã
ansible-navigator
㯠ansible-playbook
ã³ãã³ãã¨è¡¨é¢ä¸ã¯æ¦ãåãã§ããã大ããéãã®ãPlaybookãå®è¡ããããã«EEãå©ç¨ãã¾ããéçºã§ã¯ ansible-navigator
ã使ããæ¬çªã§ã¯AAPãå©ç¨ãããããã¦ãã®ã©ã¡ãã«ãåãEEã使ç¨ãããã¨ã§ãéçºã¨æ¬çªã®å·®ç°ããªãããPlaybookã®å®è¡ç°å¢ã«èµ·å ãããã©ãã«ãåæ¸ãããã¨ãã§ãã¾ããansible-navigator
ã使ãå ´åãPlaybook ã®å®è¡ã¯EEã¨ãããã³ã³ããã®ä¸ãã§å®è¡ãããèªåãæä½ãã¦ããéçºç°å¢ã®OSä¸ã®è¨å®ã¨ã¯ç¬ç«ãã¦åãã¾ããããã¯ç°å¢ã®ç¬ç«æ§ãæ
ä¿ããæå³ã§ã¯ä¾¿å©ãªåé¢ãå¥ã®é¨åã§ã¯ä¸ä¾¿ãªé¨åãåºã¦ãã¾ãããããæ
å ±ï¼å¤æ°ï¼ã®åã渡ãã§ãã
ä»åã¯ãansible-navigator
ã使ã£ã¦æ
å ±ãåã渡ããPlaybookéçºã®å¹çãé«ããæ¹æ³ã«ã¤ãã¦ç´¹ä»ãã¾ãï¼AAPä¸ã§ã¯ç°¡åã«è¨å®ãã¦å©ç¨ã§ããå種å¤æ°ãªã©ããansible-navigator
ã使ã£ãæã«ã©ãããããã¨ãã話ã ã¨æã£ã¦ãã ããï¼ã
ãããããæ¬é¡ã§ããä»å㯠AWS ãä¾ã«ãµã³ãã«ãè¦ãªããç´¹ä»ãã¾ãã
以ä¸ã®ãããªPlaybookãæºåãã¾ããããã¯AWS EC2ä¸ã®ã¤ã³ã¹ã¿ã³ã¹æ å ±ãåå¾ããPlaybookã§ãã
--- - hosts: all gather_facts: false tasks: - name: Gather information about all instances amazon.aws.ec2_instance_info: register: ret - debug: var=ret
ãããAAPã§ä½¿ãå ´åã¯ããAWSç¨ã®æå·åãããèªè¨¼ãªãã¸ã§ã¯ãããä½æãã¦ã¸ã§ãã«ã¢ã¿ããããã ãã§å®å ¨ã«å©ç¨ã§ãã¾ããã»ã»ã»ãã³ãã³ãã©ã¤ã³ã§ä½¿ãå ´åã«ã¯ä»¥ä¸ã®ããã«ãã¾ãã
ãã®AWSã¢ã¸ã¥ã¼ã«ç¨ã«å¿ è¦ãªç°å¢å¤æ°ãã»ãããã¦ããã¾ãã
export AWS_ACCESS_KEY=xxx export AWS_SECRET_KEY=yyy export AWS_REGION=ap-northeast-1
ã§ã¯ã¾ããansible-playbook
ã³ãã³ãã§å®è¡ãã¦ã¿ã¾ããã¤ã³ãã³ããªã¼ãã¡ã¤ã«ãæºåãã¦ããªãã®ã§ã-i localhost, -c local
ãªãã·ã§ã³ã§ã³ãã³ãã©ã¤ã³ã®ä¸ã§æ¥ç¶å
ã¨æ¥ç¶æ¹æ³ãæå®ãã¦ãã¾ãã
$ ansible-playbook -i localhost, -c local playbook.yaml PLAY [all] ******************************************************************** TASK [Gather information about all instances] ********************************* ok: [localhost] TASK [debug] ****************************************************************** ok: [localhost] => { "ret": { "changed": false, "failed": false, "instances": [ (çç¥) } } PLAY RECAP ******************************************************************** localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
åé¡ãªãå®è¡ã§ãã¦ãã¾ããã§ã¯ãåãæ¡ä»¶ã§ ansible-navigator
ã使ã£ã¦ã¿ã¾ãã
$ ansible-navigator run playbook.yaml -i localhost, -c local -m stdout -e 'ansible_python_interpreter=/usr/bin/python' PLAY [all] ********************************************************************* TASK [Gather information about all instances] ********************************** fatal: [localhost]: FAILED! => {"changed": false, "msg": "The amazon.aws.ec2_instance_info module requires a region and none was found in configuration, environment variables or module parameters"} PLAY RECAP ********************************************************************* localhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0 Please review the log for errors.
- Note: ä»åã®å©ç¨ãã¦ããEEã®ã¤ã¡ã¼ã¸
registry.redhat.io/ansible-automation-platform-25/ee-supported-rhel8
ã¯-c local
ã§æ¥ç¶ããã¨ãOS管çç¨ã®/usr/libexec/platform-python
ã使ç¨ããã¦ãã¾ããããæ示çã«/usr/bin/python
ã使ãããã«æå®ãã¦ãã¾ãã
èªè¨¼æ å ±ãåç §ã§ããªãããæ¥ç¶ã¨ã©ã¼ãããã¦ããã®ããããã¾ãã
ã§ã¯ãansible-navigator
ã«èªè¨¼æ
å ±ã渡ãã¦ã¿ã¾ããä¸çªç°¡åãªã®ã¯--senv
ãªãã·ã§ã³ã§ç°å¢å¤æ°ã¨ãã¦æ¸¡ãæ¹æ³ã§ãã
$ ansible-navigator run playbook.yaml -i localhost, -c local -m stdout -e 'ansible_python_interpreter=/usr/bin/python' --senv 'AWS_ACCESS_KEY=xxx' --senv 'AWS_SECRET_KEY=yyy' --senv 'AWS_REGION=ap-northeast-1' (çç¥) PLAY RECAP ******************************************************************** localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ãã¾ãåãã¾ãããå¥ã®æ¹æ³ã¨ãã¦ãç¾è¡ã·ã§ã«ã®å¤æ°ã渡ã --penv
ã¨ãããªãã·ã§ã³ãããã¾ãã
$ ansible-navigator run playbook.yaml -i localhost, -c local -m stdout -e 'ansible_python_interpreter=/usr/bin/python' --penv AWS_ACCESS_KEY --penv AWS_SECRET_KEY --penv AWS_REGION (çç¥) PLAY RECAP ******************************************************************** localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ãã¡ãããã¾ãåãã¦ãã¾ãã
-e
㯠extra_vars ã¨ã㦠ansible ã®å¤æ°ã¨ãã¦æ¸¡ããã--penv
--senv
ã¯ç°å¢å¤æ°ã¨ãã¦æ¸¡ããã¾ããä¼¼ã¦éãªããã®ãªã®ã§ãã©ã¡ãã§æ¸¡ãããã®ããã¢ã¸ã¥ã¼ã«ã®ä»æ§ã確èªããéããæèãã¦å©ç¨ã§ããã¨ãã©ãã«ãæ¸ãããã¨ãã§ãã¾ãã
ansible-playbook
ãã ansible-navigator
ã«ç§»è¡ããã¨ãç°å¢ã®ãã¼ã¹ãã³ã³ããã«ç§»ããã¨ã§ãAnsible ã§ã®æ¥ç¶ãèªè¨¼çã®åºæ¬çãªé¨åã§å¼ã£ããããã¨ãããããã¾ããç¹ã«èªè¨¼å¨ãã¯æåã®ã¤ã¾ã¥ããã¤ã³ãã§ãããããansible-navigator
ã§ã®éçºã§ãèªè¨¼å¨ãã§ãã¾ããããªããã¨ãããã°ãä»åç´¹ä»ããã³ãã³ãããEEã¸ã®æ
å ±ã®åã渡ãã«ã¤ãã¦ç¢ºèªãã¦ã¿ã¦ãã ããã