ãä¼ãããããã¨
ãã®è¨äºã¯Ansible Advent Calendar 2024ã®11æ¥ç®ã®è¨äºã§ãã
Ansibleã§Linuxãã¯ã©ã¦ãããããã¯ã¼ã¯æ©å¨ã®è¨å®å¤æ´ãèªååã§ããã®ã¯å¨ç¥ã®ã¨ããã§ãããæ
å ±åå¾ã®æ©è½ãå
å®ãã¦ãã¾ãã
å
å®...ãã¦ãã¾ãããæ©è½ãå¤ããã¦ããããããã¨1ã¤ã«å¯¾ãã¦å®ç¾æ段ã2ã¤ã3ã¤ãåå¨ãããç¶æ³ã«ãªã£ã¦ãã¾ãã
ä¸ä½ç§ãã¡ã¯ã©ã®æ©è½ã使ãããã®ã§ããããï¼
ç§èªèº«ãã¾ãç解ã§ãã¦ããªãã£ãã®ã§ããã®å ´ã§ã¾ã¨ãã¦ã¿ããã¨æãã¾ãã
- ãä¼ãããããã¨
- ãµããªè¡¨
- èªåã使ãããæ©è½ãè¦ã¤ãã
- æªå å·¥ã®showã³ãã³ããã°ãåå¾ãã
- showã³ãã³ããã°ãæ§é åãã¼ã¿ã«å¤æããæ´»ç¨ãã
- (åè) æ§é åãã¼ã¿ã¸ã®å¤æã®ã¤ã¡ã¼ã¸
- ã¦ã¼ã¹ã±ã¼ã¹ (2) showã³ãã³ããæ§é åãããã®ã¯ã©ããªå ´é¢ï¼
- å®è¡ä¾ (2-1) ãã¼ãµã使ãå ´å
- å®è¡ä¾ (2-2) network resource moduleã使ãå ´å
- (åè) cli_parseã¢ã¸ã¥ã¼ã«ã®æ¦è¦èª¬æ
- å®è¡ä¾ (2-3) gather_subsetã使ãå ´å
- ãããã«
ãµããªè¡¨
ä¸è¡¨ã«NWæ©å¨ã®ã¹ãã¼ã¿ã¹æ
å ±ãåå¾ããæ¹æ³ãã¾ã¨ãã¾ãã
åå¾ã§ããæ
å ±ã¯å¤§ããåãã¦ï¼ç¨®é¡ããã¾ãã
ãã£ã¨å¤§ããåããã¨ã(1)ã®æååãã¼ã¿ã¨(2-1)ã(2-3)ã®æ§é åãã¼ã¿ã®2ã¤ã«å¤§å¥ã§ãã¾ãã
(â») æ¬è¨äºã§ã¯ä¾ç¤ºã«Arista EOSã使ãã¾ã
èªåã使ãããæ©è½ãè¦ã¤ãã
以éã®ã»ã¯ã·ã§ã³ã§ã¯ãããã¤ãã®å
·ä½çãªã¦ã¼ã¹ã±ã¼ã¹ã«åºã¥ãã¦ä¸è¡¨ã®æ©è½ãé¸æããå®è¡çµæã示ãã¦ããã¾ãã
å°ãã§ãã¤ã¡ã¼ã¸ã湧ãããããªãã°å¹¸ãã§ãã
æªå å·¥ã®showã³ãã³ããã°ãåå¾ãã
showã³ãã³ãã®åºåããã®ã¾ã¾è¦ãããã¡ã¤ã«ã«ä¿åãããã¨ãã¯ã#ãµããªè¡¨ã® ã(1) showã³ãã³ããã®ã¾ã¾ã ã®æ©è½ã使ç¨ãã¾ãã
ã¦ã¼ã¹ã±ã¼ã¹ (1) showã³ãã³ããæªå å·¥ã§ä¿åãããã®ã¯ã©ããªå ´é¢ï¼
ãããã¯ã¼ã¯æ©å¨ã®showã³ãã³ãåºåçµæãå å·¥ãããã®ã¾ã¾ãã¡ã¤ã«ã«ä¿åãããã±ã¼ã¹ã¨ãã¦ãç§ã®ä¸ã§ã¯ä»¥ä¸ã®2ç¹ãæãå½ããã¾ãã
- ä½æ¥ãã¡ã³ããã³ã¹åå¾ã§å¯¾è±¡æ©å¨ã«showã³ãã³ããAnsibleã§ä¸æ¬å®è¡ããå®è¡çµæããã¡ã¤ã«ä¿åããããã¡ã¤ã«ãç®è¦ã§ç¢ºèªãã¦ä½æ¥ã®æå¦ãå¤æãã (ã³ãã³ãå®è¡ã®ã¿èªååã確èªã¯ããã¥ã¢ã«)
- Ansibleã§ã³ã³ãã£ã°ãå®æçã«ä¸æ¬åå¾ã»ãã¡ã¤ã«ä¿åãããä½æ¥è ã¯å¿ è¦ãªã¨ãã«ã³ã³ãã£ã°ãåç §ããè¨è¨æ¥åãªã©ã«æ´»ç¨ãã
ãããã®ã¦ã¼ã¹ã±ã¼ã¹ãæºããAnsibleã®å ·ä½çãªå®è£ æ¹æ³ã次ã®ã»ã¯ã·ã§ã³ã§è¦ã¦ããã¾ãããã
å®è¡ä¾ (1) arista.eos.eos_command module
arista.eos.eos_command moduleã§showã³ãã³ããå®è¡ããçµæãè¨é²ããä¾ã示ãã¾ãã
ä»åã¯show running-config
ãå®è¡ãããããã¯ã¼ã¯æ©å¨ã®ã³ã³ãã£ã°ã表示ãã¾ãã
ä¾ç¤ºã§ã¯ansible.builtin.debug
ã¢ã¸ã¥ã¼ã«ã§ã³ãã³ãåºåãç»é¢è¡¨ç¤ºãã¦ãã¾ãããå®éã«æ¥åã§ä½¿ãéã¯ansible.builtin.copy
ã¢ã¸ã¥ã¼ã«ãªã©ã«ç½®ãæãã¦ãã¡ã¤ã«ä¿åããæ³å®ã§ãã
- name: Retrieve Arista EOS config hosts: eos gather_facts: false tasks: - name: Execute show running-config arista.eos.eos_command: commands: - show running-config register: _eos_show_running_config_result - name: Debug _eos_show_running_config_result ansible.builtin.debug: msg: '{{ _eos_show_running_config_result.stdout }}'
以ä¸ã«å®è¡çµæã示ãã¾ãã
TASK [Debug _eos_show_running_config_result] *** ok: [veos1] => msg: - |- ! Command: show running-config ! device: veos1 (vEOS-lab, EOS-4.26.5M) ! ! boot system flash:/vEOS-lab.swi ! enable password sha512 $6$xxxxxx # ãã¹ã¯ãã¾ãã no aaa root # ...
showã³ãã³ããã°ãæ§é åãã¼ã¿ã«å¤æããæ´»ç¨ãã
showã³ãã³ãã®å®è¡çµæãæ§é åãã¼ã¿ã«å¤æãããã¨ãã¯ã#ãµããªè¡¨ã®(2-1)ã(2-3)ã®æ©è½ã使ç¨ãã¾ãã
- (2-1) ãã¼ãµå©ç¨
- (2-2) network resource module
- (2-3) gather_subset
(åè) æ§é åãã¼ã¿ã¸ã®å¤æã®ã¤ã¡ã¼ã¸
ãæ§é åãã¼ã¿ã¸ã®å¤æãã®ã¤ã¡ã¼ã¸ãè£è¶³ã¨ãã¦èª¬æãã¾ãã
æ¢ã«ç¥ã£ã¦ããæ¹ã¯èªã¿é£ã°ãã¦ãã ããã
ãæ§é åãã¼ã¿ã¸ã®å¤æããã©ã®ãããªãã®ããç解ããã«ã¯ãå®éã«åãã¦ããã¨ãããè¦ãã®ãä¸çªã§ãã
以ä¸ã®ãããã¯ã¼ã¯æ§æãä¾ã«ãã¾ãã
Arista vEOSã¹ã¤ããã3å°æ¥ç¶ããã¦ãã¾ãã
veos1
ã§show interface description
ãå®è¡ããã¤ã³ã¿ã¼ãã§ã¼ã¹ã®ã¹ãã¼ã¿ã¹ã確èªãã¾ãã
Interface Status Protocol Description Et1 up up veos2 Et1 Et2 up up veos3 Et1
ãããæ§é åãã¼ã¿ã«å¤æããã¨ã以ä¸ã®ãããªãã¼ã¿æ§é ã«ãªãã¾ãã
å©ç¨ãããã¼ãµã«ãã£ã¦ãã¼ã¿æ§é ã¯å¤ããã¾ãããåºæ¬çã«ã¯list
ã¨dict
ã®ãã¹ãæ§é ã«ãªãã¾ãã
ä¾ãã°ntc_templates
ãTextFSM
ãå©ç¨ããå ´åã¯ä»¥ä¸ã®ãããªãã¼ã¿æ§é ã«ãªãã¾ãã
(â») ãã¼ãµã¨ã¯ãæååãæ§é åãã¼ã¿ã¨ãã¦è§£éããããã°ã©ã ã®ãã¨ã§ããæ¬è¨äºã®æèã§ã¯æååãæ§é åããããã°ã©ã ã¨æã£ã¦å·®ãæ¯ãããã¾ãããntc_templates
ãTextFSM
ã¯æ£è¦è¡¨ç¾ã§å®è£
ããã¦ãã¾ã
interfaces: - port: Et1 status: up protocol: up description: veos2 Eth1 - port: Et2 status: up protocol: up description: veos3 Eth1
æ§é åãããã¨ã§ãç¹å®ã®å¤ãåãåºãããã¨ãé常ã«å®¹æã«ãªãã¾ãã
ä¾ãã°Et1
ã®status
ã¯{{ interfaces.0.status }}
ã{{ (interfaces.selectattr("port", "eq", "Et1"))["status"] }}
ã§åãåºãã¾ãã
å¾è
ã®åç
§æ¹æ³ã¯ä¸è¦ããã¨é£ããæããããããã¾ããã
ããããåããã¼ãµã使ãéãã©ã®showã³ãã³ãã§ãåºæ¬çã«åãæ¹æ³ã§ãã¼ã¿ãåãåºãããã®ã§ãåæ対象ã®showã³ãã³ããä»å¾å¢ããå ´åãåããã£ã«ã¿ã使ãåãã¾ãã
æ§é åããã¦ããªããã¼ã¿ãé½åº¦grep
ãansible.builtin.regex_search filterã§é½åº¦æ´å½¢ãããããé¥ãã«å°ãªãæéã§ãã¼ã¿ãæ§é åã§ãã¾ãã
...話ãå°ãé¸ãã¾ãããããã¼ã¿ãæ§é åã§ããã°å¤¢ãããªãåºããã¾ãã
æ§é åããããã¼ã¿ãå¤æ°ã«æ ¼ç´ãã¦è¿½å ã®ãã¸ãã¯ãçµããã®ã§ãã
ä¾ãã°ã以ä¸ã®ãããªå¦çãèãããã¾ãã
- Et1ãupãªãä½ããããdownãªãã¨ã©ã¼ã¡ãã»ã¼ã¸ãåºåãã (â showã³ãã³ãã®å®è¡ã ãã§ãªã確èªã¾ã§èªååã§ãã)
- ansible.builtin.templateã¢ã¸ã¥ã¼ã«ã§è¡¨ãã¬ãã¼ããèªåçæ (â ã¹ãã¼ã¿ã¹å¯è¦åãã¬ãã¼ãèªåçæ)
2ã®å
·ä½ä¾ãæãã¾ãã
ä¸è¿°ã®list of dict
å½¢å¼ã«æ§é åããããã¼ã¿ãinputã«ãtemplate
ã¢ã¸ã¥ã¼ã«ã使ãã°ä»¥ä¸ã®markdownã容æã«çæã§ãã¾ãã
(â») ä½è«ã§ãããlist of dictã¯æ¬è³ªçã«ã¯è¡¨ã¨åãæ§é ã®ãã¼ã¿ãªã®ã§ãããªã®ã§è¡¨å½¢å¼ã«å¤æãããã¨ã¯æ¬å½ã«ç°¡åã§ã
| port | status | protocol | description | | ---- | ------ | -------- | ----------- | | Et1 | up | up | veos2 Eth1 | | Et2 | up | up | veos3 Eth1 |
é©åãªãã¼ã«ã§markdownãhtmlåããã¨ã以ä¸ã®ãããªè¦ãç®ã®è¡¨ã«ãªãã¾ãã
showã³ãã³ããã°ãæ§é åããæ´å½¢ãããã¨ã§è¦ããã表ãçæã§ãã¾ããã
ã¦ã¼ã¹ã±ã¼ã¹ (2) showã³ãã³ããæ§é åãããã®ã¯ã©ããªå ´é¢ï¼
#æ§é åãã¼ã¿ã¸ã®å¤æã®ã¤ã¡ã¼ã¸ã§æ¢ã«è§¦ããã¨ãããç§ãæãã¤ãã¦ã¼ã¹ã±ã¼ã¹ã¯ä»¥ä¸ã®2ç¹ã§ãã
- ã³ãã³ãå®è¡ã ãã§ãªããå®è¡çµæã®ç¢ºèªã¾ã§èªååãã
- ã³ãã³ãå®è¡çµæãæ´å½¢ãã¦ã¬ãã¼ãã表形å¼ã§åºåãã
å®è¡ä¾ (2-1) ãã¼ãµã使ãå ´å
ãã¦ãAnsibleã§ãããã¯ã¼ã¯æ©å¨ã®ã¹ãã¼ã¿ã¹æ
å ±ããã¼ã¹ããæ段ã¯3ã¤ããã¾ãã
é çªã«èª¬æãã¦ããã¾ãããã¾ãã¯ç§ãå人çã«ä¸çªå¥½ãã§ããã(2) ãã¼ãµå©ç¨ãã«ã¤ãã¦èª¬æãã¾ãã
ãã¼ãµã使ãå ´åãåºæ¬çã«ã¯ansible.utils.cli_parseã¢ã¸ã¥ã¼ã«ã使ãã¾ãã
以ä¸ã«ãµã³ãã«ã示ãã¾ãã
show interfaces description
ããã¼ã¹ããplaybookã§ãã
ä»åã¯ntc_templates
ãã¼ãµãå©ç¨ãã¦ããã®ã§ãåä½ã«ã¯ntc_templates
Pythonããã±ã¼ã¸ãå¿
è¦ã§ãã
- name: Parse EOS show commands hosts: eos gather_facts: false tasks: - name: Parse show interfaces description ansible.utils.cli_parse: command: show interfaces description parser: name: ansible.netcommon.ntc_templates set_fact: _show_interfaces_description_parsed - name: Debug _show_interfaces_description_parsed ansible.builtin.debug: msg: '{{ _show_interfaces_description_parsed }}'
å®è¡çµæã¯ä»¥ä¸ã®ãããªã¤ã¡ã¼ã¸ã«ãªãã¾ãã
TextFSMã¯å¿
ãlist[dict]
(list of dicts) ã¨ãããã¼ã¿åã«æ§é åãã¾ãã
ãããã£ã¦ãshowã³ãã³ããå¤ãã£ã¦ãããããç»ä¸çãªæ¹æ³ã§ãã¼ã¿ãå å·¥ã§ãããã¨ãå©ç¹ã ã¨ç§ã¯èãã¦ãã¾ãã
TASK [Debug _show_interfaces_description_parsed] *** ok: [veos1] => msg: - description: veos2 Et1 port: Et1 protocol: up status: up - description: '' port: Et2 protocol: up status: up # ...
ãåèã¾ã§ã«ãshow interfaces description
ã®å®è¡ãã°ãåæ²ãã¾ãã
Interface Status Protocol Description Et1 up up veos2 Et1 Et2 down down veos3 Et1
ansible.utils.cli_parse module以å¤ã«ããä¼¼ãæ©è½ãæã¤ãã£ã«ã¿ã¨ãã¦ansible.netcommon.parse_cli filterãansible.netcommon.cli_parse_textfsm filterãåå¨ãã¾ãã
ãããã®ãã£ã«ã¿ã¯cli_parse
ã¢ã¸ã¥ã¼ã«ãããå
ã«ãªãªã¼ã¹ãããçµç·¯ããã使ããããã¨ãããã¾ããã対å¿ãã¦ãããã¼ãµãéå®çã§ããç¾å¨ã§ã¯ãã¾ã使ãçç±ããªãã¨æãã¾ãã
ãã£ã«ã¿ã«ã¤ãã¦ã¯å®è¡ä¾ãå²æãã¾ãã
å®è¡ä¾ (2-2) network resource moduleã使ãå ´å
network resource moduleãåå¨ããOSã®å ´åããã®æ¹æ³ã使ãã¾ãã
#å®è¡ä¾ (2-1) ãã¼ãµã使ãå ´åã¨æ¯è¼ããã¨ãã¼ãµå°å
¥ãä¸è¦ã§ããããããæ軽ã«ä½¿ãå§ãããã¨ãã§ãã¾ãã
ntc_templatesãTextFSMã¯ãCLIã§å¾ãããæ
å ±ã§ããã°å
¨ã¦æ§é åã§ãããæ±ç¨æ§ã¨ããå¿
ãlist[dict]
å½¢å¼ã§ãã¼ã¿ãè¿ããçµ±ä¸æãããã®ã§ãç§å人ã¨ãã¦ã¯ãã¼ãµå©ç¨ã«çµ±ä¸ããã®ã好ãã§ãã
ãã®ãããã¯å®ææ¦äºã§ãã
åããã¼ã¹çµæãå¾ãããæ¸ãæ¹ãç§ã®ç¥ãéã3éãåå¨ããã®ã§ãé çªã«æãã¦ããã¾ãã
1ã¤ç®ã®æ¸ãæ¹ã¯arista.eos.eos_facts moduleãå¼ã³åºãæ¹æ³ã§ãã
Factsãåéããã¨ãansible_facts
å¤æ°ã«èªåçã«æ ¼ç´ããã¾ãã
- name: Test gather facts on EOS hosts: eos gather_facts: false tasks: - name: Gather facts arista.eos.eos_facts: gather_network_resources: - interfaces - l2_interfaces - l3_interfaces - name: Debug _eos_facts_result ansible.builtin.debug: msg: '{{ ansible_facts }}'
å®è¡çµæã¯ä»¥ä¸ã®éãã§ãã
network_resources
ã®é
ä¸ãnetwork resource moduleã®æ©è½ã§åéããæ
å ±ã§ãã
Factsã使ãã¨ãnetwork_resource_module以å¤ã®Factsæ
å ±ãåæã«åéããã¾ãã
gather_subset
ãã©ã¡ã¼ã¿ã«!all
ãæå®ãã¦ãmin
ã«ç¸å½ããæ
å ±ã¯æä½éåéããã¾ãã
TASK [Debug _eos_facts_result] *** ok: [veos1] => msg: net_api: cliconf net_fqdn: veos1 # ... net_system: eos net_version: 4.26.5M network_resources: interfaces: - description: veos2 Et1 enabled: true name: Ethernet1 # ... l2_interfaces: - mode: trunk name: Ethernet1 trunk: trunk_allowed_vlans: - '2' # ... l3_interfaces: # ... - ipv4: - address: 192.168.0.11/24 name: Management1
2ã¤ç®ã®æ¸ãæ¹ã¯ãnetwork resource moduleã®state: gathered
ãæå®ããæ¹æ³ã§ãã
å¤æ°æ ¼ç´ããã«ã¯register
ãã¼ã¯ã¼ããå¿
è¦ã§ãã
1ã¤ã®Factsã ããåå¾ããã¨ãã¯ãã®æ¸ãæ¹ã§ãè¯ãã¨æãã¾ãã
è¤æ°ã®Factsãåéããå ´åã¯ãarista.eos.eos_facts
ã®æ¹ãã³ã³ãã¯ãã«æ¸ããã¨æãã¾ãã
- name: Gather EOS Facts hosts: eos gather_facts: false tasks: - name: Gather interfaces Facts arista.eos.eos_interfaces: state: gathered register: _eos_interfaces_result - name: Debug _eos_facts_result ansible.builtin.debug: msg: '{{ _eos_interfaces_result.gathered }}'
3ã¤ç®ã®æ¸ãæ¹ã¯ãgather_facts
ãæå®ããæ¹æ³ã§ãã
æ¸ãæ¹ãããç¹æ®ã§ãå人çã«è¦ãã«ããã§ãã
ã¾ãFactsã®åéã¿ã¤ãã³ã°ãPlayã®åé ã«åºå®ããã¾ãã
ç§ã®ç°å¢ã§ã¯å®æ©æ¤è¨¼ã§ãã¦ãã¾ããããmodule_defaults
ã®é
ä¸ã«eos
以å¤ã®OSã«ã¤ãã¦ãããã©ã«ãå¤ãæå®ãããã¨ã§è¤æ°OSåã®ãã¼ã¿åå¾ã1ã¤ã®Playã§ã¹ãããªè¡¨ç¾ã§ãããã¨ããã®æ¸ãæ¹ã®ã¡ãªãããªã®ã ã¨æ¨æ¸¬ãã¾ãã
Gathering facts from network devices
- name: Test gather facts on EOS hosts: eos gather_facts: true module_defaults: arista.eos.eos_facts: gather_network_resources: - interfaces - l2_interfaces - l3_interfaces tasks: - name: Debug _eos_facts_result ansible.builtin.debug: msg: '{{ ansible_facts }}'
(åè) cli_parseã¢ã¸ã¥ã¼ã«ã®æ¦è¦èª¬æ
cli_parse
ã¢ã¸ã¥ã¼ã«ã¯ãæååããã¼ã¹ãã¦æ§é åãã¼ã¿ãå¤æ°æ ¼ç´ããæ©è½ãæã¡ã¾ãã
cli_parse
ã¢ã¸ã¥ã¼ã«ãå®è¡ããã«ã¯ä»¥ä¸ã®ãããªæ
å ±ãå¿
è¦ã¨ãªãã¾ãã
æ§é åã«ä½¿ç¨ãããã¼ãµåããã©ã¡ã¼ã¿ã«æå®ããå¿ è¦ããããé¸æå¯è½ãªãã¼ãµã¨ãã¦ä»¥ä¸ã®é¸æè¢ãããã¾ãã
- ntc_templates
- TextFSM
- TTP (dmulyalin/ttp_templatesã«ãã³ãã¬ã¼ããµã³ãã«ãã)
- PyATS
- Ansible Native Parsing Engine
ãã¼ãµãè¤æ°ããã¨ã©ãã使ããè¿·ãã¨æãã¾ãã
ä¸æ¦ã«ã¯è¨ãã¾ããããã使ãæ
£ãããã¼ãµã使ããããããæ¥æ¬èªæ
å ±ãå¤ããã®ã使ããããããèªåã®ç¾å ´ã«ã¯Ciscoæ©å¨ãå¤ãããªã©æ§ã
ãªäºæ
ãç·åãã¦é¸å®ãããã®ã¨æ³åãã¾ãã
ãåèã¾ã§ã«ãç§å人ã¨ãã¦ã¯ansible.netcommon.ntc_templates
ã¨ansible.utils.textfsm
ã好ãã§ä½¿ãã¾ãã
ntc_templates
ã«ã¤ãã¦ã¯ä¸»è¦ãªãããã¯ã¼ã¯OSã®ãã¼ãµå®ç¾©ã¯æ¢ã«ããç¨åº¦æã£ã¦ãã¦ãGitHubä¸ã«å
¬éããã¦ãã¾ã (networktocode/ntc-templates - /ntc_templates/templates)ã
èªåã®æ¬²ãããã¼ãµãã³ãã¬ã¼ããGitHubä¸ã«å
¬éããã¦ããã°ãã¾ãã¯ããã使ã£ã¦ã¿ã¾ãã
ããntc-templates
ã®ãªãã¸ããªã«æ¢åã®ãã¼ãµå®ç¾©ãåå¨ããªãã£ãããæ¢åã®ãã¼ãµå®ç¾©ã¨ã¯ç°ãªããã¼ã¿æ§é ã欲ããã£ãå ´åã«ã¯TextFSMãã³ãã¬ã¼ããèªåã§è¨è¿°ãã¤ã¤ansible.utils.textfsm
ã使ãã¾ãã
ãã³ãã¬ã¼ããã¡ã¤ã«ã®ææ³ã¯ntc-templates
ã¨åæ§ãªã®ã§ãä»ã®ãã³ãã¬ã¼ããã¡ã¤ã«ã®æ¸ãæ¹ãåèã«ã§ãã¾ãã
ãã³ãã¬ã¼ããã¡ã¤ã«ã®ææ³ã調ã¹ãéã¯ãTextFSMã®Wikiæ
å ±ããã¤ã¼ã£ã¨ã®è¨äºãããããã§ãã
ãã®ä»ã使ãæ¹ã®è©³ç´°ã¯ansible.utils.cli_parseã®ãã©ã¡ã¼ã¿ä¸è¦§ãå®è¡ä¾ãåèã«ãªãã¾ãã
å®è¡ä¾ (2-3) gather_subsetã使ãå ´å
network resource moduleãAnsibleã«ç»å ´ããåãããeos_facts
ã¢ã¸ã¥ã¼ã«ãªã©ãããã¯ã¼ã¯æ©å¨ããFactsãåéããæ©è½ã¯åå¨ãã¦ãã¾ããã
ãããããã§ããããã®æ©è½ã¯gather_subset
ã¨ãããã¼ã¯ã¼ãã¨ãã¦ã¾ã æ®ã£ã¦ãã¾ãã
network resource moduleã®æ¹ãæ©è½ã¨ãã¦ã¯å¾çºã§ãããæããgather_subset
å¨ãã®æ©è½ãä»å¾æ¡å
ããããã¨ã¯ãªãã¨æãã¾ãã
ãã¨ãã£ã¦å»æ¢ã®äºåã¯ä»ã®ã¨ãããªãã®ã§ãnetwork resource moduleã§åå¾ã§ããªãæ
å ±ã®ä¸ã§gather_subset
ã§åããæ
å ±ãããã°ãé¸æè¢ã«å
¥ãã¦ã¿ã¦ãè¯ãããããã¾ããã
ãã©ãããã§ããç§å人ã¨ãã¦ã¯#å®è¡ä¾ (2-1) ãã¼ãµã使ãå ´åã§å
¨ã¦è³ã£ã¦ãã¾ãã®ãä»ã®ã¨ããã¯å¥½ãã§ãã
ã¨ã¯ãããã¼ãµã®ä½¿ãæ¹ãå¦ç¿ããã³ã¹ããããã¾ãããä¸æ¦ã«ãããæ£ç¾©ã ã¨ã¯è¨ãã¾ãã (å®ææ¦äºã§ã)ã
ä»åãFactsæ©è½ã®ãããæ¸ãæ¹ã¨ãã¦ã¯eos_facts
ã¨gather_facts
ã®2éããããã¾ãã
1ã¤ãã¤ç´¹ä»ãã¦ããã¾ãã
ã¾ãã¯1ã¤ç®ã®arista.eos.eos_factsãå©ç¨ããplaybookã®ãµã³ãã«ã§ãã
- name: Test gather facts on EOS hosts: eos gather_facts: false tasks: - name: Gather facts arista.eos.eos_facts: gather_subset: - interfaces - name: Debug _eos_facts_result ansible.builtin.debug: msg: '{{ ansible_facts }}'
å®è¡çµæã¯ä»¥ä¸ã®éãã§ãã
ãªãã ãshow interfaces
ããã¼ã¹ããæãããã¾ããã
TASK [Debug _eos_facts_result] *** ok: [veos1] => msg: # ... net_interfaces: Ethernet1: bandwidth: 1000000000 description: veos2 Et1 duplex: duplexFull ipv4: {} lineprotocol: up macaddress: 0c:65:34:fe:00:01 mtu: 9214 operstatus: connected type: bridged # ... network_resources: {}
ç¶ãã¦2ã¤ç®ã®gather_facts
ãå©ç¨ããæ¸ãæ¹ã§ãã
Factsã®åå¾ã¿ã¤ãã³ã°ãPlayã®åé ã«åºå®ããããã®ã®ããããã¯ã¼ã¯æ©å¨ã®OSã®å·®åãå¸åã§ããæ¸ãæ¹ã«ã¯ãªã£ã¦ããã§ãã
ãAnsibleãOSãã¨ã®æä½æé ã®éããå¸åããæ½è±¡åã¬ã¤ã¤ã¼ã¨ãã¦ä½¿ç¨ãããèãæ¹ãæã¯æµè¡ã£ã¦ã¾ãããã
æ½è±¡åã®å©ç¹ã«ã¤ãã¦èããã¨ã¯æè¿æ¸ã£ã¦ãã¾ããããgather_facts
ã使ç¨ããå¯ä¸ã®ã¢ããã¼ã·ã§ã³ã¯ãããªããããªããã¨æã£ã¦ãã¾ãã
- name: Test gather facts on EOS hosts: eos gather_facts: true gather_subset: - interfaces tasks: - name: Debug _eos_facts_result ansible.builtin.debug: msg: '{{ ansible_facts }}'
ãããã«
Ansibleã®ãããã¯ã¼ã¯æ©å¨ã®æ å ±ãéããæ¹æ³ã¯æ¬å½ã«ããããããã¾ãã
showã³ãã³ããã°ãä¿åããã ããªãè¿·ãã¾ãããããã¼ã¹ã®æ段ã¯æ¬å½ã«ããããããã¾ãã
ã§ãããè¿·ã£ãããã¼ãµãnetwork resource moduleç³»ã®æ©è½ã使ãã¾ãããã
è¨ãæããã¨ã#ãµããªè¡¨ã®(2-3)ã¯çç±ããªããã°ä½¿ããªãã¦è¯ãã¨æãã¾ãã
(Aristaã®network resource moduleã¯lldp_interfaces
ã®æ
å ±ããªããåéã§ããªãã®ã§ãshow lldp neighbors
ç¸å½ã®æ
å ±ããã¼ã¹ãããã¨ãã¯cli_parse
ãgather_subset
ã®ã©ã¡ããã使ãå¿
è¦ãããã¨ãã話ã¯ããã¾ããããã¯ãã®ãã¡ä¿®æ£ãããå°ããªissueã§ã)
çµå±ã®ã¨ããã¯å®ææ¦äºã§ããããã®è¨äºããã¼ã¹æ段ã®é¸æã®ä¸å©ã¨ãªãã°å¹¸ãã§ãã