Windows: add Beszel agent update playbook; tolerate pending-restart blocks

- windows/update-beszel.yaml: scoop update of beszel-agent with NSSM service stop/start
- windows/update.yaml: with reboot=false, don't fail on updates blocked by a pending
  restart (WU_E_INSTALL_NOT_ALLOWED); report installed vs not installed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
JustinandClaude Opus 5.5 committed 2026-11-12 20:58:35 -06:00
1 parent fe3119cfaf
commit 011d427182
2 files changed
+65 -4

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
---
# 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
- name: Report
ansible.builtin.debug:
msg: "{{ before.stdout | trim }} -> {{ after.stdout | trim }}"
+11 -4
View File
@@ -42,12 +42,19 @@
reboot_timeout: 3600 reboot_timeout: 3600
register: result register: result
when: not search_only | bool when: not search_only | bool
# With reboot=false, updates blocked by the pending restart (WU_E_INSTALL_NOT_ALLOWED)
# are expected; only fail on other errors.
failed_when: >-
result.failed_update_count | default(0) | int > 0 and
(reboot | bool or
result.updates | dict2items | map(attribute='value')
| selectattr('failure_hresult_code', 'defined')
| rejectattr('failure_hresult_code', 'equalto', 2149842966) | list | length > 0)
- name: Report - name: Report
ansible.builtin.debug: ansible.builtin.debug:
msg: msg:
- "Installed: {{ result.installed_update_count }}" - "Installed: {{ result.updates | dict2items | map(attribute='value') | selectattr('installed') | map(attribute='title') | list }}"
- "Failed: {{ result.failed_update_count | default(0) }}" - "Not installed: {{ result.updates | dict2items | map(attribute='value') | rejectattr('installed') | map(attribute='title') | list }}"
- "Reboot still required: {{ result.reboot_required }}" - "Reboot still required: {{ result.reboot_required }}{{ ' - reboot and re-run to finish' if result.reboot_required else '' }}"
- "{{ result.updates | dict2items | map(attribute='value.title') | list }}"
when: not search_only | bool when: not search_only | bool