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
228 lines
11 KiB
YAML
228 lines
11 KiB
YAML
---
|
|
argument_specs:
|
|
main:
|
|
short_description: Manage a Proxmox LXC container
|
|
description:
|
|
- >-
|
|
Detects the container through the Proxmox API, validates C(pve_lxc_raw_config), deletes the container when C(pve_lxc_state)
|
|
is absent and C(pve_lxc_allow_destroy) is true, otherwise creates it when missing, updates its configuration and disk,
|
|
reconciles the raw C(lxc.*) lines in C(/etc/pve/lxc/<vmid>.conf), applies the power state and waits for SSH when
|
|
the container is started.
|
|
- >-
|
|
When C(pve_lxc_manage_lifecycle) is false the role only sets C(pve_lxc_exists) and C(pve_lxc_present) to true and does nothing
|
|
else, so none of the Proxmox inputs below is read. This is how a container on a node Ansible does not manage is
|
|
handled.
|
|
- >-
|
|
API calls run on localhost and authenticate with C(pve_lxc_api_user) (bare user name, C(@<pve_lxc_api_realm>) is
|
|
appended), C(pve_lxc_api_token_id), C(pve_lxc_api_token_secret) and C(pve_lxc_api_host), applied through
|
|
C(module_defaults), and with the header C(PVEAPIToken=<user>@<realm>!<token_id>=<secret>) for the C(uri) calls,
|
|
which the role derives from them in C(vars/main.yml) (internal, not an input).
|
|
The user and the token secret have no usable default: they are asserted non-empty in the input validation,
|
|
only for a container with C(pve_lxc_manage_lifecycle) true. The caller sets them.
|
|
The raw config, disk filesystem resize and the C(pct) call are delegated to C(pve_lxc_node) with become.
|
|
C(community.proxmox) and, on the controller, the Python library C(proxmoxer) must be installed. TLS certificates
|
|
are not verified.
|
|
- >-
|
|
Also reads C(ansible_host) (container address and SSH wait), C(inventory_hostname) (container hostname) and
|
|
C(ansible_check_mode). The role sets the facts C(pve_lxc_exists) and C(pve_lxc_present) for later plays. C(pve_lxc_present) is
|
|
true only while the container exists and C(pve_lxc_state) is not absent.
|
|
options:
|
|
pve_lxc_state:
|
|
type: str
|
|
default: present
|
|
choices: [present, started, stopped, absent]
|
|
description:
|
|
- >-
|
|
C(present) keeps the container configured without touching its power state. C(started) and C(stopped) also
|
|
apply the power state, and C(started) additionally waits for SSH when C(pve_lxc_wait_for_ssh) is true. C(absent)
|
|
deletes the container, but only when C(pve_lxc_allow_destroy) is true.
|
|
pve_lxc_manage_lifecycle:
|
|
type: bool
|
|
default: true
|
|
description:
|
|
- >-
|
|
When false the container is treated as present and every lifecycle task is skipped. Set it for containers on
|
|
a node Ansible does not manage.
|
|
pve_lxc_allow_destroy:
|
|
type: bool
|
|
default: false
|
|
description:
|
|
- Safety switch required before C(pve_lxc_state=absent) deletes the container.
|
|
pve_lxc_wait_for_ssh:
|
|
type: bool
|
|
default: true
|
|
description:
|
|
- When true and C(pve_lxc_state) is started, wait for SSH on port 22 of C(ansible_host).
|
|
pve_lxc_manage_disk:
|
|
type: bool
|
|
default: false
|
|
description:
|
|
- >-
|
|
Allow the root disk to be grown to the size in C(pve_lxc_disk). Growing fails the play when Proxmox does not apply it,
|
|
and runs C(pct resize) on C(pve_lxc_node).
|
|
pve_lxc_pubkey:
|
|
type: str
|
|
default: ""
|
|
description:
|
|
- Public keys installed for root by the container creation and update, one per line.
|
|
pve_lxc_features:
|
|
type: list
|
|
elements: str
|
|
default: []
|
|
description:
|
|
- >-
|
|
Proxmox container features such as C(nesting=1) or C(keyctl=1). Omitted when empty. Proxmox applies a change
|
|
only on the next start, and lets an API user other than C(root@pam) change only some of them, such as
|
|
C(nesting).
|
|
pve_lxc_restart_on_config_change:
|
|
type: bool
|
|
default: false
|
|
description:
|
|
- Restart the container when the configuration update reports a change. Off by default so routine drift does not restart guests.
|
|
pve_lxc_cmode:
|
|
type: str
|
|
default: tty
|
|
description:
|
|
- Console mode sent on update. Sent explicitly because community.proxmox 2.0.0 otherwise forwarded a value Proxmox rejects.
|
|
pve_lxc_raw_config:
|
|
type: raw
|
|
default: []
|
|
description:
|
|
- >-
|
|
Raw C(lxc.*) lines for the container config, one per list item, each a single line starting with C(lxc.).
|
|
The role default is an empty list. Anything that is not a list of such strings fails the play, except an empty
|
|
or null value, which is treated as an empty list and removes every C(lxc.*) line that is present. The
|
|
validation also runs in check mode on a container that does not exist yet. A change restarts the container (outside
|
|
check mode, unless C(pve_lxc_state) is stopped), independent of C(pve_lxc_restart_on_config_change).
|
|
pve_lxc_onboot:
|
|
type: bool
|
|
default: true
|
|
description:
|
|
- >-
|
|
Start the container when the node boots, for a container whose C(pve_lxc_state) is C(started) or C(present).
|
|
A C(stopped) container always gets C(onboot=0), whatever this says, so a node reboot does not start it.
|
|
Sent on create and on update.
|
|
pve_lxc_reboot_if_required:
|
|
type: bool
|
|
default: true
|
|
description:
|
|
- Restart the container after its root filesystem was grown.
|
|
pve_lxc_node:
|
|
type: str
|
|
description:
|
|
- >-
|
|
Inventory name of the Proxmox host that runs the container. Must be a host in the inventory; its
|
|
C(ansible_host) is the default of C(pve_lxc_api_host). Not read when C(pve_lxc_manage_lifecycle) is false.
|
|
pve_lxc_vmid:
|
|
type: int
|
|
description:
|
|
- Container id on the Proxmox node. Not read when C(pve_lxc_manage_lifecycle) is false.
|
|
pve_lxc_ostemplate:
|
|
type: str
|
|
description:
|
|
- Template volume the container is created from, for example C(local:vztmpl/<template>.tar.zst). Only read on creation.
|
|
pve_lxc_disk:
|
|
type: raw
|
|
description:
|
|
- >-
|
|
Root disk as C(<storage>:<size in GB>), for example C(local-lvm:8). The number after the last colon is the
|
|
desired size in GB. Only read on creation, on update and for disk detection.
|
|
pve_lxc_memory:
|
|
type: raw
|
|
description:
|
|
- Memory in MB. Read on creation and on update.
|
|
pve_lxc_cores:
|
|
type: raw
|
|
description:
|
|
- CPU cores. Omitted when undefined.
|
|
pve_lxc_swap:
|
|
type: raw
|
|
description:
|
|
- Swap in MB. Omitted when undefined.
|
|
pve_lxc_nameserver:
|
|
type: str
|
|
description:
|
|
- Nameserver for the container. Omitted when undefined.
|
|
pve_lxc_net:
|
|
type: raw
|
|
description:
|
|
- >-
|
|
Mapping with C(bridge), C(gw) and C(tag). The role builds C(net0) from it as
|
|
C(name=<pve_lxc_net_interface>,bridge=<bridge>,ip=<ansible_host>/<pve_lxc_net_prefix>,gw=<gw>,tag=<tag>),
|
|
plus C(,firewall=1) when C(pve_lxc_firewall) is true.
|
|
pve_lxc_firewall:
|
|
type: bool
|
|
default: false
|
|
description:
|
|
- >-
|
|
Opt-in Proxmox guest firewall. When true, C(firewall=1) is appended to C(net0) and
|
|
C(/etc/pve/firewall/<vmid>.fw) is written on C(pve_lxc_node) before the container is created, with
|
|
C(enable), C(ipfilter) and C(macfilter) on, the two policies and C(pve_lxc_firewall_rules). When false
|
|
neither is touched, so C(net0) is unchanged; a file written earlier is left in place but inert, since
|
|
the NIC no longer has the firewall flag. The rules only filter while the datacenter firewall is enabled.
|
|
pve_lxc_firewall_policy_in:
|
|
type: str
|
|
default: DROP
|
|
choices: [ACCEPT, DROP, REJECT]
|
|
description:
|
|
- Policy for inbound traffic that no rule matches.
|
|
pve_lxc_firewall_policy_out:
|
|
type: str
|
|
default: DROP
|
|
choices: [ACCEPT, DROP, REJECT]
|
|
description:
|
|
- Policy for outbound traffic that no rule matches.
|
|
pve_lxc_firewall_rules:
|
|
type: list
|
|
elements: str
|
|
default: []
|
|
description:
|
|
- >-
|
|
Proxmox firewall rule lines, evaluated in order, first match wins, each a single line starting with
|
|
C(IN) or C(OUT) and C(ACCEPT), C(DROP) or C(REJECT), for example C(IN ACCEPT -source 192.0.2.5 -p tcp -dport 22).
|
|
Only the shape is checked; Proxmox skips a line it cannot parse.
|
|
pve_lxc_api_user:
|
|
type: str
|
|
default: ""
|
|
description:
|
|
- >-
|
|
Proxmox API user, the bare name without realm (C(@<pve_lxc_api_realm>) is appended). Required when
|
|
C(pve_lxc_manage_lifecycle) is true: the role asserts it is non-empty before any change.
|
|
pve_lxc_api_realm:
|
|
type: str
|
|
default: pam
|
|
description:
|
|
- Authentication realm of C(pve_lxc_api_user), appended as C(@<realm>) in C(module_defaults) and in the C(uri) header.
|
|
pve_lxc_api_token_id:
|
|
type: str
|
|
description:
|
|
- >-
|
|
API token id, without the user part. Role default C(<pve_lxc_api_user>-token), a Jinja expression in
|
|
C(defaults/main.yml), so it is not repeated here.
|
|
pve_lxc_api_token_secret:
|
|
type: str
|
|
no_log: true
|
|
description:
|
|
- >-
|
|
API token secret, normally vaulted. No default. Required when C(pve_lxc_manage_lifecycle) is true: the role
|
|
asserts it is set and non-empty before any change. Every task that carries it is C(no_log).
|
|
pve_lxc_api_host:
|
|
type: str
|
|
description:
|
|
- >-
|
|
Address of the Proxmox API (port 8006). Role default the C(ansible_host) of C(pve_lxc_node), or empty when
|
|
C(pve_lxc_node) is undefined; a Jinja expression in C(defaults/main.yml), so it is not repeated here.
|
|
pve_lxc_net_interface:
|
|
type: str
|
|
default: eth0
|
|
description:
|
|
- Name of the container network interface in C(net0).
|
|
pve_lxc_net_prefix:
|
|
type: raw
|
|
default: ""
|
|
description:
|
|
- >-
|
|
Prefix length (1 to 32) appended to C(ansible_host) in C(net0). Environment-specific, so the empty default
|
|
is a placeholder: the role fails with a clear message while it is unset and the LXC lifecycle is managed
|
|
with C(pve_lxc_state) other than C(absent).
|