edit-config.yml was never included by the role, so lxc_id_mappings and GPU passthrough were silently ignored. It also used blockinfile, whose comment markers are incompatible with Proxmox hoisting all comments to the top of the .conf on every write -- which orphans the markers and empties the managed block. Rewrite edit-config.yml to manage raw lxc.* lines with lineinfile (keyed on each exact line, churn-free, immune to comment hoisting), delegated to the Proxmox host. Include it from main.yml after clone/create but before start.yml, while the container is stopped, since ID mappings can't change on a running container.
61 lines
1.8 KiB
YAML
Executable File
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 | default(lxc_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
|