Skip to content

Commit 8b26981

Browse files
committed
create openwrt_upgrade.yml playbook to do openwrt firmware updates
Because of the way gekmihesg.openwrt works with its monkeypatching, and we want the upgrade process and its reboots to be serialised so we never lose all hosts at once, it's not simply a matter of calling the upgrade process then the maintenance playbook or its roles, so there's duplicated code between openwrt_upgrade.yml and openwrt_maintenace.yml. It's not elegant, but it seems to work. Also removed gather_facts from openwrt_maintenance.yml since discovered gather_facts was set and doesn't seem to be needed
1 parent af2c0d0 commit 8b26981

File tree

5 files changed

+75
-3
lines changed

5 files changed

+75
-3
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,28 @@ quickly install packages, update files, etc) unless told otherwise:
212212

213213
`$ ansible-playbook openwrt_maintenance.yml --diff --extra-vars "run_uci_config=yes"`
214214

215+
We can also issue firmware patches, and then run the configuration
216+
update step again (which assumes run_uci_config=yes):
217+
218+
`$ ansible-playbook openwrt_upgrade.yml --diff`
219+
220+
Firmware files are assumed to be kept under
221+
roles/openwrt/files/firmware/, which in my case contains symlinks back
222+
to where I keep the firmware images. Update `firmware_image` in
223+
hosts.yml and run this playbook whenever you want to issue an upgrade.
224+
It will run across all devices in your inventory unless you --limit
225+
them, so long as they have firmware_image set. If unset for a
226+
particular device, that device never gets patched by this playbook.
227+
228+
Keep in mind this playbook is much more likely to fail than the
229+
openwrt_maintenance one, because who knows what assumptions we make or
230+
your configuration makes that will break in each update (be careful of
231+
migrations to DSA switches, as always), so keep firm backups (or be
232+
prepared to run the playbook multiple times until you get it right).
233+
But in this play, devices are serialised so you never have more than
234+
one device out at a time, and failure halts the play so shouldn't
235+
extend beyond more than one device if not --limited.
236+
215237
There's also a playbook just to run single shell commands from the commandline:
216238

217239
`$ ansible-playbook openwrt_shell.yml -e "cmd='id'"`

hosts.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ all:
594594
openwrt_heavy_installation: true
595595
inet_addr_suffix: 244
596596

597+
firmware_image: vm/openwrt-24.10.1-x86-64-generic-squashfs-combined-efi.img.gz
598+
597599
packages_to_install: 'qemu-ga,pciutils,iwlwifi-firmware-ax200,kmod-iwlwifi'
598600

599601
# mode_5ghz: AC

openwrt_maintenance.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
- hosts: "{{ target | default('openwrt') }}"
44
# strategy: free
55
strategy: linear
6-
# gather_facts: no
6+
gather_facts: no
77
remote_user: "{{ remote_user | default('rootsh') }}" # so keeps working even fresh after upgrade, but not on a brand-new installation - supply '-e remote_user=root' for a new installation
88
vars:
9-
ansible_ssh_transfer_method: scp
10-
ansible_scp_extra_args: -O #https://github.com/gekmihesg/ansible-openwrt/pull/59 https://github.com/gekmihesg/ansible-openwrt/issues/64 https://github.com/ansible/ansible/issues/82239 https://github.com/gekmihesg/ansible-openwrt/pull/67
9+
ansible_ssh_transfer_method: scp
10+
ansible_scp_extra_args: -O #https://github.com/gekmihesg/ansible-openwrt/pull/59 https://github.com/gekmihesg/ansible-openwrt/issues/64 https://github.com/ansible/ansible/issues/82239 https://github.com/gekmihesg/ansible-openwrt/pull/67
1111
vars_files:
1212
- vars/openwrt.yml
1313
roles:

openwrt_upgrade.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
# https://stackoverflow.com/questions/18195142/safely-limiting-ansible-playbooks-to-a-single-machine
3+
- hosts: "{{ target | default('openwrt') }}"
4+
# strategy: free
5+
strategy: linear
6+
serial: 1
7+
gather_facts: no
8+
remote_user: "{{ remote_user | default('rootsh') }}" # so keeps working even fresh after upgrade, but not on a brand-new installation - supply '-e remote_user=root' for a new installation
9+
vars:
10+
ansible_ssh_transfer_method: scp
11+
ansible_scp_extra_args: -O #https://github.com/gekmihesg/ansible-openwrt/pull/59 https://github.com/gekmihesg/ansible-openwrt/issues/64 https://github.com/ansible/ansible/issues/82239 https://github.com/gekmihesg/ansible-openwrt/pull/67
12+
run_uci_config: yes
13+
roles:
14+
- role: gekmihesg.openwrt
15+
tasks:
16+
- name: update firmware on {{ openwrt_user_host }}
17+
block:
18+
- name: copy openwrt image
19+
command: "{{ openwrt_scp }} roles/openwrt/files/firmware/{{ firmware_image }} {{ openwrt_user_host|quote }}:/tmp/sysupgrade.bin"
20+
delegate_to: localhost
21+
- name: start sysupgrade
22+
nohup:
23+
command: sysupgrade -q /tmp/sysupgrade.bin
24+
- name: wait for reboot
25+
wait_for_connection:
26+
timeout: 300
27+
delay: 60
28+
29+
- name: "import normal maintenance vars and run maintenance cycle (with 'run_uci_config=yes')"
30+
include_vars: vars/openwrt.yml
31+
- include_role:
32+
name: gekmihesg.openwrt
33+
tasks_from: packages
34+
- include_role:
35+
name: install_files
36+
- include_role:
37+
name: openwrt
38+
39+
- name: final after configuration reboot
40+
command: reboot
41+
42+
- name: wait for final reboot
43+
wait_for_connection:
44+
timeout: 300
45+
delay: 60
46+
when: firmware_image is defined
47+
any_errors_fatal: true

roles/openwrt/files/firmware/vm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/tconnors/install/gateway-vm

0 commit comments

Comments
 (0)