Feat/vm provision ansible #9
@@ -97,7 +97,7 @@
|
||||
state: present
|
||||
no_log: true
|
||||
|
||||
- name: Grow cloned scsi0 disk to requested size
|
||||
- name: Resize disk to requested size
|
||||
community.proxmox.proxmox_disk:
|
||||
vmid: "{{ cloned_vm.vmid }}"
|
||||
disk: scsi0
|
||||
@@ -105,25 +105,21 @@
|
||||
state: resized
|
||||
no_log: true
|
||||
|
||||
- name: Start configured VM
|
||||
- name: Start VM
|
||||
community.proxmox.proxmox_kvm:
|
||||
vmid: "{{ cloned_vm.vmid }}"
|
||||
state: started
|
||||
no_log: true
|
||||
|
||||
- name: Wait for guest DNS publication
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- getent
|
||||
- ahosts
|
||||
- "{{ vm_hostname }}.{{ vm_dns_domains[vm_vlan] }}"
|
||||
ansible.builtin.command: getent ahosts "{{ vm_hostname }}.{{ vm_dns_domains[vm_vlan] }}"
|
||||
register: guest_dns
|
||||
changed_when: false
|
||||
until: guest_dns.rc == 0 and guest_dns.stdout | length > 0
|
||||
retries: 30
|
||||
delay: 5
|
||||
|
||||
- name: Wait for guest SSH port after DNS resolution
|
||||
- name: Wait for guest SSH port
|
||||
ansible.builtin.wait_for:
|
||||
host: "{{ vm_hostname }}.{{ vm_dns_domains[vm_vlan] }}"
|
||||
port: 22
|
||||
@@ -131,7 +127,7 @@
|
||||
timeout: 180
|
||||
sleep: 5
|
||||
|
||||
- name: Add new guest to ephemeral inventory
|
||||
- name: Add VM to dynamic inventory
|
||||
ansible.builtin.add_host:
|
||||
name: "{{ vm_hostname }}.{{ vm_dns_domains[vm_vlan] }}"
|
||||
groups: provisioned_vm
|
||||
@@ -146,50 +142,34 @@
|
||||
vars:
|
||||
vm_timezone: Europe/Paris
|
||||
tasks:
|
||||
- name: Wait for Ansible connection with Python
|
||||
- name: Wait for guest to be available
|
||||
ansible.builtin.wait_for_connection:
|
||||
connect_timeout: 10
|
||||
sleep: 5
|
||||
timeout: 180
|
||||
|
||||
- name: Wait for cloud-init with an external bound
|
||||
ansible.builtin.raw: timeout 300 cloud-init status --wait --long
|
||||
- name: Wait for cloud-init status
|
||||
ansible.builtin.command: timeout 300 cloud-init status --wait --long
|
||||
register: cloudinit_wait
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Show cloud-init wait diagnostics
|
||||
ansible.builtin.debug:
|
||||
msg:
|
||||
- "stdout: {{ cloudinit_wait.stdout | trim }}"
|
||||
- "stderr: {{ cloudinit_wait.stderr | trim }}"
|
||||
|
||||
- name: Require completed cloud-init
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- cloudinit_wait.rc in [0, 2]
|
||||
- "cloudinit_wait.stdout is search('(?m)^status: done\\s*$')"
|
||||
fail_msg: "VMID {{ provisioned_vmid }} cloud-init status is not complete (rc {{ cloudinit_wait.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
|
||||
|
||||
- name: Read guest timezone
|
||||
ansible.builtin.command: timedatectl show --property=Timezone --value
|
||||
register: guest_timezone_before
|
||||
changed_when: false
|
||||
- name: Assert cloud-init completion
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- cloudinit_wait.rc in [0, 2]
|
||||
- "cloudinit_wait.stdout is search('(?m)^status: done\\s*$')"
|
||||
fail_msg: "VMID {{ provisioned_vmid }} cloud-init status is not complete (rc {{ cloudinit_wait.rc }}); VM left intact for inspection."
|
||||
|
||||
- name: Set guest display timezone
|
||||
ansible.builtin.command:
|
||||
argv: [timedatectl, set-timezone, "{{ vm_timezone }}"]
|
||||
- name: Set guest timezone
|
||||
ansible.builtin.command: timedatectl set-timezone "{{ vm_timezone }}"
|
||||
become: true
|
||||
when: guest_timezone_before.stdout | trim != vm_timezone
|
||||
|
||||
- name: Verify final Ansible ping
|
||||
ansible.builtin.ping:
|
||||
|
||||
- name: Report verified guest readiness
|
||||
ansible.builtin.debug:
|
||||
msg: "VMID {{ provisioned_vmid }} at {{ inventory_hostname }} completed cloud-init and returned Ansible pong."
|
||||
msg: "VMID {{ provisioned_vmid }} at {{ inventory_hostname }} completed cloud-init."
|
||||
Reference in new issue
Block a user