Upgrading the Network Operating System on devices can be an important part of ongoing maintenance for the sake of avoiding or eliminating software defects, including security vulnerabilities.
In this exercise, you will compose and perform a play with the ability to automatically upgrade a VyOS network device.
Outcomes
You should be able to:
Compose a play with the ability to upgrade a VyOS network device.
Perform the play in check-only mode to determine what effect it would have in change mode.
Open a terminal window on the workstation VM and change to the ~/proj/ directory.
Compose a play with the ability to upgrade a VyOS network device.
Create a playbook named vyos-upgrade.yml with the following contents:
---
- name: a play that upgrades a VyOS device
hosts: vyos
vars:
sysimg_url: https://downloads.vyos.io/release/1.1.8/vyos-1.1.8-amd64.iso
tasks:
- name: abort unless target host has ansible_network_os == 'vyos'
assert:
that: "ansible_network_os == 'vyos'"
- name: get old system image information
vyos_command:
commands:
- show system image
register: old_system_image
- name: show old system image information
debug:
msg: "{{ old_system_image.stdout }}"
- 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: show new system image information
debug:
msg: "{{ new_system_image.stdout }}"
- name: reboot the system
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
Perform the play in check-only mode to determine what effect it would have in change mode.
Execute the ansible-playbook command using the --check or -C option.
Limit it to spine01.
[student@workstation proj]$ansible-playbook -C -l spine01 vyos-upgrade.ymlPLAY [a play that upgrades a VyOS device] ************************************** TASK [abort unless target host has ansible_network_os == 'vyos'] *************** ok: [spine01] => { "changed": false, "msg": "All assertions passed" } TASK [get old system image information] **************************************** ok: [spine01] TASK [show old system image information] *************************************** ok: [spine01] => { "msg": [ "The system currently has the following image(s) installed:\n\n 1: 1.1.8 (default boot)" ] } TASK [download fresh system image] ********************************************* [WARNING]: only show commands are supported when using check mode, not executing `add system image https://downloads.vyos.io/release/1.1.8/vyos-1.1.8-amd64.iso` ok: [spine01] TASK [get new system image information] **************************************** ok: [spine01] TASK [show new system image information] *************************************** ok: [spine01] => { "msg": [ "The system currently has the following image(s) installed:\n\n 1: 1.1.8 (default boot)" ] } TASK [reboot the system] ******************************************************* skipping: [spine01] TASK [wait for restart] ******************************************************** skipping: [spine01] PLAY RECAP ********************************************************************* spine01 : ok=6 changed=0 unreachable=0 failed=0
This concludes the guided exercise.