This Ansible script runs commands on remote Cisco IOS XE device and retrieve the result into output folder. The script gathers the IOS Facts Information. In the example script the command is "show running-config" to get baackup. But thos can be any command ie "show tech-support"
---
all:
children:
all_cisco_ios:
hosts:
r4:
inventory_network_os: cisco.ios.ios
inventory_host: 192.168.1.14
inventory_port: 22
inventory_user: admin
inventory_pass: password
all_cisco_asa:
hosts:
ciscoasa1:
inventory_network_os: cisco.asa.asa
inventory_network_cisco_asa_type: vpn
inventory_network_cisco_asa_ha_type: standalone
inventory_host: 192.168.1.98
inventory_port: 22
inventory_user: admin
inventory_pass: password
all_f5:
hosts:
bigip1:
inventory_network_os: f5.bigip
inventory_host: 192.168.1.245
inventory_port: 443
inventory_user: admin
inventory_pass: password
bigip2:
inventory_network_os: f5.bigip
inventory_host: 192.168.1.246
inventory_port: 443
inventory_user: admin
inventory_pass: password
bigip3:
inventory_network_os: f5.bigip
inventory_host: 192.168.1.247
inventory_port: 443
inventory_user: admin
inventory_pass: password
Ansible ansible-pylibssh modules must be installed before running the script.
pip install ansible-pylibssh
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -vvvv --vault-password-file vault_pass.yaml -i inventory-vault.yaml cisco-ios-command.yml --extra-vars="ios_device=r4"
NOTE: output
folder must be created before running the script.
- cisco-ios-command.yml >> Ansible script file
- vault_pass.yaml >> Inventory vault password information
- inventory-vault.yaml >> Inventory vault file encrypted by "Inventory vault password"
ios_device
variable shows which Cisco ASA device/devices will be connected.The value can be "r4", "r1" etc. or "all_cisco_ios" as per the example inventory file above.
- r4-2024-06-21-22-00-45.facts
- r4-2024-06-21-22-00-45.txt