Add pve_lxc, which manages the lifecycle of a Proxmox VE LXC container through the Proxmox API (community.proxmox), reconciles the raw lxc.* lines of its config on the node and, opt-in, writes its guest firewall file. It keeps the pve_lxc_* interface and carries no legacy-name guard. The input asserts run from tasks/validate.yml before any change, and the API token secret has no default. The molecule scenario runs the validation and the node-side task files against a container standing in for the node; the API lifecycle is not exercised. Debian trixie is declared, untested. Refs #386 Assisted-by: Claude Code:claude-opus-5-5
38 lines
1.5 KiB
YAML
38 lines
1.5 KiB
YAML
---
|
|
- name: Get current LXC config
|
|
no_log: true # Authorization header carries the API token
|
|
delegate_to: localhost
|
|
ansible.builtin.uri:
|
|
url: "https://{{ pve_lxc_api_host }}:8006/api2/json/nodes/{{ pve_lxc_node }}/lxc/{{ pve_lxc_vmid }}/config"
|
|
method: GET
|
|
headers:
|
|
Authorization: "{{ __pve_lxc_api_auth_header }}"
|
|
register: __pve_lxc_config
|
|
when: pve_lxc_exists
|
|
|
|
- name: Extract rootfs string
|
|
ansible.builtin.set_fact:
|
|
__pve_lxc_rootfs_str: "{{ __pve_lxc_config.json.data.rootfs | default('') }}"
|
|
|
|
- name: Extract current disk number and unit properly
|
|
ansible.builtin.set_fact:
|
|
__pve_lxc_disk_parts: "{{ __pve_lxc_rootfs_str | regex_findall('size=(\\d+)([GM])') | first | default(['0', 'G']) | list }}"
|
|
|
|
- name: Extract current disk number
|
|
ansible.builtin.set_fact:
|
|
__pve_lxc_current_disk_number: "{{ __pve_lxc_disk_parts[0] | int }}"
|
|
__pve_lxc_current_disk_unit: "{{ __pve_lxc_disk_parts[1] }}"
|
|
|
|
- name: Convert current disk size to GB
|
|
ansible.builtin.set_fact:
|
|
__pve_lxc_current_disk: "{{ __pve_lxc_current_disk_number if __pve_lxc_current_disk_unit == 'G' else (__pve_lxc_current_disk_number / 1024) }}"
|
|
|
|
- name: Extract desired disk size (GB)
|
|
ansible.builtin.set_fact:
|
|
__pve_lxc_desired_disk_size: "{{ (pve_lxc_disk.split(':')[-1] | int) }}"
|
|
|
|
- name: Determine if disk resize is needed
|
|
ansible.builtin.set_fact:
|
|
__pve_lxc_resize_disk: "{{ __pve_lxc_desired_disk_size | int > __pve_lxc_current_disk | int }}"
|
|
when: pve_lxc_exists
|