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