ãã㯠Ansible 3 Advent Calendar 2019 ã®8æ¥ç®ã®è¨äºã§ãã
â ã¯ããã«
éçºä¸ã® Ansible 2.10 ã§ã¯ãJuniper Junos åãã®ã¹ã¿ãã£ãã¯ã«ã¼ãè¨å®ã¢ã¸ã¥ã¼ã« junos_static_routes
ã¢ã¸ã¥ã¼ã« ï¼æ«å°¾ s
ããï¼ã追å ããã¾ãã
Ansible 2.9 ããç¶ã
ã¨è¿½å ããã¦ãã Network Resource Module ã®ã²ã¨ã¤ã§ãã
æ¢åã®junos_static_route
ã¢ã¸ã¥ã¼ã«ï¼æ«å°¾ s
ãªãï¼ã¯ãDECRECATED
ï¼éæ¨å¥¨ï¼æ±ãã«ãªãã¾ãã
ãã®è¨äºã§ã¯ãjunos_static_routes
ã®æ¦è¦ã®èª¬æã¨ãæä½ç¨®å¥ã示ãå state
ãªãã·ã§ã³ã®æ¤è¨¼çµæãæ²è¼ãã¾ãã
ä¸è¨ã§ããã¨ã便å©ã«ãªãã¾ãã
- ç°å¢
- Ansible 2.10.0.dev0
- Junos 18.3R1.9 (Juniper vLabs)
â ç°å¢ã®æºå
éçºç Ansible ã®ã¤ã³ã¹ãã¼ã«
éçºçãã¤ã³ã¹ãã¼ã«ããã«ã¯ã以ä¸ã®ããã« devel
ãã©ã³ããæå®ã㦠pip isntall
ãã¾ãã
$ pip install git+https://github.com/ansible/ansible.git@devel ...(ç¥)... $ ansible --version ansible 2.10.0.dev0 ...(ç¥)...
å¿ è¦ãª Python ã¢ã¸ã¥ã¼ã« ã®ã¤ã³ã¹ãã¼ã«
NETCONF ã¯ã©ã¤ã¢ã³ãã©ã¤ãã©ãªã® ncclient
ãXML ãæ±ã xmltodict
ãå¿
è¦ã¨ãå
¬å¼ããã¥ã¡ã³ãã® Requirements
ã«æ¸ããã¦ããã®ã§ãã¤ã³ã¹ãã¼ã«ãã¾ããncclient
ã¨ä¸ç·ã« paramiko
ãã¤ã³ã¹ãã¼ã«ããã¾ãã
$ pip install ncclient xmltodict
ããã¾ã§ã§ãç°å¢ã®æºåãã§ãã¾ããã
â junos_static_routes
ã¢ã¸ã¥ã¼ã«ã®åºæ¬
junos_static_routes
ã¢ã¸ã¥ã¼ã«ã«ã¯ã大ãããã¦ãè¨å®ã®å
容ã示ã config
ãªãã·ã§ã³ã¨ããã®å
容ãã©ãããç¶æ
ã«ããããæå®ãã state
ãªãã·ã§ã³ãããã¾ãã
ãµã³ãã«
- name: Merge provided configuration with device configuration (default operation is merge) junos_static_routes: config: - address_families: - afi: 'ipv4' routes: - dest: 10.200.16.75/24 next_hop: - forward_router_address: 10.200.16.2 state: merged
â» å ¬å¼ããã¥ã¡ã³ãã® Examples ããæç²
é°å²æ°ã§åããæãã§ãããconfig
ãªãã·ã§ã³å
ã§æ´ã«ç´°ãããå®å
ããã¯ã¹ããããã®æå®ãã¾ãã
state
ãªãã·ã§ã³
state
ãªãã·ã§ã³ã¯ã以ä¸ã®4種é¡ãã1ã¤é¸æã§ãã¾ãã
state ãªãã·ã§ã³ã®å¤ |
åä½ |
---|---|
merged |
config æå®ã®å
容ããã¼ã¸ï¼ããã©ã«ãï¼ |
replaced |
config æå®ã®å
容ã«ç½®ãæã |
overridden |
config æå®ã®å
容ã§ã¾ããã¨ä¸æ¸ãï¼çµæçã«ã«ã¼ãã£ã³ã°ãåé¤ããããã¨ãããï¼ |
deleted |
config æå®ã®å
容ãåé¤ |
ç¹ã« orverriden
ã®åããå人çã«ããªãç¹å¾´çï¼å¼·åï¼ã ã¨æã£ã¦ãã¾ãã
ä¸éã Examples ã«æ²è¼ããã¦ãã¾ããã ãã®è¨äºã§ã¯å°ãéãã¢ããã¼ãã§ç¬èªã«æ¤è¨¼ãã¾ãã
ã³ãã¯ã·ã§ã³ãã©ã°ã¤ã³ã¯ netconf
ã®ã¿ãµãã¼ã
junos_static_routes
ã¢ã¸ã¥ã¼ã«ã¯ãã³ãã¯ã·ã§ã³ãã©ã°ã¤ã³ã¨ãã¦ãnetconf
ã®ã¿ãµãã¼ããã¦ãã¾ããnetwor_cli
ã«ã¯å¯¾å¿ãã¦ãã¾ããã
ãã®ãããansible_connection
å¤æ°ã«ã¯ netconf
ãæå®ãã¦å©ç¨ãã¾ãã
ãããã¦ãncclient
ãªã©ãã¤ã³ã¹ãã¼ã«ãã python ç°å¢ããansible_python_interpreter
å¤æ°ã§æå®ãã¾ãã
- å¤æ°å®ç¾©ãã¡ã¤ã«ã®ä¾
ansible_connection: netconf ansible_network_os: junos ansible_user: testuser ansible_password: testpassxxx ansible_python_interpreter: /Users/ansible/envs/venvs/a210dev/bin/python
â state: merged
ã®åä½
ã¾ãã¯ãconfig
æå®ã®å
容ããã¼ã¸ãã state: merged
ï¼ããã©ã«ãï¼ ãæ¤è¨¼ãã¾ãã
äºåç¶æ
Playbook å®è¡åã¯ä»¥ä¸ã¨ãããããã©ã«ãã«ã¼ãã1ã¤ããç¶æ ã§ãã
jcluser@vMX-addr-0> show configuration routing-options static | display set set routing-options static route 0.0.0.0/0 next-hop 100.123.0.1
Playbook ä½æ
3ã¤ã®ã¹ã¿ãã£ãã¯ã«ã¼ãããã¼ã¸ãã Playbook ãä½æãã¾ãã
- hosts: vlabs gather_facts: no tasks: - name: static routes test junos_static_routes: config: - address_families: - afi: 'ipv4' routes: - dest: 10.0.1.0/24 next_hop: - forward_router_address: 192.168.0.1 - dest: 10.0.2.0/24 next_hop: - forward_router_address: 192.168.0.1 - dest: 10.0.3.0/24 next_hop: - forward_router_address: 192.168.0.1 state: merged # ãã¤ã³ã
Playbook å®è¡
Playbook ãå®è¡ãã¾ãã
$ ansible-playbook -i ../inventory.ini static_routes.yml PLAY [vlabs] *************************************************************************************************** TASK [static routes test] ************************************************************************************** changed: [vmx] PLAY RECAP ***************************************************************************************************** vmx : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ãªããå
é¨ã§ã¯å®éã«å®è¡ãããã³ãã³ã㯠junos_static_routes
ã¢ã¸ã¥ã¼ã«ã®æ»ãå¤ã® commands
ã§ç¢ºèªã§ãã¾ãã
äºå¾ç¶æ
以ä¸ã®éããã¹ã¿ãã£ãã¯ã«ã¼ãã3㤠追å ããã¾ããããã¨ãã¨ãã£ãããã©ã«ãã«ã¼ãã¯ãã®ã¾ã¾ã§ãã
jcluser@vMX-addr-0> show configuration routing-options static | display set set routing-options static route 0.0.0.0/0 next-hop 100.123.0.1 set routing-options static route 10.0.1.0/24 next-hop 192.168.0.1 set routing-options static route 10.0.2.0/24 next-hop 192.168.0.1 set routing-options static route 10.0.3.0/24 next-hop 192.168.0.1
ããã¾ã§ã§ãstate: merged
ã§ãæå®ããã«ã¼ãããã¼ã¸ããããã¨ãæ¤è¨¼ã§ãã¾ããã
â state: replaced
ã®åä½
次ã«ãconfig
æå®ã®å
容ã«ç½®ãæãã state: replaced
ãæ¤è¨¼ãã¾ãã
äºåç¶æ
å
ã»ã©æ¤è¨¼ãã state: merged
ã®äºå¾ç¶æ
ããå§ãã¾ãã
Playbook ä½æ
10.0.1.0/24
ãã¦ã®ãã¯ã¹ãããããç½®ãæãã Playbook ãä½æãã¾ãã
- hosts: vlabs gather_facts: no tasks: - name: static routes test junos_static_routes: config: - address_families: - afi: 'ipv4' routes: - dest: 10.0.1.0/24 next_hop: - forward_router_address: 172.16.0.1 # ãã¯ã¹ããããç½®ãæã state: replaced # ãã¤ã³ã
Playbook å®è¡
Playbook ãå®è¡ãã¾ãã
$ ansible-playbook -i ../inventory.ini static_routes.yml ...(ç¥)...
äºå¾ç¶æ
以ä¸ã®éãã10.0.1.0/24
ãã¦ã®ãã¯ã¹ãããããç½®ãæããã¾ããã
jcluser@vMX-addr-0> show configuration routing-options static | display set set routing-options static route 0.0.0.0/0 next-hop 100.123.0.1 set routing-options static route 10.0.2.0/24 next-hop 192.168.0.1 set routing-options static route 10.0.3.0/24 next-hop 192.168.0.1 set routing-options static route 10.0.1.0/24 next-hop 172.16.0.1
ããã¾ã§ã§ãstate: replaced
ã§ãæå®ããã«ã¼ããç½®ãæãããããã¨ãæ¤è¨¼ã§ãã¾ããã
ãªããåã config
å
容㧠state: merged
ã«ããã¨ã
jcluser@vMX-addr-0> show configuration routing-options static | display set set routing-options static route 0.0.0.0/0 next-hop 100.123.0.1 set routing-options static route 10.0.1.0/24 next-hop 192.168.0.1 # åãNWã㦠set routing-options static route 10.0.1.0/24 next-hop 172.16.0.1 # åãNWã㦠set routing-options static route 10.0.2.0/24 next-hop 192.168.0.1 set routing-options static route 10.0.3.0/24 next-hop 192.168.0.1
ã®ããã«ãåã 10.0.1.0/24
ãã¦ã®å¥ã®ã¨ã³ããªãã§ãã¾ãã
â state: overridden
ã®åä½
ä¸çªæ°ã«ãªã£ã¦ããæå®ã§ãã
config
æå®ã®å
容ã§ã¾ããã¨ä¸æ¸ããã state: overridden
ãæ¤è¨¼ãã¾ãã
äºåç¶æ
å
ã»ã©æ¤è¨¼ãã state: replaced
ã®äºå¾ç¶æ
ããå§ãã¾ãã
Playbook ä½æ
ããã©ã«ãã«ã¼ãã¨ã10.0.99.0/24
ãã¦ã®ã¿ã«ãã Playbook ãä½æãã¾ãã
æå®ãã2ã¨ã³ããªä»¥å¤ã®ã«ã¼ãã£ã³ã°ã¯åé¤ããã¾ãã
- hosts: vlabs gather_facts: no tasks: - name: static routes test junos_static_routes: config: - address_families: - afi: 'ipv4' routes: - dest: 0.0.0.0/0 next_hop: - forward_router_address: 100.123.0.1 - dest: 10.0.99.0/24 next_hop: - forward_router_address: 192.168.99.1 state: overridden # ãã¤ã³ã
Playbook å®è¡
Playbook ãå®è¡ãã¾ãã
$ ansible-playbook -i ../inventory.ini static_routes.yml ...(ç¥)...
äºå¾ç¶æ
以ä¸ã®éããããã©ã«ãã«ã¼ãã¨ã10.0.99.0/24
ãã¦ã®ã¿ã«ãªãã¾ããã
æå®ãã2ã¨ã³ããªä»¥å¤ã®ã«ã¼ãã£ã³ã°ã¯åé¤ããã¾ããã
jcluser@vMX-addr-0> show configuration routing-options static | display set set routing-options static route 0.0.0.0/0 next-hop 100.123.0.1 set routing-options static route 10.0.99.0/24 next-hop 192.168.99.1
ä»ã®æå®ã¨ã¯ç°ãªãã config
ã§æå®ããã«ã¼ãã£ã³ã°ä»¥å¤ã¯åé¤ããã ç¹ãã便å©ã§ãããã注æç¹ã§ãããã¾ãã
ããã¾ã§ã§ãstate: overridden
ã§ãæå®ã®å
容ã§ã¾ããã¨ä¸æ¸ãããããã¨ãæ¤è¨¼ã§ãã¾ããã
â state: deleted
ã®åä½
æå¾ã®ãªãã·ã§ã³ãconfig
æå®ã®å
容ãåé¤ãã state: deleted
ãæ¤è¨¼ãã¾ãã
äºåç¶æ
å
ã»ã©æ¤è¨¼ãã state: overridden
ã®äºå¾ç¶æ
ããå§ãã¾ãã
Playbook ä½æ
10.0.1.0/24
ãã¦ã«ã¼ããåé¤ããã Playbook ãä½æãã¾ãã
- hosts: vlabs gather_facts: no tasks: - name: static routes test junos_static_routes: config: - address_families: - afi: 'ipv4' routes: - dest: 10.0.99.0/24 next_hop: - forward_router_address: 192.168.99.1 state: deleted # ãã¤ã³ã
Playbook å®è¡
Playbook ãå®è¡ãã¾ãã
$ ansible-playbook -i ../inventory.ini static_routes.yml ...(ç¥)...
äºå¾ç¶æ
以ä¸ã®éãã10.0.1.0/24
ãã¦ã®ã«ã¼ããåé¤ãããããã©ã«ãã«ã¼ãã®ã¿ã«ãªãã¾ããã
jcluser@vMX-addr-0> show configuration routing-options static | display set set routing-options static route 0.0.0.0/0 next-hop 100.123.0.1
ããã¾ã§ã§ãstate: deleted
ã§ãæå®ããã«ã¼ããåé¤ããããã¨ãæ¤è¨¼ã§ãã¾ããã
â ã¾ã¨ã
junos_static_routes
ã¢ã¸ã¥ã¼ã«ã¯ã以ä¸ã®ãããªç¹å¾´ãããã¾ããã
- ã³ãã³ãï¼
set / delete ã
ãªã©ï¼ã¯ç´æ¥æå®ããªã config
ãªãã·ã§ã³ã«è¨å®ãã©ã¡ã¼ã¿ãæå®ããstate
ãªãã·ã§ã³ã®å¤ãã£ã¦æåãç°ãªãstate: merged
ãstate: replaced
ãstate: deleted
æç¶ããã¼ã¹ã®æå®state: overridden
ã¯ãconfig
ã§æå®ããã«ã¼ã以å¤ã¯åé¤ããã宣è¨çãªæå®ãã§ãã
ãªããNetwork: 2.10 Roadmapã«ããã¨ãAnsible 2.10 ã§ã¯ã以ä¸ã® *_static_routes
ã¢ã¸ã¥ã¼ã«ã®éçºãäºå®ããã¦ããããã§ãã
- vyos_static_routes
- ios_static_routes
- iosxr_static_routes
- junos_static_routes
- eos_static_routes
- nxos_static_routes
[2019/12/09 追è¨]
ç¹ã«ç¹å¾´çãªæåã ã£ããoverridden
ã«ã¤ãã¦ã¯å¥é使ãæãèããè¨äºãã¢ãããã¾ããã