Files
ansible-collection-infrastr…/roles/proxmox_lxc_provision/tasks/main.yml
T
patrick 7a617de315 fix(proxmox_lxc_provision): drop self-referential lxc_vmid default in edit-config include
lxc_vmid: {{ lxc_result.vmid | default(lxc_vmid) }} defined the var in terms of
itself, causing infinite templating recursion. Mirror start.yml and use
lxc_result.vmid directly, which is always registered by the clone or create path.
2026-07-27 18:02:17 -04:00

61 lines
1.8 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
# Must run while the container is stopped (before start.yml): ID mappings cannot be
# changed on a running container. Writes /etc/pve/lxc/<vmid>.conf on the Proxmox host.
- name: Apply raw LXC config (ID mappings, GPU passthrough)
ansible.builtin.include_tasks:
file: edit-config.yml
vars:
lxc_vmid: "{{ lxc_result.vmid }}"
when: lxc_id_mappings is defined or lxc_nvidia_gpu_mount
- 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