Skip to content

Instantly share code, notes, and snippets.

@privateip
Created November 27, 2017 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save privateip/27177caa90005a59219c91bffeeac3d5 to your computer and use it in GitHub Desktop.
Save privateip/27177caa90005a59219c91bffeeac3d5 to your computer and use it in GitHub Desktop.
example ios implementation of network_cli
(ansible) [ansible-ios]$ play example.yaml -u ansible -k -vvv
ansible-playbook 2.5.0 (network-cli-example 5c88db3630) last updated 2017/11/27 16:18:59 (GMT -400)
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/sprygada/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /home/sprygada/Workspaces/ansible/lib/ansible
executable location = /home/sprygada/Workspaces/ansible/bin/ansible-playbook
python version = 2.7.14 (default, Nov 3 2017, 10:55:25) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]
Using /etc/ansible/ansible.cfg as config file
SSH password:
Parsed /etc/ansible/hosts inventory source with ini plugin
PLAYBOOK: example.yaml **************************************************************************************************************************************************************************************
1 plays in example.yaml
PLAY [ios01] ************************************************************************************************************************************************************************************************
META: ran handlers
TASK [ios_command] ******************************************************************************************************************************************************************************************
task path: /home/sprygada/Workspaces/playbooks/ansible-ios/example.yaml:7
Using module file /home/sprygada/Workspaces/ansible/lib/ansible/modules/network/ios/ios_command.py
<an-ios-01.ansible.eng.rdu2.redhat.com> ESTABLISH LOCAL CONNECTION FOR USER: sprygada
<an-ios-01.ansible.eng.rdu2.redhat.com> EXEC /bin/sh -c 'echo ~ && sleep 0'
<an-ios-01.ansible.eng.rdu2.redhat.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/sprygada/.ansible/tmp/ansible-tmp-1511820353.2-46963144953311 `" && echo ansible-tmp-1511820353.2-46963144953311="` echo /home/sprygada/.ansible/tmp/ansible-tmp-1511820353.2-46963144953311 `" ) && sleep 0'
<an-ios-01.ansible.eng.rdu2.redhat.com> PUT /tmp/tmpExwDAW TO /home/sprygada/.ansible/tmp/ansible-tmp-1511820353.2-46963144953311/ios_command.py
<an-ios-01.ansible.eng.rdu2.redhat.com> EXEC /bin/sh -c 'chmod u+x /home/sprygada/.ansible/tmp/ansible-tmp-1511820353.2-46963144953311/ /home/sprygada/.ansible/tmp/ansible-tmp-1511820353.2-46963144953311/ios_command.py && sleep 0'
<an-ios-01.ansible.eng.rdu2.redhat.com> EXEC /bin/sh -c 'python /home/sprygada/.ansible/tmp/ansible-tmp-1511820353.2-46963144953311/ios_command.py; rm -rf "/home/sprygada/.ansible/tmp/ansible-tmp-1511820353.2-46963144953311/" > /dev/null 2>&1 && sleep 0'
ok: [ios01] => (item=show version) => {
"changed": false,
"invocation": {
"module_args": {
"answer": null,
"command": "show version",
"prompt": null
}
},
"item": "show version",
"stdout": "Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(2)T, RELEASE SOFTWARE (fc2)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2016 by Cisco Systems, Inc.\nCompiled Tue 22-Mar-16 16:19 by prod_rel_team\n\n\nROM: Bootstrap program is IOSv\n\nan-ios-01 uptime is 1 hour, 7 minutes\nSystem returned to ROM by reload\nSystem image file is \"flash0:/vios-adventerprisek9-m\"\nLast reload reason: Unknown reason\n\n\n\nThis product contains cryptographic features and is subject to United\nStates and local country laws governing import, export, transfer and\nuse. Delivery of Cisco cryptographic products does not imply\nthird-party authority to import, export, distribute or use encryption.\nImporters, exporters, distributors and users are responsible for\ncompliance with U.S. and local country laws. By using this product you\nagree to comply with applicable laws and regulations. If you are unable\nto comply with U.S. and local laws, return this product immediately.\n\nA summary of U.S. laws governing Cisco cryptographic products may be found at:\nhttp://www.cisco.com/wwl/export/crypto/tool/stqrg.html\n\nIf you require further assistance please contact us by sending email to\nexport@cisco.com.\n\nCisco IOSv (revision 1.0) with with 460033K/62464K bytes of memory.\nProcessor board ID 9BWIOHQC5Y645EPKUZ3TB\n4 Gigabit Ethernet interfaces\nDRAM configuration is 72 bits wide with parity disabled.\n256K bytes of non-volatile configuration memory.\n2097152K bytes of ATA System CompactFlash 0 (Read/Write)\n0K bytes of ATA CompactFlash 1 (Read/Write)\n0K bytes of ATA CompactFlash 2 (Read/Write)\n10080K bytes of ATA CompactFlash 3 (Read/Write)\n\n\n\nConfiguration register is 0x0",
"stdout_lines": [
"Cisco IOS Software, IOSv Software (VIOS-ADVENTERPRISEK9-M), Version 15.6(2)T, RELEASE SOFTWARE (fc2)",
"Technical Support: http://www.cisco.com/techsupport",
"Copyright (c) 1986-2016 by Cisco Systems, Inc.",
"Compiled Tue 22-Mar-16 16:19 by prod_rel_team",
"",
"",
"ROM: Bootstrap program is IOSv",
"",
"an-ios-01 uptime is 1 hour, 7 minutes",
"System returned to ROM by reload",
"System image file is \"flash0:/vios-adventerprisek9-m\"",
"Last reload reason: Unknown reason",
"",
"",
"",
"This product contains cryptographic features and is subject to United",
"States and local country laws governing import, export, transfer and",
"use. Delivery of Cisco cryptographic products does not imply",
"third-party authority to import, export, distribute or use encryption.",
"Importers, exporters, distributors and users are responsible for",
"compliance with U.S. and local country laws. By using this product you",
"agree to comply with applicable laws and regulations. If you are unable",
"to comply with U.S. and local laws, return this product immediately.",
"",
"A summary of U.S. laws governing Cisco cryptographic products may be found at:",
"http://www.cisco.com/wwl/export/crypto/tool/stqrg.html",
"",
"If you require further assistance please contact us by sending email to",
"export@cisco.com.",
"",
"Cisco IOSv (revision 1.0) with with 460033K/62464K bytes of memory.",
"Processor board ID 9BWIOHQC5Y645EPKUZ3TB",
"4 Gigabit Ethernet interfaces",
"DRAM configuration is 72 bits wide with parity disabled.",
"256K bytes of non-volatile configuration memory.",
"2097152K bytes of ATA System CompactFlash 0 (Read/Write)",
"0K bytes of ATA CompactFlash 1 (Read/Write)",
"0K bytes of ATA CompactFlash 2 (Read/Write)",
"10080K bytes of ATA CompactFlash 3 (Read/Write)",
"",
"",
"",
"Configuration register is 0x0"
]
}
Using module file /home/sprygada/Workspaces/ansible/lib/ansible/modules/network/ios/ios_command.py
<an-ios-01.ansible.eng.rdu2.redhat.com> ESTABLISH LOCAL CONNECTION FOR USER: sprygada
<an-ios-01.ansible.eng.rdu2.redhat.com> EXEC /bin/sh -c 'echo ~ && sleep 0'
<an-ios-01.ansible.eng.rdu2.redhat.com> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/sprygada/.ansible/tmp/ansible-tmp-1511820354.16-180599323258760 `" && echo ansible-tmp-1511820354.16-180599323258760="` echo /home/sprygada/.ansible/tmp/ansible-tmp-1511820354.16-180599323258760 `" ) && sleep 0'
<an-ios-01.ansible.eng.rdu2.redhat.com> PUT /tmp/tmpR0N_9w TO /home/sprygada/.ansible/tmp/ansible-tmp-1511820354.16-180599323258760/ios_command.py
<an-ios-01.ansible.eng.rdu2.redhat.com> EXEC /bin/sh -c 'chmod u+x /home/sprygada/.ansible/tmp/ansible-tmp-1511820354.16-180599323258760/ /home/sprygada/.ansible/tmp/ansible-tmp-1511820354.16-180599323258760/ios_command.py && sleep 0'
<an-ios-01.ansible.eng.rdu2.redhat.com> EXEC /bin/sh -c 'python /home/sprygada/.ansible/tmp/ansible-tmp-1511820354.16-180599323258760/ios_command.py; rm -rf "/home/sprygada/.ansible/tmp/ansible-tmp-1511820354.16-180599323258760/" > /dev/null 2>&1 && sleep 0'
ok: [ios01] => (item=show running-config) => {
"changed": false,
"invocation": {
"module_args": {
"answer": null,
"command": "show running-config",
"prompt": null
}
},
"item": "show running-config",
"stdout": "Building configuration...\n\nCurrent configuration : 7704 bytes\n!\n! Last configuration change at 21:01:41 UTC Mon Nov 27 2017\n!\nversion 15.6\nservice timestamps debug datetime msec\nservice timestamps log datetime msec\nno service password-encryption\n!\nhostname an-ios-01\n!\nboot-start-marker\nboot-end-marker\n!\n!\nvrf definition Mgmt-intf\n !\n address-family ipv4\n exit-address-family\n !\n address-family ipv6\n exit-address-family\n!\nenable password cisco\n!\nno aaa new-model\nethernet lmi ce\n!\n!\n!\nmmi polling-interval 60\nno mmi auto-configure\nno mmi pvc\nmmi snmp-timeout 180\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\nno ip domain lookup\nip domain name ansible.eng.rdu2.redhat.com\nip cef\nipv6 unicast-routing\nipv6 cef\n!\nmultilink bundle-name authenticated\n!\n!\n!\n!\nusername cisco privilege 15 secret 5 $1$8jL5$KGYyB59XgKo1pgZZ.grTf.\nusername ansible privilege 15 secret 5 $1$QrQ3$6VjcH2ynw1Bx2UYwrlbj9.\n!\nredundancy\n!\nno cdp run\n!\n! \n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\n!\ninterface Loopback0\n description Loopback\n ip address 192.168.255.2 255.255.255.255\n!\ninterface GigabitEthernet0/0\n description OOB Management\n vrf forwarding Mgmt-intf\n ip address 10.8.38.65 255.255.255.0\n duplex full\n speed auto\n media-type rj45\n!\ninterface GigabitEthernet0/1\n description to iosl201\n ip address 172.31.0.10 255.255.255.252\n ip ospf cost 1\n duplex full\n speed auto\n media-type rj45\n!\ninterface GigabitEthernet0/2\n description to iosxr01\n ip address 172.31.0.13 255.255.255.252\n ip ospf cost 1\n duplex full\n speed auto\n media-type rj45\n!\ninterface GigabitEthernet0/3\n description to ios02\n ip address 172.31.0.25 255.255.255.252\n ip ospf cost 1\n duplex full\n speed auto\n media-type rj45\n!\nrouter ospf 1\n passive-interface Loopback0\n network 172.31.0.8 0.0.0.3 area 0\n network 172.31.0.12 0.0.0.3 area 0\n network 172.31.0.24 0.0.0.3 area 0\n network 192.168.255.2 0.0.0.0 area 0\n!\nrouter bgp 1\n bgp router-id 192.168.255.2\n bgp log-neighbor-changes\n neighbor 192.168.255.1 remote-as 1\n neighbor 192.168.255.1 description iBGP peer nxos01\n neighbor 192.168.255.1 update-source Loopback0\n neighbor 192.168.255.4 remote-as 1\n neighbor 192.168.255.4 description iBGP peer csr01\n neighbor 192.168.255.4 update-source Loopback0\n neighbor 192.168.255.5 remote-as 1\n neighbor 192.168.255.5 description iBGP peer iosxr01\n neighbor 192.168.255.5 update-source Loopback0\n neighbor 192.168.255.6 remote-as 1\n neighbor 192.168.255.6 description iBGP peer nxos02\n neighbor 192.168.255.6 update-source Loopback0\n neighbor 192.168.255.7 remote-as 1\n neighbor 192.168.255.7 description iBGP peer csr02\n neighbor 192.168.255.7 update-source Loopback0\n neighbor 192.168.255.8 remote-as 1\n neighbor 192.168.255.8 description iBGP peer ios02\n neighbor 192.168.255.8 update-source Loopback0\n neighbor 192.168.255.9 remote-as 1\n neighbor 192.168.255.9 description iBGP peer iosxr02\n neighbor 192.168.255.9 update-source Loopback0\n neighbor 192.168.255.10 remote-as 1\n neighbor 192.168.255.10 description iBGP peer nxos9k01\n neighbor 192.168.255.10 update-source Loopback0\n neighbor 192.168.255.11 remote-as 1\n neighbor 192.168.255.11 description iBGP peer nxos9k02\n neighbor 192.168.255.11 update-source Loopback0\n !\n address-family ipv4\n network 192.168.255.2 mask 255.255.255.255\n neighbor 192.168.255.1 activate\n neighbor 192.168.255.4 activate\n neighbor 192.168.255.5 activate\n neighbor 192.168.255.6 activate\n neighbor 192.168.255.7 activate\n neighbor 192.168.255.8 activate\n neighbor 192.168.255.9 activate\n neighbor 192.168.255.10 activate\n neighbor 192.168.255.11 activate\n exit-address-family\n!\nip forward-protocol nd\n!\n!\nno ip http server\nno ip http secure-server\nip route vrf Mgmt-intf 10.0.0.0 255.0.0.0 10.8.38.1\nip ssh server algorithm authentication password\n!\n!\n!\n!\ncontrol-plane\n!\nbanner exec ^C\n**************************************************************************\n* IOSv - Cisco Systems Confidential *\n* *\n* Supplemental End User License Restrictions *\n* *\n* This IOSv software is provided AS-IS without warranty of any kind. *\n* Under no circumstances may this software be used separate from *\n* the Cisco Modeling Labs Software that this software was provided *\n* with, or deployed or used as part of a production environment. *\n* *\n* By using the software, you agree to abide by the terms and *\n* conditions of the Cisco End User License Agreement at *\n* http://www.cisco.com/go/eula. *\n* *\n* Unauthorized use or distribution of this software is expressly *\n* prohibited. *\n**************************************************************************\n^C\nbanner incoming ^C\n**************************************************************************\n* IOSv - Cisco Systems Confidential *\n* *\n* Supplemental End User License Restrictions *\n* *\n* This IOSv software is provided AS-IS without warranty of any kind. *\n* Under no circumstances may this software be used separate from *\n* the Cisco Modeling Labs Software that this software was provided *\n* with, or deployed or used as part of a production environment. *\n* *\n* By using the software, you agree to abide by the terms and *\n* conditions of the Cisco End User License Agreement at *\n* http://www.cisco.com/go/eula. *\n* *\n* Unauthorized use or distribution of this software is expressly *\n* prohibited. *\n**************************************************************************\n^C\nbanner login ^C\n**************************************************************************\n* IOSv - Cisco Systems Confidential *\n* *\n* Supplemental End User License Restrictions *\n* *\n* This IOSv software is provided AS-IS without warranty of any kind. *\n* Under no circumstances may this software be used separate from *\n* the Cisco Modeling Labs Software that this software was provided *\n* with, or deployed or used as part of a production environment. *\n* *\n* By using the software, you agree to abide by the terms and *\n* conditions of the Cisco End User License Agreement at *\n* http://www.cisco.com/go/eula. *\n* *\n* Unauthorized use or distribution of this software is expressly *\n* prohibited. *\n**************************************************************************\n^C\n!\nline con 0\n password cisco\nline aux 0\nline vty 0 4\n exec-timeout 720 0\n password cisco\n login local\n transport input telnet ssh\n!\nno scheduler allocate\n!\nend",
"stdout_lines": [
"Building configuration...",
"",
"Current configuration : 7704 bytes",
"!",
"! Last configuration change at 21:01:41 UTC Mon Nov 27 2017",
"!",
"version 15.6",
"service timestamps debug datetime msec",
"service timestamps log datetime msec",
"no service password-encryption",
"!",
"hostname an-ios-01",
"!",
"boot-start-marker",
"boot-end-marker",
"!",
"!",
"vrf definition Mgmt-intf",
" !",
" address-family ipv4",
" exit-address-family",
" !",
" address-family ipv6",
" exit-address-family",
"!",
"enable password cisco",
"!",
"no aaa new-model",
"ethernet lmi ce",
"!",
"!",
"!",
"mmi polling-interval 60",
"no mmi auto-configure",
"no mmi pvc",
"mmi snmp-timeout 180",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"no ip domain lookup",
"ip domain name ansible.eng.rdu2.redhat.com",
"ip cef",
"ipv6 unicast-routing",
"ipv6 cef",
"!",
"multilink bundle-name authenticated",
"!",
"!",
"!",
"!",
"username cisco privilege 15 secret 5 $1$8jL5$KGYyB59XgKo1pgZZ.grTf.",
"username ansible privilege 15 secret 5 $1$QrQ3$6VjcH2ynw1Bx2UYwrlbj9.",
"!",
"redundancy",
"!",
"no cdp run",
"!",
"! ",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"!",
"interface Loopback0",
" description Loopback",
" ip address 192.168.255.2 255.255.255.255",
"!",
"interface GigabitEthernet0/0",
" description OOB Management",
" vrf forwarding Mgmt-intf",
" ip address 10.8.38.65 255.255.255.0",
" duplex full",
" speed auto",
" media-type rj45",
"!",
"interface GigabitEthernet0/1",
" description to iosl201",
" ip address 172.31.0.10 255.255.255.252",
" ip ospf cost 1",
" duplex full",
" speed auto",
" media-type rj45",
"!",
"interface GigabitEthernet0/2",
" description to iosxr01",
" ip address 172.31.0.13 255.255.255.252",
" ip ospf cost 1",
" duplex full",
" speed auto",
" media-type rj45",
"!",
"interface GigabitEthernet0/3",
" description to ios02",
" ip address 172.31.0.25 255.255.255.252",
" ip ospf cost 1",
" duplex full",
" speed auto",
" media-type rj45",
"!",
"router ospf 1",
" passive-interface Loopback0",
" network 172.31.0.8 0.0.0.3 area 0",
" network 172.31.0.12 0.0.0.3 area 0",
" network 172.31.0.24 0.0.0.3 area 0",
" network 192.168.255.2 0.0.0.0 area 0",
"!",
"router bgp 1",
" bgp router-id 192.168.255.2",
" bgp log-neighbor-changes",
" neighbor 192.168.255.1 remote-as 1",
" neighbor 192.168.255.1 description iBGP peer nxos01",
" neighbor 192.168.255.1 update-source Loopback0",
" neighbor 192.168.255.4 remote-as 1",
" neighbor 192.168.255.4 description iBGP peer csr01",
" neighbor 192.168.255.4 update-source Loopback0",
" neighbor 192.168.255.5 remote-as 1",
" neighbor 192.168.255.5 description iBGP peer iosxr01",
" neighbor 192.168.255.5 update-source Loopback0",
" neighbor 192.168.255.6 remote-as 1",
" neighbor 192.168.255.6 description iBGP peer nxos02",
" neighbor 192.168.255.6 update-source Loopback0",
" neighbor 192.168.255.7 remote-as 1",
" neighbor 192.168.255.7 description iBGP peer csr02",
" neighbor 192.168.255.7 update-source Loopback0",
" neighbor 192.168.255.8 remote-as 1",
" neighbor 192.168.255.8 description iBGP peer ios02",
" neighbor 192.168.255.8 update-source Loopback0",
" neighbor 192.168.255.9 remote-as 1",
" neighbor 192.168.255.9 description iBGP peer iosxr02",
" neighbor 192.168.255.9 update-source Loopback0",
" neighbor 192.168.255.10 remote-as 1",
" neighbor 192.168.255.10 description iBGP peer nxos9k01",
" neighbor 192.168.255.10 update-source Loopback0",
" neighbor 192.168.255.11 remote-as 1",
" neighbor 192.168.255.11 description iBGP peer nxos9k02",
" neighbor 192.168.255.11 update-source Loopback0",
" !",
" address-family ipv4",
" network 192.168.255.2 mask 255.255.255.255",
" neighbor 192.168.255.1 activate",
" neighbor 192.168.255.4 activate",
" neighbor 192.168.255.5 activate",
" neighbor 192.168.255.6 activate",
" neighbor 192.168.255.7 activate",
" neighbor 192.168.255.8 activate",
" neighbor 192.168.255.9 activate",
" neighbor 192.168.255.10 activate",
" neighbor 192.168.255.11 activate",
" exit-address-family",
"!",
"ip forward-protocol nd",
"!",
"!",
"no ip http server",
"no ip http secure-server",
"ip route vrf Mgmt-intf 10.0.0.0 255.0.0.0 10.8.38.1",
"ip ssh server algorithm authentication password",
"!",
"!",
"!",
"!",
"control-plane",
"!",
"banner exec ^C",
"**************************************************************************",
"* IOSv - Cisco Systems Confidential *",
"* *",
"* Supplemental End User License Restrictions *",
"* *",
"* This IOSv software is provided AS-IS without warranty of any kind. *",
"* Under no circumstances may this software be used separate from *",
"* the Cisco Modeling Labs Software that this software was provided *",
"* with, or deployed or used as part of a production environment. *",
"* *",
"* By using the software, you agree to abide by the terms and *",
"* conditions of the Cisco End User License Agreement at *",
"* http://www.cisco.com/go/eula. *",
"* *",
"* Unauthorized use or distribution of this software is expressly *",
"* prohibited. *",
"**************************************************************************",
"^C",
"banner incoming ^C",
"**************************************************************************",
"* IOSv - Cisco Systems Confidential *",
"* *",
"* Supplemental End User License Restrictions *",
"* *",
"* This IOSv software is provided AS-IS without warranty of any kind. *",
"* Under no circumstances may this software be used separate from *",
"* the Cisco Modeling Labs Software that this software was provided *",
"* with, or deployed or used as part of a production environment. *",
"* *",
"* By using the software, you agree to abide by the terms and *",
"* conditions of the Cisco End User License Agreement at *",
"* http://www.cisco.com/go/eula. *",
"* *",
"* Unauthorized use or distribution of this software is expressly *",
"* prohibited. *",
"**************************************************************************",
"^C",
"banner login ^C",
"**************************************************************************",
"* IOSv - Cisco Systems Confidential *",
"* *",
"* Supplemental End User License Restrictions *",
"* *",
"* This IOSv software is provided AS-IS without warranty of any kind. *",
"* Under no circumstances may this software be used separate from *",
"* the Cisco Modeling Labs Software that this software was provided *",
"* with, or deployed or used as part of a production environment. *",
"* *",
"* By using the software, you agree to abide by the terms and *",
"* conditions of the Cisco End User License Agreement at *",
"* http://www.cisco.com/go/eula. *",
"* *",
"* Unauthorized use or distribution of this software is expressly *",
"* prohibited. *",
"**************************************************************************",
"^C",
"!",
"line con 0",
" password cisco",
"line aux 0",
"line vty 0 4",
" exec-timeout 720 0",
" password cisco",
" login local",
" transport input telnet ssh",
"!",
"no scheduler allocate",
"!",
"end"
]
}
META: ran handlers
META: ran handlers
PLAY RECAP **************************************************************************************************************************************************************************************************
ios01 : ok=1 changed=0 unreachable=0 failed=0
(ansible) [ansible-ios]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment