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
This commit is contained in:
parent
c51e5e438a
commit
a9429b661a
|
@ -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: gather firmware version
|
||||
setup:
|
||||
filter: ansible_local
|
||||
|
||||
- name: handle update
|
||||
block:
|
||||
- name: upload new firmware
|
||||
copy:
|
||||
src: "{{ firmware_file }}"
|
||||
dest: "/tmp/{{ firmware_file | basename }}"
|
||||
|
||||
- name: issue sysupgrade command
|
||||
command:
|
||||
cmd: "sysupgrade /tmp/{{ firmware_file | basename }}"
|
||||
ignore_errors: yes
|
||||
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
|
||||
|
|
Reference in New Issue