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

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