I was using Ansible playbooks to configure Cisco IOS routers running in VIRL and wanted to extract the router configurations before stopping the simulation.
Unfortunately, VIRL extracts startup configurations not running ones, so I’d have to log into each router and execute write memory (the command youngsters know as copy running startup). Making it worse, my lab had six routers. Yes, I know, I have first-world problems.
Fortunately, I was using Ansible, and had the inventory file describing all the routers, so it should be relatively easy to execute write memory on all of them with the raw module, but my default Ansible connection plugin was local to make networking modules work correctly.
Update 2017-02-14: As Nikolay pointed out in the comments, I might be able to use the ios_command module.
Here’s the workaround that worked for me: specify connection plugin to use with the –c command line option:
ansible all -i hosts -m raw -c paramiko -a "write mem"
And here’s another gotcha: the –c command line option supersedes the transport option in ansible.cfg but not the ansible_connection variable specified on a host or a group of hosts in inventory file, so make sure you specify the default connection method in the right place.
Want to do something similar?
It’s amazing how many small problems you can solve once you have an infrastructure like Ansible in place. To learn more about using Ansible for network automation, watch the Ansible for Networking Engineers webinar, and if you want to get your own real-life network automation project off the ground, sign up for the Building Network Automation Solutions online course.