diff --git a/README.md b/README.md index 86d4ef5..13d3ea8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ An Ansible Collection of reusable, hardened roles for a self-hosted home lab: `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, -`pihole`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and +`pihole`, `pve_lxc`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management`, plus the internal `_binary_update`. Roles still to come are listed under [Roadmap](#roadmap). Status: roles arrive in waves. Release 2.1.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `pihole`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call). @@ -39,7 +39,7 @@ when its own prerequisites (tests, a safe cutover wherever the role already runs Still to come: -- Wave 2: `pve_vm`, `pve_lxc`, `tailscale`. +- Wave 2: `pve_vm`, `tailscale`. - Wave 3: `rke2`, `proxmox_host`. - Later, wave not yet assigned: `opnsense`, `proxmox_firewall`. diff --git a/changelogs/fragments/pve-lxc-role.yml b/changelogs/fragments/pve-lxc-role.yml new file mode 100644 index 0000000..91745e8 --- /dev/null +++ b/changelogs/fragments/pve-lxc-role.yml @@ -0,0 +1,7 @@ +--- +minor_changes: + - >- + pve_lxc - New role. Creates, updates, grows the root disk of, starts, stops and (with ``pve_lxc_allow_destroy``) + deletes 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. Declares Debian trixie, untested; + the molecule scenario covers the node-side files and the input validation, not the API lifecycle. diff --git a/galaxy.yml b/galaxy.yml index 238b60a..80caa26 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -7,8 +7,8 @@ authors: - Defame1297 description: >- Reusable, hardened Ansible roles for a self-hosted home lab (cloudflared, docker, fail2ban, - gitea, gitea_runner, network_interfaces, pihole, sshd, system_baseline, systemd_hardening, - traefik, ufw, user_management; _binary_update is internal). + gitea, gitea_runner, network_interfaces, pihole, pve_lxc, sshd, system_baseline, + systemd_hardening, traefik, ufw, user_management; _binary_update is internal). license: - GPL-3.0-or-later tags: diff --git a/roles/pve_lxc/README.md b/roles/pve_lxc/README.md new file mode 100644 index 0000000..6993bba --- /dev/null +++ b/roles/pve_lxc/README.md @@ -0,0 +1,108 @@ +# pve_lxc + +Creates and maintains a Proxmox VE LXC container through the Proxmox API: configuration, root disk size, raw `lxc.*` config lines, an opt-in guest firewall file and the power state. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth. + +## Supported platforms + +Proxmox VE nodes on Debian 13 (trixie). The play runs for the container's inventory host: the API calls run on the controller (`delegate_to: localhost`), and the raw config, the guest firewall file and the filesystem resize run on the Proxmox node (`delegate_to: pve_lxc_node`) with become. + +Untested platforms: Debian trixie, as declared in `meta/main.yml`. The molecule scenario runs the node-side tasks in an Ubuntu 24.04 (noble) container standing in for the node (see [Tests](#tests)); a Debian test image does not exist yet. + +The role targets Proxmox nodes only, so it does not cover Ubuntu noble or resolute: Proxmox VE runs on Debian. + +## Requirements and run order + +- Use it by its fully qualified name, `mortis.kamino.pve_lxc`, in a play over the container hosts. It gathers no facts and needs none. +- The controller needs the `community.proxmox` collection and the Python library `proxmoxer`. +- Role dependencies: none. +- `pve_lxc_node` must be an inventory host: the node-side tasks are delegated to it, and its `ansible_host` is the default API address. `pve_lxc_api_user` and `pve_lxc_api_token_secret` have no usable default and are asserted non-empty before any change when `pve_lxc_manage_lifecycle` is true; `pve_lxc_net_prefix` too, unless `pve_lxc_state` is `absent`. The raw config and firewall inputs are validated at the same point. +- The container's own `ansible_host` is its address in `net0` and the target of the SSH wait, and `inventory_hostname` is its hostname. +- Run it before any role that configures the inside of the container. Gate those on `pve_lxc_present` (below), so a container that is absent is not configured. + +## Role variables + +No variable is marked required in the argument spec: with `pve_lxc_manage_lifecycle: false` the role reads none of the Proxmox inputs. + +| Variable | Default | Description | +|---|---|---| +| `pve_lxc_state` | `present` | `present`, `started`, `stopped` or `absent`. `present` leaves the power state alone. | +| `pve_lxc_manage_lifecycle` | `true` | False skips everything and treats the container as present (a container on a node Ansible does not manage). | +| `pve_lxc_allow_destroy` | `false` | Required before `absent` deletes the container. | +| `pve_lxc_wait_for_ssh` | `true` | Wait for SSH on port 22 of `ansible_host` when `started`. | +| `pve_lxc_manage_disk` | `false` | Grow the root disk to the size in `pve_lxc_disk`. | +| `pve_lxc_reboot_if_required` | `true` | Restart the container after its root filesystem was grown. | +| `pve_lxc_pubkey` | `""` | Public keys for root, one per line. | +| `pve_lxc_features` | `[]` | Container features, for example `nesting=1`. Omitted when empty. | +| `pve_lxc_restart_on_config_change` | `false` | Restart after a configuration update reports a change. | +| `pve_lxc_cmode` | `tty` | Console mode sent on update. | +| `pve_lxc_raw_config` | `[]` | Raw `lxc.*` lines, one per item. See Notes. | +| `pve_lxc_onboot` | `true` | Start on node boot, for `started` and `present`. A `stopped` container always gets `onboot=0`. | +| `pve_lxc_node`, `pve_lxc_vmid` | none | Inventory name of the Proxmox node and container id. | +| `pve_lxc_ostemplate` | none | Template volume, for example `local:vztmpl/