Files
meshcore-ansible/examples/firmware-ota.yml
T
tthandClaude Opus 5.5 8884742ae2
ci / test (push) Failing after 24s
examples/firmware-ota.yml: the side channel (ota_side)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 00:18:34 +01:00

108 lines
4.4 KiB
YAML

# OTA firmware update from a public release of meshcore-tth -- the repeaters
# must already run an -ota image of the same artifact (the first one goes by
# a regular flash, see the meshcore-tth README).
#
# ansible-playbook -i inventory.yml firmware-ota.yml -e ota_release=v1.18.0+tth.20261114.3 --check
# ansible-playbook -i inventory.yml firmware-ota.yml -e ota_release=v1.18.0+tth.20261114.3
#
# Play 1 downloads the release's packages for the artifact on the controller and
# refuses them unless SHA256SUMS carries the release signature and every file
# matches it. Keep ota_allowed_signers (tools/ota_allowed_signers of
# meshcore-tth) next to this playbook: a key fetched from the same server as
# the release would prove nothing. Play 2 copies them next to the companion and
# lets the module pick the delta that fits each repeater's image.
- name: Release packages
hosts: localhost
gather_facts: false
vars:
ota_artifact: SenseCap_Solar_repeater-observer-ota
ota_api: https://git.rfa.cz/api/v1/repos/tth-pub/meshcore-tth
ota_dir: "{{ playbook_dir }}/ota/{{ ota_release }}"
ota_signers: "{{ playbook_dir }}/ota_allowed_signers"
tasks:
- name: Release {{ ota_release }}
ansible.builtin.uri:
url: "{{ ota_api }}/releases/tags/{{ ota_release | urlencode }}"
register: ota_rel
check_mode: false
- name: Download directory
ansible.builtin.file:
path: "{{ ota_dir }}/mcfw"
state: directory
mode: "0755"
check_mode: false
- name: Manifest and the signed checksums
ansible.builtin.get_url:
url: "{{ (ota_rel.json.assets | selectattr('name', 'eq', item) | first).browser_download_url }}"
dest: "{{ ota_dir }}/{{ item }}"
mode: "0644"
loop: [manifest.json, SHA256SUMS, SHA256SUMS.sig]
check_mode: false
- name: Signature of SHA256SUMS
ansible.builtin.shell: >-
ssh-keygen -Y verify -f {{ ota_signers | quote }} -I meshcore-ota@tth-pub -n meshcore-ota
-s {{ (ota_dir ~ '/SHA256SUMS.sig') | quote }} < {{ (ota_dir ~ '/SHA256SUMS') | quote }}
changed_when: false
check_mode: false
- name: Packages of {{ ota_artifact }}
ansible.builtin.set_fact:
ota_names: "{{ [_ota.full] + (_ota.deltas | dict2items | map(attribute='value.file') | list) }}"
ota_sums: "{{ dict(lookup('file', ota_dir ~ '/SHA256SUMS').splitlines() | map('split') | map('reverse')) }}"
vars:
_ota: "{{ (lookup('file', ota_dir ~ '/manifest.json') | from_json).envs[ota_artifact].ota }}"
# only the artifact's .mcfw files, so the module sees nothing else there
- name: Download them, each checked against SHA256SUMS
ansible.builtin.get_url:
url: "{{ (ota_rel.json.assets | selectattr('name', 'eq', item) | first).browser_download_url }}"
dest: "{{ ota_dir }}/mcfw/{{ item }}"
checksum: "sha256:{{ ota_sums[item] }}"
mode: "0644"
loop: "{{ ota_names }}"
check_mode: false
- name: OTA update
hosts: meshcore_repeaters
gather_facts: false
serial: 1 # RF: one repeater at a time
vars:
meshcore_admin_password: "{{ vault_meshcore_admin_password }}"
ota_dir: "{{ playbook_dir }}/ota/{{ ota_release }}/mcfw/"
tasks:
- name: Packages next to the companion
ansible.builtin.copy:
src: "{{ ota_dir }}"
dest: /tmp/meshcore-ota/
mode: "0644"
delegate_to: "{{ mc_via }}"
check_mode: false
# --check: reads `fw status` and says which package would go. A delta of
# ~25 kB over two hops takes ~40 min at duty 3; the node keeps what it got,
# so a stopped transfer goes on with resume: true.
- name: Update
tth.meshcore.meshcore_fw_ota:
transport: "{{ mc_transport }}"
target: "{{ mc_target }}"
password: "{{ meshcore_admin_password }}"
packages: /tmp/meshcore-ota/
duty: 3
# Off the shared channel: set ota_side (e.g. -e ota_side=869.525,62.5,7,5)
# and point mc_transport/mc_via at a MeshCore companion in direct range
# of the node (not an openHop virtual one -- it cannot retune).
side: "{{ ota_side | default(omit) }}"
delegate_to: "{{ mc_via }}"
async: 7200
poll: 30
register: ota
- name: Result
ansible.builtin.debug:
msg: >-
{{ inventory_hostname }}: {{ ota.state }} {{ ota.package | default('') }}
{{ '-- no delta from ' ~ ota.base ~ ', flash the full image' if ota.no_package else '' }}