playbook_sysupgrade: make idempotent

only issue a sysupgrade if the desired garet version and profile
specified in the inventory does not match the firmware running on the
device.

Because we do not put the firmware files into this git, simply
clone the garet repo, checkout the desired commit, build the needed
profile and then put the firmware file into
  firmware/garet_${profile}-${version}.bin
prettify_jumphost_ansible
Gregor Michels 2022-10-24 00:00:07 +02:00
parent c51e5e438a
commit a9429b661a
1 changed files with 24 additions and 13 deletions

View File

@ -1,19 +1,30 @@
---
- name: upgrade firmware on openwrt device(s)
gather_facts: no
hosts: accesspoints
vars:
running_garet_profile: "{{ ansible_local['garet']['profile'] | default() }}"
running_garet_release: "{{ ansible_local['garet']['release'] | default() }}"
firmware_file: "firmware/garet_{{ garet_profile }}-{{ garet_release }}.bin"
gather_facts: no
tasks:
- name: upload new firmware
copy:
src: "{{ firmware_file }}"
dest: "/tmp/{{ firmware_file | basename }}"
- name: gather firmware version
setup:
filter: ansible_local
- name: issue sysupgrade command
command:
cmd: "sysupgrade /tmp/{{ firmware_file | basename }}"
ignore_errors: yes
- name: handle update
block:
- name: upload new firmware
copy:
src: "{{ firmware_file }}"
dest: "/tmp/{{ firmware_file | basename }}"
- name: wait till device is back online
wait_for_connection:
delay: 10
timeout: 600
- name: issue sysupgrade command
shell:
cmd: "sysupgrade /tmp/{{ firmware_file | basename }} && exit 0"
ignore_unreachable: yes
- name: wait till device is back online
wait_for_connection:
delay: 10
timeout: 600
when: garet_profile != running_garet_profile or garet_release != running_garet_release