From ff691bae3d9f13aa7514dd1dbdcd206045f16e6a Mon Sep 17 00:00:00 2001 From: Jose Date: Sat, 15 Nov 2025 21:49:12 +0100 Subject: [PATCH] Use fqdn for ansible.builtin modules --- tasks/configure-vm.yml | 44 +++++++++++++++++++------------------- tasks/create-clones.yml | 28 ++++++++++++------------ tasks/create-template.yml | 22 +++++++++---------- tasks/create-vm.yml | 12 +++++------ tasks/download-image.yml | 10 ++++----- tasks/helpers.yml | 32 +++++++++++++-------------- tasks/main.yml | 18 ++++++++-------- tasks/preflight-checks.yml | 36 +++++++++++++++---------------- 8 files changed, 101 insertions(+), 101 deletions(-) diff --git a/tasks/configure-vm.yml b/tasks/configure-vm.yml index f3a3315..dab7e05 100644 --- a/tasks/configure-vm.yml +++ b/tasks/configure-vm.yml @@ -4,7 +4,7 @@ - name: "[CONFIG] Configure UEFI + Secure Boot + TPM (if enabled)" block: - name: "[CONFIG] Enable UEFI and TPM" - command: > + ansible.builtin.command: > qm set {{ vm_id }} --bios ovmf --efidisk0 {{ storage }}:0,pre-enrolled-keys=1 @@ -13,7 +13,7 @@ changed_when: tpm_config.rc == 0 - name: "[CONFIG] Verify TPM configuration" - debug: + ansible.builtin.debug: msg: "✓ UEFI + TPM configured for VM {{ vm_id }}" when: enable_tpm | default(false) @@ -21,13 +21,13 @@ - name: "[CONFIG] Import and attach disk" block: - name: "[CONFIG] Check if disk already exists" - stat: + ansible.builtin.stat: path: "/var/lib/vz/images/{{ vm_id }}/vm-{{ vm_id }}-disk-0.qcow2" register: disk_exists changed_when: false - name: "[CONFIG] Import qcow2 disk" - command: > + ansible.builtin.command: > qm importdisk {{ vm_id }} {{ debian_image_path }} {{ storage }} @@ -38,14 +38,14 @@ when: not disk_exists.stat.exists - name: "[CONFIG] Verify disk import" - fail: + ansible.builtin.fail: msg: "Disk import failed for VM {{ vm_id }}" when: - not disk_exists.stat.exists - disk_import is failed - name: "[CONFIG] Attach imported disk" - command: > + ansible.builtin.command: > qm set {{ vm_id }} --scsihw virtio-scsi-pci --scsi0 {{ storage }}:vm-{{ vm_id }}-disk-0 @@ -54,7 +54,7 @@ changed_when: disk_attach.rc == 0 - name: "[CONFIG] Enable serial console and set boot order" - command: > + ansible.builtin.command: > qm set {{ vm_id }} --serial0 socket --boot order=scsi0 @@ -62,12 +62,12 @@ changed_when: serial_config.rc == 0 - name: "[CONFIG] Display disk configuration" - debug: + ansible.builtin.debug: msg: "✓ Disk configured and attached to VM {{ vm_id }}" rescue: - name: "[CONFIG] Handle disk configuration error" - fail: + ansible.builtin.fail: msg: | Failed to configure disk for VM {{ vm_id }}: {{ ansible_failed_result | default('Unknown error') }} @@ -75,12 +75,12 @@ - name: "[CONFIG] Resize disk (if enabled)" block: - name: "[CONFIG] Resize disk" - command: "qm resize {{ vm_id }} scsi0 {{ resize_size }}" + ansible.builtin.command: "qm resize {{ vm_id }} scsi0 {{ resize_size }}" register: disk_resize changed_when: disk_resize.rc == 0 - name: "[CONFIG] Display disk resize result" - debug: + ansible.builtin.debug: msg: "✓ Disk resized to {{ resize_size }}" when: resize_disk | default(false) @@ -88,12 +88,12 @@ - name: "[CONFIG] Configure GPU passthrough (if enabled)" block: - name: "[CONFIG] Enable PCI GPU passthrough" - command: "qm set {{ vm_id }} --hostpci0 {{ gpu_device }}" + ansible.builtin.command: "qm set {{ vm_id }} --hostpci0 {{ gpu_device }}" register: gpu_config changed_when: gpu_config.rc == 0 - name: "[CONFIG] Display GPU configuration" - debug: + ansible.builtin.debug: msg: "✓ GPU passthrough configured: {{ gpu_device }}" when: gpu_passthrough | default(false) @@ -101,12 +101,12 @@ - name: "[CONFIG] Configure VirtIO GPU (if enabled)" block: - name: "[CONFIG] Enable VirtIO GPU" - command: "qm set {{ vm_id }} --vga virtio" + ansible.builtin.command: "qm set {{ vm_id }} --vga virtio" register: virtio_gpu_config changed_when: virtio_gpu_config.rc == 0 - name: "[CONFIG] Display VirtIO GPU configuration" - debug: + ansible.builtin.debug: msg: "✓ VirtIO GPU configured" when: virtio_gpu | default(false) @@ -114,34 +114,34 @@ - name: "[CONFIG] Create and apply Cloud-Init snippets" block: - name: "[CONFIG] Create Cloud-Init vendor-data snippet" - template: + ansible.builtin.template: src: cloudinit_vendor.yaml.j2 dest: "/var/lib/vz/snippets/{{ vm_id }}-vendor.yaml" mode: "0644" register: vendor_snippet - name: "[CONFIG] Create Cloud-Init user-data snippet" - template: + ansible.builtin.template: src: cloudinit_userdata.yaml.j2 dest: "/var/lib/vz/snippets/{{ vm_id }}-user.yaml" mode: "0644" register: user_snippet - name: "[CONFIG] Verify SSH key is readable" - stat: + ansible.builtin.stat: path: "{{ ssh_key_path | expanduser }}" register: ssh_key_stat failed_when: not ssh_key_stat.stat.readable - name: "[CONFIG] Copy SSH public key to snippets" - copy: + ansible.builtin.copy: src: "{{ ssh_key_path | expanduser }}" dest: "/var/lib/vz/snippets/{{ vm_id }}-sshkey.pub" mode: "0644" register: ssh_snippet - name: "[CONFIG] Apply Cloud-Init configuration" - command: > + ansible.builtin.command: > qm set {{ vm_id }} --ciuser {{ ci_user }} --sshkeys local:snippets/{{ vm_id }}-sshkey.pub @@ -154,7 +154,7 @@ - name: "[CONFIG] Display Cloud-Init configuration" debug: - msg: | + ansible.builtin.msg: | ✓ Cloud-Init configured - User: {{ ci_user }} - Hostname: {{ hostname }} @@ -163,7 +163,7 @@ rescue: - name: "[CONFIG] Handle Cloud-Init configuration error" - fail: + ansible.builtin.fail: msg: | Failed to configure Cloud-Init for VM {{ vm_id }}: {{ ansible_failed_result | default('Unknown error') }} diff --git a/tasks/create-clones.yml b/tasks/create-clones.yml index bb2c4ba..8c67706 100644 --- a/tasks/create-clones.yml +++ b/tasks/create-clones.yml @@ -2,7 +2,7 @@ # create-clones.yml - Create and configure clones from template with error handling - name: "[CLONES] Validate clone list is not empty" - fail: + ansible.builtin.fail: msg: "No clones defined in 'clones' variable" when: - create_clones | default(false) @@ -11,19 +11,19 @@ - name: "[CLONES] Process each clone" block: - name: "[CLONES] Check if clone already exists" - stat: + ansible.builtin.stat: path: "/etc/pve/qemu-server/{{ clone.id }}.conf" register: clone_conf changed_when: false - name: "[CLONES] Display clone status" - debug: + ansible.builtin.debug: msg: "Clone {{ clone.id }} ({{ clone.hostname }}) - Status: {{ 'EXISTS' if clone_conf.stat.exists else 'WILL BE CREATED' }}" - name: "[CLONES] Clone VM from template" block: - name: "[CLONES] Execute clone command" - command: > + ansible.builtin.command: > qm clone {{ vm_id }} {{ clone.id }} --name {{ clone.hostname }} --full {{ clone.full | default(0) }} @@ -31,20 +31,20 @@ when: not clone_conf.stat.exists - name: "[CLONES] Verify clone was created" - stat: + ansible.builtin.stat: path: "/etc/pve/qemu-server/{{ clone.id }}.conf" register: clone_verify changed_when: false failed_when: not clone_verify.stat.exists - name: "[CLONES] Wait for clone to be ready" - pause: + ansible.builtin.pause: seconds: 2 when: not clone_conf.stat.exists rescue: - name: "[CLONES] Handle clone creation error" - fail: + ansible.builtin.fail: msg: | Failed to clone VM {{ vm_id }} to {{ clone.id }}: {{ ansible_failed_result | default('Unknown error') }} @@ -52,7 +52,7 @@ - name: "[CLONES] Configure Cloud-Init for clone (if needed)" block: - name: "[CLONES] Set clone hostname and IP" - command: > + ansible.builtin.command: > qm set {{ clone.id }} --hostname {{ clone.hostname }} --ipconfig0 "ip={{ clone.ip }},gw={{ clone.gateway }}" @@ -60,18 +60,18 @@ when: not clone_conf.stat.exists - name: "[CLONES] Apply SSH keys to clone" - command: > + ansible.builtin.command: > qm set {{ clone.id }} --sshkeys local:snippets/{{ vm_id }}-sshkey.pub when: not clone_conf.stat.exists rescue: - name: "[CLONES] Handle clone configuration error" - debug: + ansible.builtin.debug: msg: "WARNING: Could not fully configure clone {{ clone.id }}. You may need to configure manually." - name: "[CLONES] Start clone VM" - command: "qm start {{ clone.id }}" + ansible.builtin.command: "qm start {{ clone.id }}" register: clone_start retries: 3 delay: 2 @@ -79,11 +79,11 @@ when: not clone_conf.stat.exists - name: "[CLONES] Wait for clone to boot" - pause: + ansible.builtin.pause: seconds: 3 - name: "[CLONES] Display clone creation result" - debug: + ansible.builtin.debug: msg: | ✓ Clone created and started - ID: {{ clone.id }} @@ -97,6 +97,6 @@ when: create_clones | default(false) - name: "[CLONES] Skip clone creation (disabled)" - debug: + ansible.builtin.debug: msg: "ℹ Clone creation is disabled. Set 'create_clones: true' to enable." when: not (create_clones | default(false)) diff --git a/tasks/create-template.yml b/tasks/create-template.yml index b76c7ad..97eea04 100644 --- a/tasks/create-template.yml +++ b/tasks/create-template.yml @@ -2,66 +2,66 @@ # create-template.yml - Convert VM to template with proper idempotency - name: "[TEMPLATE] Check if VM is already a template" - shell: "qm config {{ vm_id }} | grep -q 'template: 1'" + ansible.builtin.shell: "qm config {{ vm_id }} | grep -q 'template: 1'" register: is_template changed_when: false failed_when: false - name: "[TEMPLATE] Display template status" - debug: + ansible.builtin.debug: msg: "Template status for VM {{ vm_id }}: {{ 'ALREADY A TEMPLATE' if is_template.rc == 0 else 'NOT YET A TEMPLATE' }}" - name: "[TEMPLATE] Verify VM is stopped before converting" block: - name: "[TEMPLATE] Check VM status" - shell: "qm status {{ vm_id }} | grep -q 'stopped'" + ansible.builtin.shell: "qm status {{ vm_id }} | grep -q 'stopped'" register: vm_stopped changed_when: false failed_when: false - name: "[TEMPLATE] Stop VM if running" - command: "qm stop {{ vm_id }}" + ansible.builtin.command: "qm stop {{ vm_id }}" when: vm_stopped.rc != 0 register: vm_stop - name: "[TEMPLATE] Wait for VM to stop" - pause: + ansible.builtin.pause: seconds: 2 when: vm_stopped.rc != 0 rescue: - name: "[TEMPLATE] Handle VM stop error" - debug: + ansible.builtin.debug: msg: "WARNING: Could not verify/stop VM {{ vm_id }}. Continuing..." - name: "[TEMPLATE] Convert VM to template" block: - name: "[TEMPLATE] Convert to template" - command: "qm template {{ vm_id }}" + ansible.builtin.command: "qm template {{ vm_id }}" register: template_convert when: is_template.rc != 0 changed_when: template_convert.rc == 0 - name: "[TEMPLATE] Verify conversion" - shell: "qm config {{ vm_id }} | grep 'template: 1'" + ansible.builtin.shell: "qm config {{ vm_id }} | grep 'template: 1'" register: template_verify changed_when: false failed_when: template_verify.rc != 0 - name: "[TEMPLATE] Display template conversion result" - debug: + ansible.builtin.debug: msg: | ✓ VM {{ vm_id }} ({{ hostname }}) successfully converted to template Template can now be cloned rescue: - name: "[TEMPLATE] Handle template conversion error" - fail: + ansible.builtin.fail: msg: | Failed to convert VM {{ vm_id }} to template: {{ ansible_failed_result | default('Unknown error') }} - name: "[TEMPLATE] Skip template conversion (already done)" - debug: + ansible.builtin.debug: msg: "ℹ VM {{ vm_id }} is already a template, skipping conversion" when: is_template.rc == 0 diff --git a/tasks/create-vm.yml b/tasks/create-vm.yml index 49259ed..6e77d58 100644 --- a/tasks/create-vm.yml +++ b/tasks/create-vm.yml @@ -2,17 +2,17 @@ # create-vm.yml - Create base VM on Proxmox - name: "[VM] Check if VM already exists" - stat: + ansible.builtin.stat: path: "/etc/pve/qemu-server/{{ vm_id }}.conf" register: vm_conf changed_when: false - name: "[VM] Display VM status" - debug: + ansible.builtin.debug: msg: "VM {{ vm_id }} ({{ hostname }}) - Status: {{ 'ALREADY EXISTS' if vm_conf.stat.exists else 'WILL BE CREATED' }}" - name: "[VM] Create base VM" - command: > + ansible.builtin.command: > qm create {{ vm_id }} --name {{ hostname }} --memory {{ memory }} @@ -25,7 +25,7 @@ changed_when: vm_create.rc == 0 - name: "[VM] Handle VM creation error" - fail: + ansible.builtin.fail: msg: | Failed to create VM {{ vm_id }}: {{ vm_create.stderr | default('No error message') }} @@ -34,13 +34,13 @@ - vm_create is failed - name: "[VM] Verify VM was created" - stat: + ansible.builtin.stat: path: "/etc/pve/qemu-server/{{ vm_id }}.conf" register: vm_conf_verify changed_when: false failed_when: not vm_conf_verify.stat.exists - name: "[VM] Display VM creation result" - debug: + ansible.builtin.debug: msg: "✓ VM {{ vm_id }} created successfully" when: not vm_conf.stat.exists diff --git a/tasks/download-image.yml b/tasks/download-image.yml index c56e0e9..ee4e605 100644 --- a/tasks/download-image.yml +++ b/tasks/download-image.yml @@ -2,20 +2,20 @@ # download-image.yml - Download and cache Debian GenericCloud image - name: "[IMAGE] Check for Debian GenericCloud image" - stat: + ansible.builtin.stat: path: "{{ debian_image_path }}" register: debian_img changed_when: false - name: "[IMAGE] Create template directory if missing" - file: + ansible.builtin.file: path: "/var/lib/vz/template/qemu" state: directory mode: "0755" when: not debian_img.stat.exists - name: "[IMAGE] Download Debian GenericCloud qcow2" - get_url: + ansible.builtin.get_url: url: "{{ debian_image_url }}" dest: "{{ debian_image_path }}" mode: "0644" @@ -27,14 +27,14 @@ when: not debian_img.stat.exists - name: "[IMAGE] Verify downloaded image integrity" - stat: + ansible.builtin.stat: path: "{{ debian_image_path }}" register: debian_img_final changed_when: false failed_when: not debian_img_final.stat.exists or debian_img_final.stat.size == 0 - name: "[IMAGE] Display image info" - debug: + ansible.builtin.debug: msg: | Image cached at: {{ debian_image_path }} Size: {{ debian_img_final.stat.size | int / 1024 / 1024 / 1024 | round(2) }} GB diff --git a/tasks/helpers.yml b/tasks/helpers.yml index 916dadd..c705322 100644 --- a/tasks/helpers.yml +++ b/tasks/helpers.yml @@ -14,13 +14,13 @@ - name: "[HELPER] Check VM exists" block: - name: "[HELPER] Stat VM config file" - stat: + ansible.builtin.stat: path: "/etc/pve/qemu-server/{{ target_vm_id }}.conf" register: vm_config changed_when: false - name: "[HELPER] Set fact: vm_exists" - set_fact: + ansible.builtin.set_fact: vm_exists: "{{ vm_config.stat.exists }}" when: helper_task == "check_vm_exists" @@ -31,13 +31,13 @@ - name: "[HELPER] Check if VM is template" block: - name: "[HELPER] Query VM template status" - shell: "qm config {{ target_vm_id }} | grep -q '^template: 1$'" + ansible.builtin.shell: "qm config {{ target_vm_id }} | grep -q '^template: 1$'" changed_when: false failed_when: false register: template_check - name: "[HELPER] Set fact: is_template" - set_fact: + ansible.builtin.set_fact: is_template: "{{ template_check.rc == 0 }}" when: helper_task == "check_template" @@ -48,12 +48,12 @@ - name: "[HELPER] Check VM running status" block: - name: "[HELPER] Query VM status" - shell: "qm status {{ target_vm_id }} | grep -oP 'status: \\K\\w+'" + ansible.builtin.shell: "qm status {{ target_vm_id }} | grep -oP 'status: \\K\\w+'" changed_when: false register: vm_status_cmd - name: "[HELPER] Set fact: vm_status" - set_fact: + ansible.builtin.set_fact: vm_status: "{{ vm_status_cmd.stdout | default('unknown') }}" when: helper_task == "check_vm_status" @@ -64,12 +64,12 @@ - name: "[HELPER] Check storage space" block: - name: "[HELPER] Query storage status" - command: "pvesm status {{ storage_name }}" + ansible.builtin.command: "pvesm status {{ storage_name }}" changed_when: false register: storage_status - name: "[HELPER] Extract available space" - set_fact: + ansible.builtin.set_fact: storage_available: "{{ storage_status.stdout_lines[1].split()[1] | int }}" when: helper_task == "check_storage" @@ -80,20 +80,20 @@ - name: "[HELPER] Validate VM ID" block: - name: "[HELPER] Check VM ID format" - assert: + ansible.builtin.assert: that: - target_vm_id | int >= 100 - target_vm_id | int <= 999999 fail_msg: "Invalid VM ID {{ target_vm_id }}. Must be between 100 and 999999" - name: "[HELPER] Check if ID already in use" - stat: + ansible.builtin.stat: path: "/etc/pve/qemu-server/{{ target_vm_id }}.conf" register: id_check changed_when: false - name: "[HELPER] Warn if ID exists" - debug: + ansible.builtin.debug: msg: "WARNING: VM ID {{ target_vm_id }} already exists" when: id_check.stat.exists @@ -105,13 +105,13 @@ - name: "[HELPER] Get VM information" block: - name: "[HELPER] Read VM config" - slurp: + ansible.builtin.slurp: src: "/etc/pve/qemu-server/{{ target_vm_id }}.conf" register: vm_config_file changed_when: false - name: "[HELPER] Parse VM config" - set_fact: + ansible.builtin.set_fact: vm_info: "{{ vm_config_file.content | b64decode }}" when: helper_task == "get_vm_info" @@ -122,12 +122,12 @@ - name: "[HELPER] List all VMs" block: - name: "[HELPER] Get VM list" - command: "qm list" + ansible.builtin.command: "qm list" changed_when: false register: vm_list_output - name: "[HELPER] Parse VM list" - set_fact: + ansible.builtin.set_fact: vm_list: "{{ vm_list_output.stdout_lines[1:] }}" when: helper_task == "list_vms" @@ -138,7 +138,7 @@ - name: "[HELPER] Cleanup Cloud-Init snippets" block: - name: "[HELPER] Remove old snippets for VM" - file: + ansible.builtin.file: path: "{{ item }}" state: absent loop: diff --git a/tasks/main.yml b/tasks/main.yml index db82cfe..1dc6868 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,7 +8,7 @@ # 5. Clone creation & deployment - name: "Create Debian VM template and deploy clones on Proxmox" - debug: + ansible.builtin.debug: msg: | ╔════════════════════════════════════════════════════════════╗ ║ Proxmox VM Template & Clone Manager ║ @@ -21,7 +21,7 @@ # 1. PREFLIGHT CHECKS ################################################################## - name: "STAGE 1: Run pre-flight environment checks" - include_tasks: preflight-checks.yml + ansible.builtin.include_tasks: preflight-checks.yml tags: [preflight, always] run_once: true @@ -29,28 +29,28 @@ # 2. DOWNLOAD IMAGE ################################################################## - name: "STAGE 2: Download and cache Debian GenericCloud image" - include_tasks: download-image.yml + ansible.builtin.include_tasks: download-image.yml tags: [image, always] ################################################################## # 3. CREATE VM ################################################################## - name: "STAGE 3: Create base VM" - include_tasks: create-vm.yml + ansible.builtin.include_tasks: create-vm.yml tags: [vm, create] ################################################################## # 4. CONFIGURE VM (Disk, Cloud-Init, GPU, TPM, etc.) ################################################################## - name: "STAGE 4: Configure VM (disk, Cloud-Init, optional features)" - include_tasks: configure-vm.yml + ansible.builtin.include_tasks: configure-vm.yml tags: [vm, configure, cloudinit] ################################################################## # 5. CREATE TEMPLATE ################################################################## - name: "STAGE 5: Convert VM to template" - include_tasks: create-template.yml + ansible.builtin.include_tasks: create-template.yml tags: [template, create] when: make_template | default(false) @@ -58,12 +58,12 @@ # 6. CREATE CLONES ################################################################## - name: "STAGE 6: Create and configure clones" - include_tasks: create-clones.yml + ansible.builtin.include_tasks: create-clones.yml tags: [clones, create] when: create_clones | default(false) - name: "Display completion summary" - debug: + ansible.builtin.debug: msg: | ╔════════════════════════════════════════════════════════════╗ ║ ✓ Playbook execution completed ║ @@ -81,7 +81,7 @@ # rescue: # - name: "Handle playbook errors" -# debug: +# ansible.builtin.debug: # msg: | # ✗ Playbook execution failed # Check the error messages above for details. diff --git a/tasks/preflight-checks.yml b/tasks/preflight-checks.yml index a8a03ca..58f3d0a 100644 --- a/tasks/preflight-checks.yml +++ b/tasks/preflight-checks.yml @@ -2,63 +2,63 @@ # preflight-checks.yml - Validate environment before running main tasks - name: "[PREFLIGHT] Check if running on Proxmox host" - stat: + ansible.builtin.stat: path: "/etc/pve/nodes" register: pve_nodes failed_when: not pve_nodes.stat.exists changed_when: false - name: "[PREFLIGHT] Verify qm command is available" - command: which qm + ansible.builtin.command: which qm changed_when: false failed_when: false register: qm_check - name: "[PREFLIGHT] Fail if qm not found" - fail: + ansible.builtin.fail: msg: "qm command not found. This role requires Proxmox VE to be installed." when: qm_check.rc != 0 - name: "[PREFLIGHT] Check if user can run qm commands" - command: qm version + ansible.builtin.command: qm version changed_when: false register: qm_version - name: "[PREFLIGHT] Display Proxmox version" - debug: + ansible.builtin.debug: msg: "Proxmox Version: {{ qm_version.stdout }}" - name: "[PREFLIGHT] Verify storage pool exists" - command: "pvesm status {{ storage }}" + ansible.builtin.command: "pvesm status {{ storage }}" changed_when: false failed_when: false register: storage_check - name: "[PREFLIGHT] Fail if storage not found" - fail: + ansible.builtin.fail: msg: "Storage pool '{{ storage }}' not found. Available pools: run 'pvesm status'" when: storage_check.rc != 0 - name: "[PREFLIGHT] Check SSH key file exists" - stat: + ansible.builtin.stat: path: "{{ ssh_key_path | expanduser }}" register: ssh_key_file failed_when: not ssh_key_file.stat.exists changed_when: false - name: "[PREFLIGHT] Validate VM ID is unique" - command: "test ! -f /etc/pve/qemu-server/{{ vm_id }}.conf" + ansible.builtin.command: "test ! -f /etc/pve/qemu-server/{{ vm_id }}.conf" changed_when: false failed_when: false register: vm_id_check - name: "[PREFLIGHT] Warn if VM ID already exists" - debug: + ansible.builtin.debug: msg: "WARNING: VM ID {{ vm_id }} already exists. It will be skipped or updated." when: vm_id_check.rc != 0 - name: "[PREFLIGHT] Validate clone IDs are unique" - command: "test ! -f /etc/pve/qemu-server/{{ item.id }}.conf" + ansible.builtin.command: "test ! -f /etc/pve/qemu-server/{{ item.id }}.conf" changed_when: false failed_when: false loop: "{{ clones }}" @@ -66,13 +66,13 @@ when: create_clones | default(false) - name: "[PREFLIGHT] Warn if any clone IDs already exist" - debug: + ansible.builtin.debug: msg: "WARNING: Clone ID {{ item.item.id }} already exists and will be skipped." loop: "{{ clone_id_checks.results }}" when: item.rc != 0 and create_clones | default(false) - name: "[PREFLIGHT] Validate IP address format for clones" - assert: + ansible.builtin.assert: that: - "item.ip | ipaddr" fail_msg: "Invalid IP address for clone {{ item.id }}: {{ item.ip }}" @@ -80,20 +80,20 @@ when: create_clones | default(false) - name: "[PREFLIGHT] Validate static IP address format (if not DHCP)" - assert: + ansible.builtin.assert: that: - "ip_address | ipaddr" fail_msg: "Invalid static IP address: {{ ip_address }}" when: ip_mode == 'static' - name: "[PREFLIGHT] Validate gateway IP address" - assert: + ansible.builtin.assert: that: - "gateway | ipaddr" fail_msg: "Invalid gateway IP address: {{ gateway }}" - name: "[PREFLIGHT] Validate DNS servers" - assert: + ansible.builtin.assert: that: - "item | ipaddr" fail_msg: "Invalid DNS server IP: {{ item }}" @@ -101,14 +101,14 @@ when: dns is defined and dns | length > 0 - name: "[PREFLIGHT] Check snippets storage exists" - stat: + ansible.builtin.stat: path: "/var/lib/vz/snippets" register: snippets_dir failed_when: not snippets_dir.stat.exists changed_when: false - name: "[PREFLIGHT] Summary - All checks passed" - debug: + ansible.builtin.debug: msg: | ✓ Proxmox environment validated ✓ Storage pool '{{ storage }}' available