--- # 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 }}"