Files
ansible-collection-infrastr…/roles/proxmox_lxc_provision/tasks/edit-config.yml
T
patrick 77723f8ef7 fix(proxmox_lxc_provision): wait for container config file before editing it
The proxmox create task can return before pmxcfs has flushed the .conf, so the
first delegated lineinfile hit 'Destination /etc/pve/lxc/<vmid>.conf does not
exist'. Poll for the file with wait_for (up to 30s) before applying idmaps/GPU
config, which continues as soon as it appears rather than eating a fixed sleep.
2026-07-27 19:06:22 -04:00

43 lines
1.7 KiB
YAML
Executable File

---
# Proxmox's container config parser hoists all comment lines to the top of the
# .conf on every write (pct set, container start/stop, API calls), which orphans
# blockinfile's # BEGIN/# END markers and breaks idempotency. Manage the raw lxc.*
# lines directly with lineinfile instead -- these are real config keys that Proxmox
# preserves in place. Each line is keyed on its own exact content, so no comment
# markers are needed and re-runs stay churn-free.
- name: Wait for the container config file to exist
ansible.builtin.wait_for:
path: "/etc/pve/lxc/{{ lxc_vmid }}.conf"
timeout: 30
delegate_to: "{{ proxmox_delegate_host }}"
become: true
- name: Configure ID mappings
ansible.builtin.lineinfile:
path: "/etc/pve/lxc/{{ lxc_vmid }}.conf"
line: "{{ item }}"
regexp: "^{{ item | regex_escape }}$"
insertafter: EOF
loop: "{{ lxc_id_mappings.splitlines() | select | list }}"
delegate_to: "{{ proxmox_delegate_host }}"
become: true
when: lxc_id_mappings is defined
- name: Configure NVIDIA GPU passthrough
ansible.builtin.lineinfile:
path: "/etc/pve/lxc/{{ lxc_vmid }}.conf"
line: "{{ item }}"
regexp: "^{{ item | regex_escape }}$"
insertafter: EOF
loop:
- "lxc.cgroup2.devices.allow: c {{ gpu_device_id }}:* rwm"
- "lxc.cgroup2.devices.allow: c {{ uvm_device_id }}:* rwm"
- "lxc.mount.entry: /dev/nvidia0 dev/nvidia0 none bind,optional,create=file"
- "lxc.mount.entry: /dev/nvidiactl dev/nvidiactl none bind,optional,create=file"
- "lxc.mount.entry: /dev/nvidia-uvm dev/nvidia-uvm none bind,optional,create=file"
- "lxc.mount.entry: /dev/nvidia-uvm-tools dev/nvidia-uvm-tools none bind,optional,create=file"
delegate_to: "{{ proxmox_delegate_host }}"
become: true
when: lxc_nvidia_gpu_mount