Files
Ansible/windows/update-beszel.yaml
T
JustinandClaude Opus 5.5 84433d5cbc Beszel: fail on silent update failures and crashed agents
- Windows: fail if a scoop update ran but the agent version didn't change
- Ubuntu: after restarting an upgraded agent, check it is still active

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-17 15:38:08 -06:00

60 lines
2.0 KiB
YAML

---
# Upgrade the Beszel agent on Windows hosts.
# Agent is installed with scoop (in the login user's profile) and run as an NSSM service "beszel-agent".
# Service is stopped during the update because Windows locks the running exe.
- name: Upgrade Beszel agent (Windows)
hosts: windows
gather_facts: false
vars:
scoop: 'C:\Users\Justin\scoop\shims\scoop.ps1'
agent_exe: 'C:\Users\Justin\scoop\shims\beszel-agent.exe'
service: beszel-agent
tasks:
- name: Get current version
ansible.windows.win_command: '"{{ agent_exe }}" -v'
register: before
changed_when: false
- name: Update scoop buckets
ansible.windows.win_shell: '& "{{ scoop }}" update'
changed_when: false
- name: Check whether an update is available
ansible.windows.win_shell: '& "{{ scoop }}" status 2>&1 | Out-String'
register: status
changed_when: false
- name: Update agent
when: "'beszel-agent' in status.stdout"
block:
- name: Stop service
ansible.windows.win_service:
name: "{{ service }}"
state: stopped
- name: Scoop update beszel-agent
ansible.windows.win_shell: '& "{{ scoop }}" update beszel-agent 2>&1 | Out-String'
register: upd
always:
- name: Start service
ansible.windows.win_service:
name: "{{ service }}"
state: started
- name: Get new version
ansible.windows.win_command: '"{{ agent_exe }}" -v'
register: after
changed_when: before.stdout != after.stdout
# scoop's exit code is lost through Out-String, so a failed update would otherwise
# look like success. If an update was attempted, the version must have changed.
failed_when: >-
after.rc != 0 or
(upd is not skipped and before.stdout | trim == after.stdout | trim)
- name: Report
ansible.builtin.debug:
msg: "{{ before.stdout | trim }} -> {{ after.stdout | trim }}"