refactor: Update check-exists.yml to check by vmid or hostname
This commit is contained in:
@@ -4,12 +4,11 @@
|
|||||||
type: lxc
|
type: lxc
|
||||||
register: proxmox_lxcs
|
register: proxmox_lxcs
|
||||||
|
|
||||||
- name: Check if LXC with hostname already exists
|
- name: Check if LXC already exists
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
lxc_exists: >-
|
lxc_exists: >-
|
||||||
{{
|
{{
|
||||||
proxmox_lxcs.proxmox_vms
|
(lxc_vmid is defined and lxc_vmid | int in (proxmox_lxcs.proxmox_vms | map(attribute='vmid') | list))
|
||||||
| selectattr('name', 'equalto', lxc_hostname)
|
or
|
||||||
| list
|
(lxc_hostname is defined and (proxmox_lxcs.proxmox_vms | selectattr('name', 'equalto', lxc_hostname) | list | length > 0))
|
||||||
| length > 0
|
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -12,15 +12,12 @@
|
|||||||
community.proxmox.proxmox_vm_info: *proxmox_defaults
|
community.proxmox.proxmox_vm_info: *proxmox_defaults
|
||||||
block:
|
block:
|
||||||
- name: Check if container exists
|
- name: Check if container exists
|
||||||
community.proxmox.proxmox:
|
ansible.builtin.include_tasks:
|
||||||
vmid: "{{ lxc_vmid }}"
|
file: check-exists.yml
|
||||||
state: current
|
|
||||||
register: existing_container
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Skip if container already exists
|
- name: Skip if container already exists
|
||||||
meta: end_host
|
meta: end_host
|
||||||
when: existing_container is succeeded
|
when: lxc_exists | bool
|
||||||
|
|
||||||
- name: Container source must be defined (lxc_clone_from or lxc_template)
|
- name: Container source must be defined (lxc_clone_from or lxc_template)
|
||||||
ansible.builtin.fail:
|
ansible.builtin.fail:
|
||||||
|
|||||||
Reference in New Issue
Block a user