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