ce7e2bc205
Claude-Session: https://claude.ai/code/session_01JEczyvRjfakkiDNkbZA7PR
40 lines
1.4 KiB
YAML
40 lines
1.4 KiB
YAML
---
|
|
# Installs and enables the QEMU guest agent on VMs (group "vms") so Proxmox
|
|
# can query IPs, quiesce filesystems for snapshots and shut the VM down cleanly.
|
|
# The VM also needs the agent enabled on the Proxmox side:
|
|
# qm set <vmid> --agent enabled=1 (then power-cycle the VM once)
|
|
|
|
- name: VM Guest Agent - Install and enable qemu-guest-agent
|
|
hosts: vms
|
|
become: true
|
|
gather_facts: true
|
|
|
|
tasks:
|
|
- name: Install qemu-guest-agent
|
|
ansible.builtin.package:
|
|
name: qemu-guest-agent
|
|
state: present
|
|
|
|
- name: Check whether the guest agent virtio port is present
|
|
ansible.builtin.stat:
|
|
path: /dev/virtio-ports/org.qemu.guest_agent.0
|
|
register: agent_port
|
|
|
|
- name: Enable and start qemu-guest-agent
|
|
ansible.builtin.systemd:
|
|
name: qemu-guest-agent
|
|
enabled: true
|
|
state: started
|
|
when: agent_port.stat.exists
|
|
|
|
- name: Warn when the agent device is missing
|
|
ansible.builtin.debug:
|
|
msg: "WARNING: {{ inventory_hostname }} has no guest agent device - run 'qm set <vmid> --agent enabled=1' on the Proxmox host and power-cycle the VM"
|
|
when: not agent_port.stat.exists
|
|
|
|
- name: Summary
|
|
ansible.builtin.debug:
|
|
msg: >-
|
|
{{ inventory_hostname }} ({{ ansible_virtualization_type | default('unknown') }}) -
|
|
qemu-guest-agent {{ 'RUNNING' if agent_port.stat.exists else 'NOT AVAILABLE' }}
|