diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 8f84274..851828f 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -28,7 +28,7 @@ jobs: timeout-minutes: 30 # The ci image (images/ci, built by image.yml): tag for the release, digest enforced. container: - image: git.rkdr.net/mortis/ci:0.2.43@sha256:373c3ba69e3cdccdf6acf96d9c1cbfa173d2db0fbda441f4256eb46bd3ce6b99 + image: git.rkdr.net/mortis/ci:0.2.45@sha256:922febf5bdccbc773a4f7f52cf118498d029f27a7c56b33c9b6f43ac2b6c2d32 env: PIP_DISABLE_PIP_VERSION_CHECK: "1" steps: diff --git a/.gitea/workflows/gitea-release-key.yml b/.gitea/workflows/gitea-release-key.yml index 5b25a14..0eb0191 100644 --- a/.gitea/workflows/gitea-release-key.yml +++ b/.gitea/workflows/gitea-release-key.yml @@ -44,7 +44,7 @@ jobs: # The ci image (images/ci, built by image.yml), at the pin of lint.yml: tag for the # release, digest enforced. Only its /opt/venv Python (with PyYAML) is used here. container: - image: git.rkdr.net/mortis/ci:0.2.43@sha256:373c3ba69e3cdccdf6acf96d9c1cbfa173d2db0fbda441f4256eb46bd3ce6b99 + image: git.rkdr.net/mortis/ci:0.2.45@sha256:922febf5bdccbc773a4f7f52cf118498d029f27a7c56b33c9b6f43ac2b6c2d32 steps: # The container has no Node, so JavaScript actions such as actions/checkout # cannot run; clone with git and the job token. diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index 5e0888b..bfab4f0 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -31,7 +31,7 @@ jobs: # The tag says which release, the digest is what is enforced (bump both together # when image.yml publishes a new version). container: - image: git.rkdr.net/mortis/ci:0.2.43@sha256:373c3ba69e3cdccdf6acf96d9c1cbfa173d2db0fbda441f4256eb46bd3ce6b99 + image: git.rkdr.net/mortis/ci:0.2.45@sha256:922febf5bdccbc773a4f7f52cf118498d029f27a7c56b33c9b6f43ac2b6c2d32 env: PIP_DISABLE_PIP_VERSION_CHECK: "1" PRE_COMMIT_HOME: /opt/pre-commit diff --git a/.gitea/workflows/molecule.yml b/.gitea/workflows/molecule.yml index d76791c..2dd3c7e 100644 --- a/.gitea/workflows/molecule.yml +++ b/.gitea/workflows/molecule.yml @@ -54,7 +54,7 @@ jobs: env: # The tools and collections molecule runs with: the image Lint and Build use. CI_IMAGE: >- - git.rkdr.net/mortis/ci:0.2.43@sha256:373c3ba69e3cdccdf6acf96d9c1cbfa173d2db0fbda441f4256eb46bd3ce6b99 + git.rkdr.net/mortis/ci:0.2.45@sha256:922febf5bdccbc773a4f7f52cf118498d029f27a7c56b33c9b6f43ac2b6c2d32 # Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run # one locally. MOLECULE_IMAGE: >- diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3657eec..c891494 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,15 @@ mortis.kamino Release Notes .. contents:: Topics +v2.2.0 +====== + +Minor Changes +------------- + +- galaxy.yml - Declare ``community.proxmox`` (>=2.1.0) as a dependency, needed by ``pve_lxc``. Its modules need the Python library ``proxmoxer`` 2.3 or later on the controller. +- 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. + v2.1.0 ====== diff --git a/README.md b/README.md index 86d4ef5..ca3d82e 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ 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). +Status: roles arrive in waves. Release 2.2.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `pihole`, `pve_lxc`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call). ## Consuming @@ -17,11 +17,13 @@ name (FQCN) only, `mortis.kamino.`: collections: - name: https://git.rkdr.net/mortis/kamino.git type: git - version: v2.1.0 + version: v2.2.0 ``` -Its dependencies (`community.general`, `ansible.posix`) are declared in `galaxy.yml`, so -`ansible-galaxy` installs them unless the same file already pins a satisfying version. +Its dependencies (`community.general`, `ansible.posix`, `community.proxmox`) are declared in `galaxy.yml`, so +`ansible-galaxy` installs them unless the same file already pins a satisfying version. The modules of +`community.proxmox` also need the Python library `proxmoxer` 2.3 or later on the controller +(`pip install 'proxmoxer>=2.3'`); `galaxy.yml` cannot declare a Python dependency. ```yaml - ansible.builtin.include_role: @@ -39,7 +41,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/.plugin-cache.yaml b/changelogs/.plugin-cache.yaml index 1f4807d..de50b32 100644 --- a/changelogs/.plugin-cache.yaml +++ b/changelogs/.plugin-cache.yaml @@ -35,6 +35,10 @@ objects: description: Install and configure Pi-hole from the upstream repository name: pihole version_added: null + pve_lxc: + description: Manage a Proxmox LXC container + name: pve_lxc + version_added: null sshd: description: Write a hardened sshd drop-in name: sshd @@ -65,6 +69,8 @@ plugins: callback: {} cliconf: {} connection: {} + eda_event_filter: {} + eda_event_source: {} filter: {} httpapi: {} inventory: {} @@ -75,4 +81,4 @@ plugins: strategy: {} test: {} vars: {} -version: 2.1.0 +version: 2.2.0 diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 558b550..e580c08 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -414,3 +414,19 @@ releases: - pihole-role.yml - system-baseline-apt-tmpdir.yml release_date: '2026-11-25' + 2.2.0: + changes: + minor_changes: + - galaxy.yml - Declare ``community.proxmox`` (>=2.1.0) as a dependency, needed + by ``pve_lxc``. Its modules need the Python library ``proxmoxer`` 2.3 or later + on the controller. + - 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. + fragments: + - 386-community-proxmox-dependency.yml + - pve-lxc-role.yml + release_date: '2026-11-25' diff --git a/docs/images/ci.md b/docs/images/ci.md index 968fd8a..5e15584 100644 --- a/docs/images/ci.md +++ b/docs/images/ci.md @@ -9,9 +9,10 @@ Ubuntu 26.04 with: - **Python tools** in `/opt/venv` (on `PATH`; it runs on Python 3.14, the version of `.python-version`, from the baked copy and not from the distribution's `python3`), from `requirements-dev.lock` (the hashed lock of `requirements-dev.txt`, installed with `pip install --require-hashes`): `ansible-core`, `ansible-lint`, `pre-commit`, `antsibull-changelog`, `galaxy-importer`, `reuse`, `molecule` and - `molecule-plugins[docker]` (the Docker driver, with the `docker` Python SDK). + `molecule-plugins[docker]` (the Docker driver, with the `docker` Python SDK), and `proxmoxer`, the controller-side + library the modules of `community.proxmox` import. - **The collections the roles call** in `/opt/collections` (`ANSIBLE_COLLECTIONS_PATH` is set to it), from - `requirements.yml`: `community.general` and `ansible.posix` at the exact versions CI tests against, so + `requirements.yml`: `community.general`, `ansible.posix` and `community.proxmox` at the exact versions CI tests against, so `ansible-lint --offline` resolves their modules instead of mocking them; and from `extensions/molecule/requirements.yml`, `community.docker`, which the Molecule Docker driver's own playbooks call. - **Every pre-commit hook environment** of `.pre-commit-config.yaml` in `/opt/pre-commit` diff --git a/galaxy.yml b/galaxy.yml index 238b60a..6eb8d3c 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,14 +1,14 @@ --- namespace: mortis name: kamino -version: 2.1.0 +version: 2.2.0 readme: README.md 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: @@ -22,10 +22,13 @@ homepage: https://git.rkdr.net/mortis/kamino issues: https://git.rkdr.net/mortis/kamino/issues # CI tests the versions pinned in requirements.yml; the lower bounds here are not tested. # No upper bound, so a consumer's newer pin does not conflict. community.general is used by system_baseline and ufw, -# ansible.posix by system_baseline and user_management. +# ansible.posix by system_baseline and user_management, community.proxmox by pve_lxc (Proxmox VE guest lifecycle). +# community.proxmox's modules import the Python library proxmoxer (2.3 or later) on the controller; galaxy.yml +# cannot declare a Python dependency, so the README says it and requirements-dev.txt pins it for CI. dependencies: community.general: ">=14.0.0" ansible.posix: ">=2.2.0" + community.proxmox: ">=2.1.0" build_ignore: # Repository tooling that is not part of the Collection. scripts/check_tarball.py fails # the build if anything outside its allowlist ends up in the archive, so a new top-level diff --git a/images/ci/Dockerfile b/images/ci/Dockerfile index bf67b70..65a116c 100644 --- a/images/ci/Dockerfile +++ b/images/ci/Dockerfile @@ -12,7 +12,7 @@ # - OS packages: git, shellcheck (actionlint runs it over run: blocks), the # distribution's python3 and ca-certificates. # - /opt/venv: requirements-dev.lock, the hashed lock of requirements-dev.txt (ansible-core, ansible-lint, pre-commit, -# antsibull-changelog, galaxy-importer, reuse, molecule and its Docker driver), on the Python of +# antsibull-changelog, galaxy-importer, reuse, molecule and its Docker driver, proxmoxer), on the Python of # .python-version (PYTHON_VERSION below), the one the lock was resolved on and a clone's .venv uses. # - /opt/collections: the collections of requirements.yml (the versions the roles are # tested against), found through ANSIBLE_COLLECTIONS_PATH, so `ansible-lint --offline` @@ -177,7 +177,7 @@ FROM os AS final ARG PYTHON_VERSION=3.14 LABEL org.opencontainers.image.title="ci" \ - org.opencontainers.image.description="CI tooling image for the mortis.kamino Ansible Collection: the Lint, Build and Molecule workflows run in it, so a job only checks out the code and runs. It bakes in ansible-core, ansible-lint, pre-commit with every hook environment of the repository, antsibull-changelog, galaxy-importer, reuse, molecule with its Docker driver, the collections of requirements.yml and extensions/molecule/requirements.yml, git, shellcheck, Python 3.11, 3.13 and the version of .python-version (the tools in /opt/venv run on it) next to the distribution python3 and primed ansible-test sanity virtualenvs. Pin it by tag and digest, as a job container or with docker run; it has no Node, so clone with git." \ + org.opencontainers.image.description="CI tooling image for the mortis.kamino Ansible Collection: the Lint, Build and Molecule workflows run in it, so a job only checks out the code and runs. It bakes in ansible-core, ansible-lint, pre-commit with every hook environment of the repository, antsibull-changelog, galaxy-importer, reuse, molecule with its Docker driver, proxmoxer, the collections of requirements.yml and extensions/molecule/requirements.yml, git, shellcheck, Python 3.11, 3.13 and the version of .python-version (the tools in /opt/venv run on it) next to the distribution python3 and primed ansible-test sanity virtualenvs. Pin it by tag and digest, as a job container or with docker run; it has no Node, so clone with git." \ org.opencontainers.image.source="https://git.rkdr.net/mortis/kamino" \ org.opencontainers.image.url="https://git.rkdr.net/mortis/kamino" \ org.opencontainers.image.documentation="https://git.rkdr.net/mortis/kamino/src/branch/main/docs/images/ci.md" \ @@ -185,7 +185,7 @@ LABEL org.opencontainers.image.title="ci" \ org.opencontainers.image.authors="Defame1297 and contributors" \ org.opencontainers.image.base.name="ubuntu:26.04" \ net.rkdr.mortis.purpose="CI tooling image for the mortis.kamino Ansible Collection: the Lint, Build and Molecule workflows run in it, so a job only checks out the code and runs." \ - net.rkdr.mortis.contents="Ubuntu 26.04, /opt/venv (ansible-core, ansible-lint, pre-commit, antsibull-changelog, galaxy-importer, reuse, molecule, molecule-plugins[docker]), /opt/collections (community.general, ansible.posix, community.docker), /opt/pre-commit hook environments, ansible-test sanity venvs, python3 (distribution), python3.11, python3.13, python (the one of /opt/venv), git, shellcheck, /opt/ci-pins.sha256" \ + net.rkdr.mortis.contents="Ubuntu 26.04, /opt/venv (ansible-core, ansible-lint, pre-commit, antsibull-changelog, galaxy-importer, reuse, molecule, molecule-plugins[docker], proxmoxer), /opt/collections (community.general, ansible.posix, community.proxmox, community.docker), /opt/pre-commit hook environments, ansible-test sanity venvs, python3 (distribution), python3.11, python3.13, python (the one of /opt/venv), git, shellcheck, /opt/ci-pins.sha256" \ net.rkdr.mortis.usage="Lint and Build: job container on the kamino-docker runner, git.rkdr.net/mortis/ci:version@sha256:digest with PRE_COMMIT_HOME set to /opt/pre-commit. Molecule (host executor, kamino-molecule runner): docker run as the runner user, with the Docker socket and the checkout mounted at the same path. In both, run sha256sum -c /opt/ci-pins.sha256 in the checkout root and install the pinned tools and collections when a pull request changed them, else use /opt/venv/bin and ANSIBLE_COLLECTIONS_PATH=/opt/collections. See the documentation label." ENV PIP_DISABLE_PIP_VERSION_CHECK=1 \ diff --git a/requirements-dev.lock b/requirements-dev.lock index cbb959b..a1ff4d4 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -1623,6 +1623,10 @@ propcache==0.5.4 \ # via # aiohttp # yarl +proxmoxer==2.3.0 \ + --hash=sha256:0b0b2067187af1fc6d4257a46ac68c8fd79cc25d2813637cdae7a9a98fbfd11f \ + --hash=sha256:1c03445e95cf9c53b6e50614dbaf561e0e1eb3ec878cf45ddde4bc4421c56743 + # via -r requirements-dev.txt puremagic==2.3.0 \ --hash=sha256:15ce035fe4c3f23e884a105d07448a5a81dd2e297985bdb636928ddf89bb3fe7 \ --hash=sha256:b54e4a69dd37c50bacc879380f132382ab4e9a935529628c8975abcc73e10640 diff --git a/requirements-dev.txt b/requirements-dev.txt index 1cd271c..373fb55 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -14,6 +14,9 @@ galaxy-importer==0.4.44 reuse==6.3.0 molecule==26.11.0 molecule-plugins[docker]==26.11.0 +# proxmoxer: the controller-side library community.proxmox's modules import (they refuse anything below 2.3), +# so lint and Molecule run where a consumer's controller would. +proxmoxer==2.3.0 # apm-cli: for changing apm.yml (run apm install, commit the lock). Keep it at 0.36.1 or later (#252): # before 0.29.0, `apm audit --ci` compares the whole .claude/settings.json and fails on any hand-written key. apm-cli==0.37.0 diff --git a/requirements.yml b/requirements.yml index 8641753..d32c390 100644 --- a/requirements.yml +++ b/requirements.yml @@ -11,3 +11,5 @@ collections: version: 14.0.1 - name: ansible.posix version: 2.2.2 + - name: community.proxmox + version: 2.1.0 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/