ã¬ãããããã®ææã§ããAnsible ã®ãã¯ãã«ã«ãµãã¼ãããã¦ãã¾ããæ¯æ1ã¤ã¯ä½ãæ¸ããã¨ãç®æ¨ã«ãã¦ãã¾ãã5æããã£ã¨ããéã«å»ã£ã¦ãã¾ãã¾ãã¦ã5æ34æ¥(6æ3æ¥) ã¨ãããã¨ã«ããã¦ãã ããã
ããã¾ã§2åã«åãã¾ãã¦ãAnsible ã§æ±ãå¤æ°ã«ã¤ãã¦ç´¹ä»ãã¾ããã
ããã¾ã§ã¯ã³ãã³ãã©ã¤ã³ãã ansible-playbook ãå®è¡ããä¾ãè¦ã¦ãã¾ããããAnsible automation controller ã§ã¯ããå°ã è¤éãªå¤æ°ã®åã渡ããã§ãã¾ãã2ã¤ã®æ¹æ³ã«ã¤ãã¦ç´¹ä»ãã¦ããã¾ãã
Ansible Automation Platform 2.2 (Ansible automation controller 4.2.0) ãå©ç¨ããä¾ã§èª¬æãã¦ããã¾ãã
set_stats
ã¯ã¼ã¯ããã¼ã¸ã§ããã³ãã¬ã¼ããå®ç¾©ãã¦ãè¤æ°ã®ãã¬ã¤ããã¯ã®å®è¡ã®éã§å¦ççµæã次ã®ãã¬ã¤ããã¯ã«å¼ãç¶ããããã¨ãããã¨æãã¾ãã
ç°¡åãããä¾ã§æ縮ã§ããããã®ãããªã¯ã¼ã¯ããã¼ãèãã¦ã¿ã¾ããæååãå¼ãç¶ãããã¨ãããã¨ã ãã®ä¾ãªã®ã§ãå 容ã®å¦¥å½æ§ã«ã¤ãã¦ã¯ããã§ã¯æ°ã«ããªãã§ãã ããã
ã¸ã§ããã³ãã¬ã¼ãA
- ãã¹ã¯ã¼ãæååãå¤é¨å¤æ°ã¨ãã¦åãåã
- 管ç対象ã«ãã¹ã¯ã¼ããè¨å®ãã
- ãã¹ã¯ã¼ãæååã次ã®ã¸ã§ããã³ãã¬ã¼ãã§ä½¿ããããã«ãã
--- - hosts: all gather_facts: false vars: service_account: ansible tasks: - name: store a password for further use set_stats: data: service_account_password: "{{ password_string }}" aggregate: false - name: change a password for a service account user: name: "{{ service_account }}" state: present password: "{{ password_string | password_hash('sha512', 65534 | random(seed=inventory_hostname) | string) }}" become: true
set_stats: ã§ã¯ aggregate: false
ãæå®ãã¾ããããããæå®ããªãå ´åã¯ããã©ã«ãã® true
ã¨ãªããå¼ã³åºããæ°ã ãæååãé£çµããã¦ãã¾ãã¾ãã
ã¸ã§ããã³ãã¬ã¼ãB
- ã¸ã§ããã³ãã¬ã¼ãAãããã¹ã¯ã¼ãæååãåãåã
- 管ç対象ã«ã¢ã¯ã»ã¹ãã¦hostnameã³ãã³ããå®è¡ãã
--- - hosts: all gather_facts: false vars: ansible_user: ansible ansible_password: "{{ service_account_password }}" tasks: - name: run something command: hostname register: result - name: debug debug: var: result
ã¯ã¼ã¯ããã¼
ã¯ã¼ã¯ããã¼ã§ã¯ survey ãå®ç¾©ãã¦ãå®è¡æã«å ¥åãåãä»ããããã«ãã¾ããã
å®è¡çµæ
ã¯ã¼ã¯ããã¼ã¸ã§ããã³ãã¬ã¼ããèµ·åããã¨å ¥åãæ±ããããã®ã§é©å½ã«å ¥ãã¾ãã
ç¡äºå®è¡ããã¾ããã
ãã®ã¨ãããããã®ã¸ã§ããã³ãã¬ã¼ãã®çµæãè¦ãã¨ã1ã¤ç®ã®ã¸ã§ããã³ãã¬ã¼ã㧠set_stats ã§æ ¼ç´ãããå¤æ° service_account_password
ã®å¤ã Artifacts ã¨ãã¦ä¿åããã¦ã2ã¤ç®ã®ã¸ã§ããã³ãã¬ã¼ãã®å¤é¨å¤æ°ã¨ãã¦æ¸¡ã£ã¦ãããã¨ããããã¾ãã
å ¥åããæååã¯é ãããã¨ãããã¨ã¯ããã§ãããããããã§ã¯æ¬é¡ã§ã¯ããã¾ããã
ããã§ã¯ set_stats ã¢ã¸ã¥ã¼ã«ã§ Artifacts ã¨ãã¦ä¿åããã¦ãå¤é¨å¤æ°ã«æ¸¡ã£ã¦ããã¨ãããã¨ã示ãããã£ãã§ãã
set_fact
å ã»ã©ã®ä¾ã§ã¯ãã¸ã§ããã³ãã¬ã¼ãã§çæããå¤æ°ã次ã®ã¸ã§ããã³ãã¬ã¼ãã«å¤é¨å¤æ°ã¨ãã¦æ¸¡ãããã¨ããããã¾ããã
ããããã100å°ãã£ãå ´åãèãã¦ã¿ã¾ããä»åã®ä¾ã§ã¯åç´ãª1ã¤ã®å¤æ°ã§ãããã100å°å¥ã ã«è¨å®ãããã¨ãããã¨ã«ãªãã¨ãå¤é¨å¤æ°ã¨ãã¦100å°åã®ãã¼ã¿ããªã¹ãã«ãã¦ä½æããå¾æ®µã®ã¸ã§ããã³ãã¬ã¼ãã§ã¯æ¸¡ã£ã¦ãã100å°åã®ãã¡è©²å½ãããã®ãé¸æãã¦ä½¿ãã¨ããå¦çãå¿ è¦ã¨ãªã£ã¦ãã¾ãã¾ãã
Ansible ã§ã¯ fact ã®ä»çµã¿ãããã¾ãã¦ã以åã®è¨äºã¾ã§ã§åºã¦ãããããªã¤ã³ãã³ããªã«è¨å®ãããã¹ãå¤æ°ã«å¯¾ãã¦åçã«æ ¼ç´ãããã¨ãã§ãã¾ããããã«ããã100å°ã§ãä½å°ã§ãã£ã¦ãã·ã³ãã«ã«ãã¬ã¤ããã¯ãå®è£ ãããã¨ãã§ãã¾ãã
å ã»ã© set_stats ã§å®è£ ãããã®ããset_fact ã§æ¸ãæãã¦ã¿ã¾ãããä»åã¯ãã¹ã¯ã¼ãæååãå¤ããä¸ããã®ã§ã¯ãªãããã¬ã¤ããã¯ã®ä¸ã§ãã¹ããã¨ã«ã©ã³ãã ã«çæãã¦ãã¾ãã
ã¸ã§ããã³ãã¬ã¼ãA
- ãã¹ã¯ã¼ãæååãã©ã³ãã ã«çæãã
- 管ç対象ã«ãã¹ã¯ã¼ããè¨å®ãã
- ãã¹ã¯ã¼ãæååã次ã®ã¸ã§ããã³ãã¬ã¼ãã§ä½¿ããããã«ãã
--- - hosts: all gather_facts: false vars: service_account: ansible tasks: - name: generate a password set_fact: service_account_password: "{{ lookup('password', '/dev/null', seed=inventory_hostname) }}" cacheable: true - name: change a password for a service account user: name: "{{ service_account }}" state: present password: "{{ service_account_password | password_hash('sha512', 65534 | random(seed=inventory_hostname) | string) }}" become: true
set_fact: ã§ã¯ cacheable: true
ãæå®ãã¦ãã ãããã¸ã§ããã³ãã¬ã¼ãã§ã Enable Fact Storage
ãªãã·ã§ã³ãæå¹ã«ãããã¨ã§ããã¬ã¤ããã¯ãã fact ãã¼ã¿ã¸ã®èªã¿æ¸ããã§ããããã«ãªãã¾ãã
ã¸ã§ããã³ãã¬ã¼ãB
- ã¸ã§ããã³ãã¬ã¼ãAãããã¹ã¯ã¼ãæååãåãåã
- 管ç対象ã«ã¢ã¯ã»ã¹ãã¦hostnameã³ãã³ããå®è¡ãã
--- - hosts: all gather_facts: false vars: ansible_user: ansible ansible_password: "{{ ansible_facts.service_account_password }}" tasks: - name: run something command: hostname register: result - name: debug debug: var: result
å¤é¨å¤æ°ããåãåãã®ã§ã¯ãªããansible_facts
ããåãåã£ã¦ãã¦ãã¾ããããã使ãã¸ã§ããã³ãã¬ã¼ãã§ãåæ§ã« Enable Fact Storage
ãªãã·ã§ã³ãæå¹ã«ãã¦ããã¦ãã ããã
å®è¡çµæ
ãã®ã¯ã¼ã¯ããã¼ã¸ã§ããã³ãã¬ã¼ãã2å°ã®ãã¹ããå®ç¾©ããã¤ã³ãã³ããªã¼ãæå®ãã¦å®è¡ãã¦ã¿ã¾ããã
ããããã®ã¸ã§ããã³ãã¬ã¼ãã§ã¯å ¥åºåãããã¾ããã®ã§ãVariables ã Artifacts ã¯ç©ºã§ãã
fact ãã¼ã¿ã¯ãã¤ã³ãã³ããªã¼ãããã¹ãããã©ãã¨è¦ããã¨ãã§ãã¾ããçæããæååããã¹ãã®ããããã§å¥ã ã«æ ¼ç´ããã¦ãããã¨ããããã¾ãã
çµããã«
ä»å㯠Ansible ã®å¤æ°ãè¤æ°ã®ã¸ã§ãã§åã渡ãããæ¹æ³ã«ã¤ãã¦ç´¹ä»ãã¾ããã
ã¾ã¨ãã¦ä¸ã¤ã®å¤é¨å¤æ°ã¨ãã¦æ¸¡ãããã¨ã㯠set_stats
ã使ãããã¹ããã¨ã«å¥ã
ãªå¤ãè¨å®ãã¦ä½¿ãããã¨ã㯠set_fact
ã使ããã¨ãã§ãã¾ãã
fact ã®ãã¼ã¿ã¯ãã¬ã¤ããã¯ã®å
é 㧠gather_facts: true
ã¨æ¸ããã¨ãã« setup ã¢ã¸ã¥ã¼ã«ãå®è¡ãã¦æ
å ±åéãããçµæãããã¤ãããã¯ã¤ã³ãã³ããªã§ã¯ã©ã¦ããµã¼ãã¹ãã API ã§åå¾ããæ
å ±ãªã©ãæ ¼ç´ããã¾ããå°ã
使ãæ¹ãè¨å®ãè¤éãªã¨ãããããã¾ãããautomation controller ä¸ã§ä½¿ããã¨ã«ãã£ã¦ä¾¿å©ã«ã使ãããã ãããã®ã¨æãã¾ãã
Ansible Automation Platform ã®è©¦ç¨çã¯ãã¡ããã覧ãã ããã
Happy Automation!