From 53f4d276015c3ad60ba60bd96d9b28be785f1c4f Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Tue, 10 Nov 2026 16:06:21 +0000 Subject: [PATCH] feat(ansible): provision QEMU guest agent on new clones --- ansible/proxmox/README.md | 2 +- ansible/proxmox/provision_vm.yml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ansible/proxmox/README.md b/ansible/proxmox/README.md index f39b1d0..89caa5d 100644 --- a/ansible/proxmox/README.md +++ b/ansible/proxmox/README.md @@ -16,4 +16,4 @@ In a Semaphore Variable Group, set fixed `proxmox_api_host` (hostname, not URL), Only `vlan66` maps to `lab.vezpi.com` in the playbook; unknown VLANs fail before API provisioning. `vm_hostname` must be a single short DNS label (no dots). DHCP/DNS must publish `.lab.vezpi.com` for the chosen VNet; a derived name is not proof of a current record. Stale/reused DNS can point at another host: verify record ownership and the new guest's SSH host key out of band before running. Never trust an unverified `ssh-keyscan` result or disable host-key checking. -Use a template with bootable `scsi0`, a `scsi1` cloud-init drive, Python 3, `cloud-init`, `timeout`, SSH and a reachable guest network. Select an SSH Key Store **user credential on the task inventory** whose private key matches one authorized public key for `vm_user`; the same Ansible invocation's inventory credential must be available to the dynamically added guest (verify this in the installed Semaphore version). The localhost API token is separate. Pre-enroll a verified guest host key in the runner's trusted `known_hosts` using a Captain-approved mechanism; no private key path or trust bypass is configured here. DNS, SSH port, Python-capable Ansible connection, cloud-init wait/status and final Ansible ping are bounded stages. The connection check retries transient transport failures within its timeout; Python 3 is required in the image. Completed cloud-init status accepts rc 0 or degraded rc 2, prints `--long` diagnostics and warns on rc 2; other codes, incomplete status and timeouts fail. A failed or timed-out VM remains for Captain to inspect, not delete. After accepted cloud-init completion, the guest timezone is read and, if needed, set to `Europe/Paris` (CET/CEST); RTC and NTP are untouched. The guest needs `timedatectl`, timezone data (`tzdata`), and authorized noninteractive sudo/become for `vm_user` when a timezone change is needed. If these are unavailable, readiness fails; no sudo configuration, package installation or reboot is added. +Use a template with bootable `scsi0`, a `scsi1` cloud-init drive, Python 3, `cloud-init`, `timeout`, SSH and a reachable guest network; the template need not have the agent enabled. Select an SSH Key Store **user credential on the task inventory** whose private key matches one authorized public key for `vm_user`; the same Ansible invocation's inventory credential must be available to the dynamically added guest (verify this in the installed Semaphore version). The localhost API token is separate. Pre-enroll a verified guest host key in the runner's trusted `known_hosts` using a Captain-approved mechanism; no private key path or trust bypass is configured here. The clone enables its virtio guest-agent channel before first start. DNS, SSH port, Ansible connection and cloud-init wait/status are bounded stages; the connection check retries transient transport failures within its timeout. Completed cloud-init status accepts rc 0 or degraded rc 2 and warns on rc 2; other codes, incomplete status and timeouts fail. After accepted cloud-init completion, the guest sets its timezone to `Europe/Paris` (CET/CEST); RTC and NTP are untouched. The guest needs `timedatectl`, timezone data (`tzdata`), apt access and authorized noninteractive sudo/become for `vm_user`. It installs `qemu-guest-agent` with apt, checks for the virtio port and starts the package's device-activated service (no manual enablement of its static unit). Any failure leaves the new VM intact for inspection; no sudo configuration or reboot is added. Playbook success does not verify Proxmox agent communication: on the new VM's actual node, Captain checks `qm agent ping` (successful exit with no error; an empty response is valid). diff --git a/ansible/proxmox/provision_vm.yml b/ansible/proxmox/provision_vm.yml index b72a43f..0640116 100644 --- a/ansible/proxmox/provision_vm.yml +++ b/ansible/proxmox/provision_vm.yml @@ -94,6 +94,7 @@ ipconfig0: "{{ vm_ipconfig0 }}" ciuser: "{{ vm_user }}" sshkeys: "{{ vm_ssh_public_key }}" + agent: "enabled=1,type=virtio" state: present no_log: true @@ -170,6 +171,23 @@ ansible.builtin.command: timedatectl set-timezone "{{ vm_timezone }}" become: true + - name: Install QEMU guest agent + ansible.builtin.apt: + name: qemu-guest-agent + state: present + become: true + + - name: Require QEMU guest agent virtio channel in guest + ansible.builtin.command: + argv: [test, -e, /dev/virtio-ports/org.qemu.guest_agent.0] + changed_when: false + + - name: Start QEMU guest agent + ansible.builtin.service: + name: qemu-guest-agent + state: started + become: true + - name: Report verified guest readiness ansible.builtin.debug: msg: "VMID {{ provisioned_vmid }} at {{ inventory_hostname }} completed cloud-init."