Thursday, January 2, 2020

how to reboot network devices with Ansible

With Ansible Engine 2.9 there is now improved handling for wait_for_connection with network devices. This means that network devices can lose connectivity (for something like a reboot) and the Ansible Playbook can continue working as expected. You can perform some tasks, perform a reboot, the continue operating the Ansible Playbook programatically.

This requires two important steps that may be new for Ansible novices! (One), you need to deal with prompts, which are super common with network devices during a reboot, and (two), dealing with the connection going down programmatically.

For (One) you can use the cli_command module which deals with prompts, here is an example for a Cisco IOS routers->

--- - name: reboot ios device cli_command: command: reload prompt: - Save? - confirm answer: - y - y 

For (Two) you need to use the meta: reset_connection like this->

- name: reset the connection meta: reset_connection 

With the combination of (One) and (Two) you can now use the wait_for_connection with network devices. You can do something like this

--- - name: reboot ios device cli_command: command: reload prompt: - Save? - confirm answer: - y - name: reset the connection meta: reset_connection - name: Wait for the network device to reload wait_for_connection: delay: 10 

hopefully this will help some folks that need a programmatic way to reboot routers! I have written a small blog post here, but I didn't want to break rule #3 for reddit so I rewrote some portions to help folks that prefer only using reddit!



No comments:

Post a Comment