- Added default configuration for VM creation in defaults/main.yml. - Created tasks for configuring the VM with UEFI, TPM, disks, GPU, and Cloud-Init in tasks/configure-vm.yml. - Implemented clone creation and configuration logic in tasks/create-clones.yml. - Added template conversion functionality in tasks/create-template.yml. - Developed base VM creation logic in tasks/create-vm.yml. - Included image download and caching tasks in tasks/download-image.yml. - Introduced utility tasks for common operations in tasks/helpers.yml. - Organized main orchestration logic in tasks/main.yml, with clear stages for each operation. - Added pre-flight checks to validate the environment before execution in tasks/preflight-checks.yml.
118 lines
3.4 KiB
YAML
118 lines
3.4 KiB
YAML
---
|
|
# preflight-checks.yml - Validate environment before running main tasks
|
|
|
|
- name: "[PREFLIGHT] Check if running on Proxmox host"
|
|
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
|
|
changed_when: false
|
|
failed_when: false
|
|
register: qm_check
|
|
|
|
- name: "[PREFLIGHT] Fail if qm not found"
|
|
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
|
|
changed_when: false
|
|
register: qm_version
|
|
|
|
- name: "[PREFLIGHT] Display Proxmox version"
|
|
debug:
|
|
msg: "Proxmox Version: {{ qm_version.stdout }}"
|
|
|
|
- name: "[PREFLIGHT] Verify storage pool exists"
|
|
command: "pvesm status {{ storage }}"
|
|
changed_when: false
|
|
failed_when: false
|
|
register: storage_check
|
|
|
|
- name: "[PREFLIGHT] Fail if storage not found"
|
|
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:
|
|
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"
|
|
changed_when: false
|
|
failed_when: false
|
|
register: vm_id_check
|
|
|
|
- name: "[PREFLIGHT] Warn if VM ID already exists"
|
|
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"
|
|
changed_when: false
|
|
failed_when: false
|
|
loop: "{{ clones }}"
|
|
register: clone_id_checks
|
|
when: create_clones | default(false)
|
|
|
|
- name: "[PREFLIGHT] Warn if any clone IDs already exist"
|
|
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:
|
|
that:
|
|
- "item.ip | ipaddr"
|
|
fail_msg: "Invalid IP address for clone {{ item.id }}: {{ item.ip }}"
|
|
loop: "{{ clones }}"
|
|
when: create_clones | default(false)
|
|
|
|
- name: "[PREFLIGHT] Validate static IP address format (if not DHCP)"
|
|
assert:
|
|
that:
|
|
- "ip_address | ipaddr"
|
|
fail_msg: "Invalid static IP address: {{ ip_address }}"
|
|
when: ip_mode == 'static'
|
|
|
|
- name: "[PREFLIGHT] Validate gateway IP address"
|
|
assert:
|
|
that:
|
|
- "gateway | ipaddr"
|
|
fail_msg: "Invalid gateway IP address: {{ gateway }}"
|
|
|
|
- name: "[PREFLIGHT] Validate DNS servers"
|
|
assert:
|
|
that:
|
|
- "item | ipaddr"
|
|
fail_msg: "Invalid DNS server IP: {{ item }}"
|
|
loop: "{{ dns }}"
|
|
when: dns is defined and dns | length > 0
|
|
|
|
- name: "[PREFLIGHT] Check snippets storage exists"
|
|
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:
|
|
msg: |
|
|
✓ Proxmox environment validated
|
|
✓ Storage pool '{{ storage }}' available
|
|
✓ SSH key found at {{ ssh_key_path }}
|
|
✓ VM ID {{ vm_id }} is available
|
|
✓ Ready to create VM: {{ hostname }}
|