refactor(proxmox_lxc_provision): centralize module_defaults so tasks_from works without setup
Previously the community.proxmox.proxmox / proxmox_vm_info module_defaults were defined inline on the outer block in main.yml. Invoking individual task files via 'tasks_from: stop' (or delete/convert/etc.) bypassed main.yml, leaving the API parameters unset and producing 'missing required arguments: api_host, api_user' errors. The README worked around this by telling callers to repeat the module_defaults block at the play level — easy to forget, and duplicated config. Extract the defaults dict into _proxmox_module_defaults in defaults/main.yml (using a YAML anchor to share between the two modules), and wrap every task file that calls a Proxmox module in a block that references it. Callers only need the proxmox_* connection vars in scope (typically group_vars/all/) — both 'roles:' and 'tasks_from:' invocations now configure the API consistently. Files wrapped: check-exists, create, clone, update, start, stop, delete, convert. wait/post-clone/edit-config don't call Proxmox modules and are unchanged. main.yml's now-redundant outer module_defaults is removed. README updated to drop the 'Using Standalone Tasks' workaround boilerplate.
This commit is contained in:
@@ -1,24 +1,27 @@
|
||||
---
|
||||
- name: Create an LXC container
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ lxc_vmid | default(omit) }}"
|
||||
hostname: "{{ lxc_hostname }}"
|
||||
password: "{{ lxc_root_password | default(omit) }}"
|
||||
ostemplate: "{{ lxc_template }}"
|
||||
cores: "{{ lxc_cores }}"
|
||||
memory: "{{ lxc_memory }}"
|
||||
swap: "{{ lxc_swap }}"
|
||||
disk: "{{ lxc_disk }}"
|
||||
mounts: "{{ lxc_mounts | default(omit) }}"
|
||||
netif: >-
|
||||
{"net0": "name={{ lxc_iface_name }},bridge={{ lxc_bridge }},ip={{ lxc_ipv4 }},gw={{ lxc_gateway }},ip6={{ lxc_ipv6 }}{% if lxc_vlan_tag is defined %},tag={{ lxc_vlan_tag }}{% endif %}"}
|
||||
pubkey: "{{ lookup('file', lxc_pubkey_file) | default(omit) }}"
|
||||
onboot: "{{ lxc_onboot | default(false) }}"
|
||||
startup: "{{ lxc_startup | default(omit) }}"
|
||||
unprivileged: "{{ lxc_unprivileged | default(true) }}"
|
||||
features: "{{ lxc_features | default(omit) }}"
|
||||
timezone: "{{ lxc_timezone | default(omit) }}"
|
||||
nameserver: "{{ lxc_nameserver | default(omit) }}"
|
||||
state: present
|
||||
tags: "{{ lxc_tags | default(omit) }}"
|
||||
register: lxc_result
|
||||
- name: Create LXC container
|
||||
module_defaults: "{{ _proxmox_module_defaults }}"
|
||||
block:
|
||||
- name: Create an LXC container
|
||||
community.proxmox.proxmox:
|
||||
vmid: "{{ lxc_vmid | default(omit) }}"
|
||||
hostname: "{{ lxc_hostname }}"
|
||||
password: "{{ lxc_root_password | default(omit) }}"
|
||||
ostemplate: "{{ lxc_template }}"
|
||||
cores: "{{ lxc_cores }}"
|
||||
memory: "{{ lxc_memory }}"
|
||||
swap: "{{ lxc_swap }}"
|
||||
disk: "{{ lxc_disk }}"
|
||||
mounts: "{{ lxc_mounts | default(omit) }}"
|
||||
netif: >-
|
||||
{"net0": "name={{ lxc_iface_name }},bridge={{ lxc_bridge }},ip={{ lxc_ipv4 }},gw={{ lxc_gateway }},ip6={{ lxc_ipv6 }}{% if lxc_vlan_tag is defined %},tag={{ lxc_vlan_tag }}{% endif %}"}
|
||||
pubkey: "{{ lookup('file', lxc_pubkey_file) | default(omit) }}"
|
||||
onboot: "{{ lxc_onboot | default(false) }}"
|
||||
startup: "{{ lxc_startup | default(omit) }}"
|
||||
unprivileged: "{{ lxc_unprivileged | default(true) }}"
|
||||
features: "{{ lxc_features | default(omit) }}"
|
||||
timezone: "{{ lxc_timezone | default(omit) }}"
|
||||
nameserver: "{{ lxc_nameserver | default(omit) }}"
|
||||
state: present
|
||||
tags: "{{ lxc_tags | default(omit) }}"
|
||||
register: lxc_result
|
||||
|
||||
Reference in New Issue
Block a user