â ã¯ããã«
fact ã¨ããã°ããµã¼ãã¼ç³»ã¢ã¸ã¥ã¼ã«ã®å ´åã¯ãgather_facts: yes
ï¼ããã©ã«ãï¼ã§åéããã¾ãããããããã¯ã¼ã¯ã¢ã¸ã¥ã¼ã«ã®å ´åã¯äºæ
ãç°ãªãã¾ããã
å
·ä½çã«ã¯ãgather_facts: yes
ã§ã¯ãAnsible ã³ã³ããã¼ã«ãã¼ãèªèº«ã® fact ãåéããã¦ãã¾ããããããã¯ã¼ã¯æ©å¨å´ã® fact ãåéããã«ã¯ ios_facts
ã¢ã¸ã¥ã¼ã«ããjunos_facts
ã¢ã¸ã¥ã¼ã«ãªã©ããã©ãããã©ã¼ã åå¥ã® *_facts
ã¢ã¸ã¥ã¼ã«ã使ãå¿
è¦ãããã¾ããã
Ansible 2.9 ã§ã¯ãgather_facts: yes
ï¼ããã©ã«ãï¼ã§ãããã¯ã¼ã¯æ©å¨å´ã® fact ãåéãããããã«ãªãã¾ãããéã«Ansible ã³ã³ããã¼ã«ãã¼ãèªèº«ã® fact ã¯åéãããªããªãã¾ããã
ãã®è¨äºã§ã¯ãIOS ã対象ã«ãã¦ãç°¡åãªä¾ããã¨ã«èª¬æãã¾ãã
â» ãã°ã®ã¿ãããã®ãããCALLBACK PLUGIN ã YAML ã«å¤æ´ãã¦ãã¾ãã
- ç°å¢
- Ansible 2.9.0
â ããã©ã«ãã§ã¯ã³ã³ãã£ã°ãåéããã
ããã©ã«ãã§ãgather_facts: yes
ãªã®ã§ããã®ã¾ã¾è©¦ãã¾ããdebug
ã¢ã¸ã¥ã¼ã«ã§ãfact ã®åå空éã§ãããansible_facts
ãã¾ããã¨åºåãã¾ãã
- Playbook
- hosts: ios tasks: - name: debug facts debug: var: ansible_facts
- å®è¡
ãã®å ´åãios_facts
ã¢ã¸ã¥ã¼ã«ã§ãã㨠gather_subset: all
㧠fact ãåéãã¾ãã
ã¤ã¾ããä¸è¨ã®ããã« ã³ã³ãã£ã°ãåé ããã¾ãã
$ ansible-playbook -i ../inventory.ini fact_test.yml PLAY [ios] ****************************************************************************** TASK [Gathering Facts] ****************************************************************** [WARNING]: Ignoring timeout(10) for ios_facts ok: [ios1] TASK [debug facts] ********************************************************************** ok: [ios1] => ansible_facts: _facts_gathered: true discovered_interpreter_python: /usr/bin/python net_all_ipv4_addresses: - 172.16.100.1 - 10.10.20.48 net_all_ipv6_addresses: [] net_api: cliconf net_config: |- ! ! Last configuration change at 12:35:22 UTC Sun Nov 24 2019 by developer ! version 16.11 service timestamps debug datetime msec service timestamps log datetime msec service call-home platform qfp utilization monitor load 80 no platform punt-keepalive disable-kernel-core ...(ç¥)... end net_filesystems: - 'bootflash:' net_filesystems_info: 'bootflash:': spacefree_kb: 5793276.0 spacetotal_kb: 7712692.0 net_gather_network_resources: [] net_gather_subset: - hardware - default - interfaces - config net_hostname: csr1000v-1 net_image: bootflash:packages.conf net_interfaces: GigabitEthernet1: bandwidth: 1000000 description: MANAGEMENT INTERFACE - DON'T TOUCH ME duplex: Full ipv4: - address: 10.10.20.48 subnet: '24' lineprotocol: up macaddress: 0050.56bb.e99c mediatype: Virtual mtu: 1500 operstatus: up type: CSR vNIC ...(ç¥)... net_iostype: IOS-XE net_memfree_mb: 2074004.25 net_memtotal_mb: 2378439.3125 net_model: CSR1000V net_neighbors: {} net_python_version: 2.7.10 net_serialnum: XXXXXXXXXXX net_system: ios net_version: 16.11.01a network_resources: {} PLAY RECAP ****************************************************************************** ios1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
â gather_facts: yes
ã®ã¾ã¾åé対象ãçµãã«ã¯
å
ã»ã©ã®ä¾ã¯ gather_subset: all
ç¸å½ã ã£ãã®ã§ãä¸è¦ãªæ
å ±ããã£ãããããã¾ããããããã fact åéãä¸è¦ã§ããã° gather_facts: no
ã«ãã¾ãããgather_facts: yes
ã®ã¾ã¾åé対象ãå¶éãããã±ã¼ã¹ããããã¨æãã¾ãã
module_defaultsãå©ç¨ãã¦ãios_facts
ã¢ã¸ã¥ã¼ã«ã® gather_subset
ãªãã·ã§ã³ãæå®ãããã¨ã§å¿
è¦ãªæ
å ±ã«å¶éã§ãã¾ãã
ã»ã»ã»ã¨æã£ã¦è©¦ããã®ã§ããããã¾ãå¶éã§ãã¾ããã§ããã
å ¬å¼ããã°ã«ãæ²è¼ããã¦ããæ¹æ³ã§ãããå¾®å¦ã«è©¦ãæ¹ã誤ã£ã¦ããã®ããããã¾ããã
ãã¾ãå¶éã§ããªãã£ããã®ã®ãã²ã¨ã¾ããã°ã¨ãã¦æ®ãã¦ããã¾ãã
- Playbook
- hosts: ios module_defaults: # æé»çã«å®è¡ããã ios_facts ã®ãªãã·ã§ã³ãæå®ãã¦ãã ios_facts: gather_subset: "!config" # ã³ã³ãã£ã°ã ! ã§é¤å¤ tasks: - name: debug facts debug: var: ansible_facts
- å®è¡
$ ansible-playbook -i ../inventory.ini fact_test.yml PLAY [ios] *********************************************************************** TASK [Gathering Facts] ******************************************************************* [WARNING]: Ignoring timeout(10) for ios_facts ok: [ios1] TASK [debug facts] ********************************************************************** ok: [ios1] => ansible_facts: _facts_gathered: true discovered_interpreter_python: /usr/bin/python net_all_ipv4_addresses: - 172.16.100.1 - 10.10.20.48 net_all_ipv6_addresses: [] net_api: cliconf net_config: |- ! ! Last configuration change at 13:11:27 UTC Sun Nov 24 2019 by developer ! version 16.11 service timestamps debug datetime msec service timestamps log datetime msec service call-home platform qfp utilization monitor load 80 no platform punt-keepalive disable-kernel-core ...(ç¥)... end net_filesystems: - 'bootflash:' net_filesystems_info: 'bootflash:': spacefree_kb: 5793252.0 spacetotal_kb: 7712692.0 net_gather_network_resources: [] net_gather_subset: - hardware - default - interfaces - config net_hostname: csr1000v-1 net_image: bootflash:packages.conf net_interfaces: GigabitEthernet1: bandwidth: 1000000 description: MANAGEMENT INTERFACE - DON'T TOUCH ME duplex: Full ipv4: - address: 10.10.20.48 subnet: '24' lineprotocol: up macaddress: 0050.56bb.e99c mediatype: Virtual mtu: 1500 operstatus: up type: CSR vNIC ...(ç¥)... net_iostype: IOS-XE net_memfree_mb: 2074004.25 net_memtotal_mb: 2378439.3125 net_model: CSR1000V net_neighbors: {} net_python_version: 2.7.10 net_serialnum: XXXXXXXXXXX net_system: ios net_version: 16.11.01a network_resources: {} PLAY RECAP ****************************************************************************** ios1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ã¨ãããã¨ã§ãæå³ããã³ã³ãã£ã°ãåéããã¦ãã¾ãã¾ãããmodule_defaults
ã§æå®ããå
容ãåæ ããã¦ããªãããã«è¦ãã¾ãããªã«ãåãã£ããæ´æ°ãã¾ãã
[2019/11/24追è¨]
ansible.cfg
ã® DEFAULT_GATHER_SUBSET
ã«è¨å®ãããå¹ãã¾ãããå½±é¿ç¯å²ãåºããã¾ãããã
â ã¾ã¨ã
- Ansible 2.8 ã¾ã§ã¯
ios_facts
ã¢ã¸ã¥ã¼ã«ãªã©ããã©ãããã©ã¼ã åå¥ã® fact åéã¢ã¸ã¥ã¼ã«ã§ fact ãåéãã¦ãã - Ansible 2.9 ã§ãããã¯ã¼ã¯ã¢ã¸ã¥ã¼ã«ã
gather_facts: yes
(ããã©ã«ã) 㧠fact ãåéãããããã«ãªã£ã *_facts
ã¢ã¸ã¥ã¼ã«ã§ãããgather_subset: all
ç¸å½ãªã®ã§ãã³ã³ãã£ã°ãåéããã- 対象ãå¶éãã«ã¯
module_defaults
ãå©ç¨ããã°ãããã»ã»ã¯ãã»ã»ã»ã ããä»åã®è©¦ãæ¹ã§ã¯ãã¾ããããªãã£ã