From a9429b661a50af446add2a58cacd1315b0d26feb Mon Sep 17 00:00:00 2001 From: Gregor Michels Date: Mon, 24 Oct 2022 00:00:07 +0200 Subject: [PATCH] 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 --- playbook_sysupgrade.yml | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/playbook_sysupgrade.yml b/playbook_sysupgrade.yml index 9e4e79f..a43b0f3 100644 --- a/playbook_sysupgrade.yml +++ b/playbook_sysupgrade.yml @@ -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