1e3ab88304
The previous commit (d5cf6f6) used 'module_defaults: "{{ _proxmox_module_defaults }}"'
to template the entire defaults dict. Ansible rejects this because
module_defaults keys must be static action/module/group names at parse
time — only values may be templated.
Expose _proxmox_api_args as a flat dict of API parameters in
defaults/main.yml, and in each task file's module_defaults block use
the literal community.proxmox.proxmox and community.proxmox.proxmox_vm_info
keys with templated values pointing at the var.
20 lines
700 B
YAML
Executable File
20 lines
700 B
YAML
Executable File
---
|
|
- name: Check if LXC exists
|
|
module_defaults:
|
|
community.proxmox.proxmox: "{{ _proxmox_api_args }}"
|
|
community.proxmox.proxmox_vm_info: "{{ _proxmox_api_args }}"
|
|
block:
|
|
- name: Query Proxmox for existing LXCs
|
|
community.proxmox.proxmox_vm_info:
|
|
type: lxc
|
|
register: proxmox_lxcs
|
|
|
|
- name: Check if LXC already exists
|
|
ansible.builtin.set_fact:
|
|
lxc_exists: >-
|
|
{{
|
|
(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))
|
|
}}
|