feat(ansible): accept degraded cloud-init and set guest timezone

This commit is contained in:
Hermes Agent committed 2026-11-09 12:47:58 +00:00
1 parent ee9d19a781
commit ef9b4454ff
2 files changed
+48 -8

No files matched your search

+1 -1
View File
@@ -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 `<hostname>.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. 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 `<hostname>.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. Nonzero cloud-init status fails; a failed or timed-out VM remains for Captain to inspect, not delete. No guest agent, package installation, sudo changes or reboot are added. 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 verified as `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.
+47 -7
View File
@@ -171,6 +171,8 @@
- name: Verify cloud-init and Ansible on the new guest - name: Verify cloud-init and Ansible on the new guest
hosts: provisioned_vm hosts: provisioned_vm
gather_facts: false gather_facts: false
vars:
vm_timezone: Europe/Paris
tasks: tasks:
- name: Wait for Ansible connection with Python - name: Wait for Ansible connection with Python
ansible.builtin.wait_for_connection: ansible.builtin.wait_for_connection:
@@ -179,28 +181,66 @@
timeout: 180 timeout: 180
- name: Wait for cloud-init with an external bound - name: Wait for cloud-init with an external bound
ansible.builtin.raw: timeout 300 cloud-init status --wait ansible.builtin.raw: timeout 300 cloud-init status --wait --long
register: cloudinit_wait register: cloudinit_wait
changed_when: false changed_when: false
failed_when: false failed_when: false
- name: Require cloud-init wait to succeed - name: Show cloud-init wait diagnostics
ansible.builtin.debug:
msg:
- "stdout: {{ cloudinit_wait.stdout | trim }}"
- "stderr: {{ cloudinit_wait.stderr | trim }}"
- name: Require cloud-init wait to complete
ansible.builtin.assert: ansible.builtin.assert:
that: cloudinit_wait.rc == 0 that: cloudinit_wait.rc in [0, 2]
fail_msg: "VMID {{ provisioned_vmid }} cloud-init wait failed (rc {{ cloudinit_wait.rc }}); VM left intact for inspection." fail_msg: "VMID {{ provisioned_vmid }} cloud-init wait failed (rc {{ cloudinit_wait.rc }}); VM left intact for inspection."
- name: Read final cloud-init status - name: Read final cloud-init status
ansible.builtin.raw: cloud-init status ansible.builtin.raw: cloud-init status --long
register: cloudinit_status register: cloudinit_status
changed_when: false changed_when: false
failed_when: false failed_when: false
- name: Require successful completed cloud-init - name: Show final cloud-init diagnostics
ansible.builtin.debug:
msg:
- "stdout: {{ cloudinit_status.stdout | trim }}"
- "stderr: {{ cloudinit_status.stderr | trim }}"
- name: Require completed cloud-init
ansible.builtin.assert: ansible.builtin.assert:
that: that:
- cloudinit_status.rc == 0 - cloudinit_status.rc in [0, 2]
- "cloudinit_status.stdout is search('(?m)^status: done\\s*$')" - "cloudinit_status.stdout is search('(?m)^status: done\\s*$')"
fail_msg: "VMID {{ provisioned_vmid }} cloud-init status is not successful (rc {{ cloudinit_status.rc }}); VM left intact for inspection." fail_msg: "VMID {{ provisioned_vmid }} cloud-init status is not complete (rc {{ cloudinit_status.rc }}); VM left intact for inspection."
- name: Warn about degraded cloud-init completion
ansible.builtin.debug:
msg: "VMID {{ provisioned_vmid }} cloud-init completed with degraded status (rc 2); individual cloud-init operations may not have succeeded. Inspect the diagnostics before relying on this guest."
when: cloudinit_wait.rc == 2 or cloudinit_status.rc == 2
- name: Read guest timezone
ansible.builtin.command: timedatectl show --property=Timezone --value
register: guest_timezone_before
changed_when: false
- name: Set guest display timezone
ansible.builtin.command:
argv: [timedatectl, set-timezone, "{{ vm_timezone }}"]
become: true
when: guest_timezone_before.stdout | trim != vm_timezone
- name: Verify guest timezone
ansible.builtin.command: timedatectl show --property=Timezone --value
register: guest_timezone_after
changed_when: false
- name: Require configured guest timezone
ansible.builtin.assert:
that: guest_timezone_after.stdout | trim == vm_timezone
fail_msg: "VMID {{ provisioned_vmid }} guest timezone did not become {{ vm_timezone }}; VM left intact for inspection."
- name: Verify final Ansible ping - name: Verify final Ansible ping
ansible.builtin.ping: ansible.builtin.ping: