After completing this section, you should be able to use Ansible to upgrade the operating system of network devices in your environment.
An important DevNetOps role involves vigilance and prompt action concerning security updates. This often entails upgrading the network OS on devices. How that happens depends on the platform. The process of upgrading a network OS is illustrated here using VyOS, because VyOS has a single, simple, upgrade methodology. An overview is given of the process of upgrading IOS devices.
Be sure to thoroughly test and verify automation processes before involving production resources.
Upgrading IOS on Cisco devices typically involves these steps, each of which can be automated with Ansible:
Gather information (facts).
Obtain an updated image and copy it to device flash.
Set the device to boot from the new image.
Ensure that the running configuration is saved and backed up.
Reload the device.
Verify connectivity and functionality when the boot sequence finishes.
VyOS has a simpler upgrade procedure.
An upgrade method for VyOS:
Store the URL of the new image in a variable.
Get the old system image.
Download a fresh image.
Get a new system image.
Reload only if the new image is different from the old image.
Wait for restart.
A more sophisticated method avoids downloading the new image unless needed.
# sysimg_url var defined in group_vars
- name: a play that upgrades a VyOS device
hosts: spine02
gather_facts: no
tasks:
- name: get old system image information
vyos_command:
commands:
- show system image
register: old_system_image
- name: download fresh system image
vyos_command:
commands:
- add system image {{ sysimg_url }}
- name: get new system image information
vyos_command:
commands:
- show system image
register: new_system_image
- name: reload only if changed
vyos_command:
commands:
- command: reboot now
ignore_errors: yes
when: old_system_image.stdout != new_system_image.stdout
- name: wait for restart
wait_for_connection:
delay: 20
timeout: 120
when: old_system_image.stdout != new_system_image.stdout