Use fqdn for ansible.builtin modules

This commit is contained in:
2025-11-15 21:49:12 +01:00
parent ec2b3b7edc
commit ff691bae3d
8 changed files with 101 additions and 101 deletions

View File

@@ -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