- 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]>
55 lines
1.7 KiB
YAML
55 lines
1.7 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
|
|
|
|
- name: Report
|
|
ansible.builtin.debug:
|
|
msg: "{{ before.stdout | trim }} -> {{ after.stdout | trim }}"
|