d5cf6f656e
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.
52 lines
1.4 KiB
YAML
Executable File
52 lines
1.4 KiB
YAML
Executable File
---
|
|
- name: Check if container exists
|
|
ansible.builtin.include_tasks:
|
|
file: check-exists.yml
|
|
|
|
- name: Skip if container already exists
|
|
meta: end_host
|
|
when: lxc_exists | bool
|
|
|
|
- name: Container source must be defined (lxc_clone_from or lxc_template)
|
|
ansible.builtin.fail:
|
|
msg: "Neither lxc_clone_from or lxc_template are defined"
|
|
when: lxc_clone_from is undefined and lxc_template is undefined
|
|
|
|
- name: Clone container from another container or template, then update
|
|
when: lxc_clone_from is defined
|
|
block:
|
|
- name: Clone from template
|
|
ansible.builtin.include_tasks:
|
|
file: clone.yml
|
|
register: clone_result
|
|
|
|
- name: Update container
|
|
ansible.builtin.include_tasks:
|
|
file: update.yml
|
|
vars:
|
|
lxc_vmid: "{{ clone_result.vmid }}"
|
|
register: lxc_result
|
|
|
|
- name: Create the new container
|
|
ansible.builtin.include_tasks:
|
|
file: create.yml
|
|
when: lxc_template is defined and lxc_clone_from is undefined
|
|
|
|
- name: Start the created container and wait for ssh
|
|
vars:
|
|
lxc_vmid: "{{ lxc_result.vmid }}"
|
|
ansible.builtin.include_tasks:
|
|
file: "{{ item }}"
|
|
loop:
|
|
- start.yml
|
|
- wait.yml
|
|
when: lxc_start
|
|
|
|
- name: Post clone updates
|
|
when: lxc_clone_from is defined
|
|
delegate_to: "{{ lxc_hostname }}"
|
|
block:
|
|
- name: Include post-clone tasks
|
|
ansible.builtin.include_tasks:
|
|
file: post-clone.yml
|