My Ansible playbook to update VyOS system

I just want to share my playbook to upgrade VyOS image with Ansible.
This playbook copies local iso file, (version 1.2.8 in my playbook).
Installs system with add system image
Schedules a reboot at ~4:30 in the morning.
Clean up old installation file.

Tested with ansible 2.9.14

---
- name: VyOS - install new image and schedule machine reboot.
  gather_facts: False
  vars:
    vyos_version: 1.2.8
    vyos_dir: "files/"
    vyos_file: "vyos-{{vyos_version}}-amd64.iso"
  hosts:
    - vyosrouter

  tasks:
    - name: "Copying {{vyos_file}} to system"
      net_put:
        src: "{{ vyos_dir }}{{ vyos_file }}"
        dest: "{{ vyos_file }}"

    - name: "Installing {{vyos_version}} on system"
      cli_command:
        command: add system image "{{ vyos_file }}"
        newline: True
        check_all: True
        prompt:
        - 'What would you like to name this image'
        - 'directory and config file'
        - 'current configuration'
        answer:
        - "{{ vyos_version }}"
        - 'Yes'
        - 'Yes'

    - name: Schedule reboot around 04:30 tonight
      cli_command:
        command: "reboot at 04:{{ range(25,35) | random }}"

    - name: Cleanup installation file
      cli_command:
        command: "rm {{ vyos_file }}"
3 Likes