Author SHA1 Message Date
Defame1297 4f9b96b2f4 Merge branch 'main' into feat/tailscale-role
Build / build (pull_request) Successful in 30s
Molecule / molecule (pull_request) In progress
Lint / lint (pull_request) Successful in 2m25s
2026-11-26 21:32:08 +00:00
Defame1297 731bc022cd fix(tailscale): tolerate an unloaded tailscaled unit in reset-failed
Build / build (pull_request) Successful in 26s
Lint / lint (pull_request) Canceled after 2m8s
Molecule / molecule (pull_request) Canceled after 1m37s
After a removal without purge the role has disabled tailscaled, so the
reinstall's postinst does not start it. systemd then unloads the inactive,
unreferenced unit, and `systemctl reset-failed tailscaled` exits 1 with
"Unit tailscaled.service not loaded.", failing the configure step on both
noble and resolute. An unloaded unit has no failure state to clear, and the
restart that follows loads it, so that one error is not a failure.

Assisted-by: Claude Code:claude-opus-5-5
2026-11-26 21:24:10 +00:00
Defame1297 29165a610f fix(tailscale): harden removal, restarts and the auth key check
Build / build (pull_request) Successful in 29s
Lint / lint (pull_request) Successful in 2m25s
Molecule / molecule (pull_request) Failing after 3m23s
- Removal passes on a host without a tailscaled unit, and the
  best-effort logout reports a change only when it succeeded.
- Under --check the service tasks run only when the unit exists, also
  with --tags configure on a host without the package.
- The auth key is required before any change only when the run includes
  the configure tasks; --tags remove, install and update need none. The
  assert in the up block stays as the hard guard.
- When the flags change or tailscaled is not active, the role clears its
  failure state and restarts it at once, so a daemon the package started
  without a TUN device does not stay in the start limit.
- The health tag is back on the configure include.
- The scenario tests removal without purge (state and defaults kept, a
  second removal passes) and a purge with a state directory the package
  does not delete itself, and waits for tailscaled to be active.

Assisted-by: Claude Code:claude-opus-5-5
2026-11-26 20:47:49 +00:00
Defame1297 9c415ee347 Merge pull request 'ci(lint): enable and gate ansible-lint's complexity rule' (#397) from ci/138-complexity-gate into main
Reviewed-on: #397
2026-11-26 19:30:30 +00:00
Defame1297 3b20a1b6c6 ci(lint): enable and gate ansible-lint's complexity rule
Build / build (pull_request) Successful in 29s
Molecule / molecule (pull_request) Successful in 5s
Lint / lint (pull_request) Successful in 1m31s
Enable complexity at the default max_tasks and empty warn_list so
experimental findings fail Lint. Replace the repository-wide role-name
skip with an ignore line for the internal role _binary_update, so a
misnamed public role fails.

Closes #138

Assisted-by: Claude Code:claude-opus-5-5
2026-11-26 19:19:15 +00:00
Defame1297 80c76b16ee feat(tailscale): add the tailscale role
Installs Tailscale from the upstream APT repository with the keyring
pinned by sha256, enables tailscaled and, with tailscale_up (default
true), runs tailscale up with tailscale_auth_key while the node is not
Running. It can also update to the APT candidate version and remove or
purge.

The role asserts Ubuntu and follows the host's release, and requires a
non-empty auth key before any change whenever tailscale up will run.
tailscale_userspace_networking now sets --tun=userspace-networking in
the FLAGS of /etc/default/tailscaled, where tailscaled reads it, instead
of passing it to tailscale up.

The molecule scenario installs the real package on noble and resolute
without joining a tailnet, and covers the update and purge paths and
the refusal cases.

Closes #396

Assisted-by: Claude Code:claude-opus-5-5
2026-11-26 19:08:25 +00:00
Defame1297 31634c4eef Merge pull request 'test(roles): run molecule's check step before and after converge' (#395) from test/134-check-before-after-converge into main
Reviewed-on: #395
Reviewed-by: Defame1297 <[email protected]>
2026-11-26 15:22:51 +00:00
Defame1297 6b99ac9ca0 Merge branch 'main' into test/134-check-before-after-converge
Build / build (pull_request) Successful in 32s
Lint / lint (pull_request) Successful in 2m59s
Molecule / molecule (pull_request) Successful in 42m34s
2026-11-26 14:39:35 +00:00
Defame1297 9ce0fbd433 fix(roles): refresh apt in the docker and traefik scenarios and apply review round 2
Build / build (pull_request) Successful in 22s
Lint / lint (pull_request) Successful in 2m1s
Molecule / molecule (pull_request) Successful in 44m6s
The molecule images ship without apt lists, and --check does not
refresh them, so the fresh-host check of docker and traefik could not
find curl and wget. Their prepare now refreshes the cache, as pihole's
and system_baseline's already do by installing fixtures.

The sequence test gets its own class after the platform tests, the
check-mode rule is split into guards and README, and the
user_management comment sits on the task it explains.

Assisted-by: Claude Code
2026-11-26 12:18:48 +00:00
Defame1297 3afff00b9b fix(roles): apply review findings to the check-mode change
Build / build (pull_request) Successful in 25s
Lint / lint (pull_request) Successful in 2m13s
Molecule / molecule (pull_request) Failing after 34m3s
Guard gitea_runner's docker group membership like its Docker start, run
user_management's getent probe unconditionally, and state the
play-level check_mode limit in every touched README. The check-mode
rule now allows the pihole guard form and names roles whose --check
needs their package installed.

Assisted-by: Claude Code
2026-11-26 11:11:19 +00:00
Defame1297 824456ea65 Merge pull request 'chore(deps): update git.rkdr.net/mortis/ci docker tag to v0.2.46' (#393) from renovate/git.rkdr.net-mortis-ci-0.x into main
Reviewed-on: #393
2026-11-26 10:46:04 +00:00
Defame1297 cf2286b7a7 test(roles): run molecule's check step before and after converge
Every role scenario with a converge now runs check right before it (a
fresh host) and right after it (a configured host), and a script test
fails a scenario without both. pihole and pve_lxc move their second
check from after idempotence to after converge to match.

The roles that failed under --check on a fresh host get the two allowed
guards: cloudflared, docker, gitea, gitea_runner, traefik and
user_management. ufw and fail2ban preview only a host where their
package is installed, as their READMEs now say.

Closes #134

Assisted-by: Claude Code
2026-11-26 10:11:54 +00:00
Defame1297 b8ad7fc0a6 Merge branch 'main' into renovate/git.rkdr.net-mortis-ci-0.x
Gitea release key / check (pull_request) Successful in 24s
Build / build (pull_request) Successful in 27s
Lint / lint (pull_request) Successful in 3m18s
Molecule / molecule (pull_request) Successful in 43m39s
2026-11-26 10:01:44 +00:00
Defame1297 51b38211e7 Merge pull request 'chore(release): 3.0.0' (#394) from chore/release-3.0.0 into main
Build / build (push) Successful in 23s
Reviewed-on: #394
2026-11-26 09:18:12 +00:00
Defame1297 27c4ca14c4 chore(release): 3.0.0
Build / build (pull_request) Successful in 1m11s
Lint / lint (pull_request) Successful in 5m26s
Molecule / molecule (pull_request) Successful in 1m56s
Major release: the roles declare exactly the Ubuntu releases they pass
Molecule on in CI. Ubuntu 26.04 (resolute) is added next to 24.04
(noble); 22.04 (jammy) is dropped from five roles and docker narrows
from every Ubuntu release to noble and resolute.

Assisted-by: Claude Code
2026-11-26 08:11:04 +00:00
renovate-bot ff13f2d3a4 chore(deps): update git.rkdr.net/mortis/ci docker tag to v0.2.46
renovate/stability-days Updates have met minimum release age requirement
Gitea release key / check (pull_request) Successful in 52s
Build / build (pull_request) Successful in 1m15s
Lint / lint (pull_request) Successful in 3m9s
Molecule / molecule (pull_request) Successful in 35m49s
2026-11-26 08:10:58 +00:00
Defame1297 7a4e9f161e Merge pull request 'chore(deps): update dependency apm-cli to v0.38.0' (#392) from renovate/apm-cli-0.x into main
Images / image (0.1, Dockerfile, ubuntu:24.04@sha256:9c7f200c07e3d4a03e7249d2c16bf66a51120fb876aa2242cf31451412543289, molecule-ubuntu2404, images/molecule-ubuntu2404) (push) Successful in 53s
Images / image (0.1, Dockerfile, ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db, molecule-ubuntu2604, images/molecule-ubuntu2604) (push) Successful in 2m20s
Images / image (0.2, images/ci/Dockerfile, ubuntu:26.04@sha256:d66b366dac61b575bee2aef07e9c26e8070096fbe84a3d4d3eb0da069b5d76db, ci, ) (push) Successful in 7m37s
Reviewed-on: #392
2026-11-26 07:59:18 +00:00
Defame1297 11c5e1987f Merge branch 'main' into renovate/apm-cli-0.x
Build / build (pull_request) Successful in 24s
Molecule / molecule (pull_request) Successful in 56s
Lint / lint (pull_request) Successful in 1m49s
2026-11-26 07:57:23 +00:00
Defame1297 6fe3970f23 Merge pull request 'test(roles): run the Ubuntu roles on 24.04 and 26.04 and declare exactly those' (#381) from test/133-ubuntu-2404-2604 into main
Reviewed-on: #381
2026-11-26 07:46:31 +00:00
Defame1297 042c926058 Merge remote-tracking branch 'origin/main' into test/133-ubuntu-2404-2604
Build / build (pull_request) Successful in 32s
Lint / lint (pull_request) Successful in 3m10s
Molecule / molecule (pull_request) Successful in 35m55s
2026-11-26 06:40:49 +00:00
renovate-bot 6ab8b82fba chore(deps): update dependency apm-cli to v0.38.0
renovate/stability-days Updates have met minimum release age requirement
Build / build (pull_request) Successful in 21s
Molecule / molecule (pull_request) Successful in 1m2s
Lint / lint (pull_request) Successful in 1m52s
2026-11-26 03:18:34 +00:00
Defame1297 a6b8bc150d test(roles): run docker and gitea on 26.04 and check become in its smoke scenario
Build / build (pull_request) Successful in 46s
Molecule / molecule (pull_request) Canceled after 30s
Lint / lint (pull_request) Canceled after 44s
molecule-ubuntu2604 0.1.7 lets become from root through and ships gnupg,
so docker and gitea declare resolute like the other Ubuntu roles and the
accepted exception goes. The 26.04 image-smoke scenario now checks
become and gnupg, so a regression fails the image's own pin pull request.

Assisted-by: Claude Code
2026-11-25 22:33:59 +00:00
Defame1297 5f936962e0 Merge remote-tracking branch 'origin/main' into test/133-ubuntu-2404-2604 2026-11-25 22:26:07 +00:00
Defame1297 1f27f02f13 test(roles): accept both prohibit-password names and declare pihole on 26.04
Build / build (pull_request) Successful in 32s
Lint / lint (pull_request) Successful in 3m0s
Molecule / molecule (pull_request) Failing after 13m34s
sshd -T prints prohibit-password as without-password on OpenSSH 9 and
as prohibit-password on OpenSSH 10 (Ubuntu 26.04). pihole shipped in
2.1.0 on noble only, so gaining resolute is a minor change. The docker
and gitea exception now points at the image fix, #376.

Assisted-by: Claude Code
2026-11-25 21:09:12 +00:00
Defame1297 df06260b27 Merge remote-tracking branch 'origin/main' into test/133-ubuntu-2404-2604
# Conflicts:
#	changelogs/fragments/pihole-role.yml
2026-11-25 21:09:00 +00:00
Defame1297 2e1ad033e4 test(roles): run the Ubuntu roles on 24.04 and 26.04 and declare exactly those
Build / build (pull_request) Successful in 51s
Lint / lint (pull_request) Successful in 3m42s
Molecule / molecule (pull_request) Failing after 20m50s
Every role except network_interfaces runs its molecule scenarios on the
24.04 and 26.04 images and declares Ubuntu noble and resolute; jammy and
Ubuntu all are dropped. trixie stays declared until the Debian 13 image
(#226) tests it. docker and gitea stay on noble until the 26.04 image
ships gnupg (#378).

Closes #133

Assisted-by: Claude Code
2026-11-25 20:17:53 +00:00
105 changed files with 1754 additions and 165 deletions

No files matched your search

+5 -4
View File
@@ -24,7 +24,8 @@ exclude_paths:
supported_ansible_also: supported_ansible_also:
- "2.22." - "2.22."
skip_list: # complexity runs at the default max_tasks (100) until the schema accepts the key (#139). An empty
# role-name requires ^[a-z][a-z0-9_]*$, which rejects the leading underscore that marks an # warn_list makes experimental rules (complexity), jinja[spacing] and fqcn[deep] fail Lint.
# internal role (_binary_update), as in prometheus.prometheus (roles/_common). enable_list:
- role-name - complexity
warn_list: []
+3
View File
@@ -9,3 +9,6 @@ roles/_binary_update/molecule/check_mode/verify.yml var-naming[no-role-prefix]
roles/_binary_update/molecule/default/verify.yml var-naming[no-role-prefix] roles/_binary_update/molecule/default/verify.yml var-naming[no-role-prefix]
roles/_binary_update/molecule/default/tasks/assert_state.yml var-naming[no-role-prefix] roles/_binary_update/molecule/default/tasks/assert_state.yml var-naming[no-role-prefix]
roles/_binary_update/molecule/resources/roles/binary_update_caller/tasks/main.yml var-naming[no-role-prefix] roles/_binary_update/molecule/resources/roles/binary_update_caller/tasks/main.yml var-naming[no-role-prefix]
# role-name requires ^[a-z][a-z0-9_]*$, which rejects the leading underscore that marks an
# internal role (_binary_update), as in prometheus.prometheus (roles/_common).
roles/_binary_update role-name
+5 -3
View File
@@ -110,14 +110,16 @@ issue.
*Why:* a pull request that raises the ansible-core floor must run its scenarios on the new core *Why:* a pull request that raises the ansible-core floor must run its scenarios on the new core
before it automerges. *Held:* control: the pin comparison in `molecule.yml`. before it automerges. *Held:* control: the pin comparison in `molecule.yml`.
- **Every scenario sets `scenario.test_sequence` to molecule's default minus both `destroy` - **Every scenario sets `scenario.test_sequence` to molecule's default minus both `destroy`
steps, names each platform `${KAMINO_RUN_ID:-local}-<name>` and labels it steps, with a role scenario's `check` right before and right after `converge`, names each
platform `${KAMINO_RUN_ID:-local}-<name>` and labels it
`net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"` in its `molecule.yml`;** copy it into `net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"` in its `molecule.yml`;** copy it into
a new scenario. *Why:* the run script removes each scenario's containers by those names as soon a new scenario. *Why:* the run script removes each scenario's containers by those names as soon
as it ends, which skips the driver's destroy wait, the workflow finds a run's containers by the as it ends, which skips the driver's destroy wait, the workflow finds a run's containers by the
label, and the molecule state lives in each scenario's own `ANSIBLE_HOME` in the job tree, so a label, and the molecule state lives in each scenario's own `ANSIBLE_HOME` in the job tree, so a
killed run leaves none behind. *Held:* control: `tests/scripts/test_run_molecule_scenarios.py` killed run leaves none behind. *Held:* control: `tests/scripts/test_run_molecule_scenarios.py`
fails a `destroy` in a sequence, a platform name that is not unique or not per run, a missing fails a `destroy` in a sequence, a role scenario's `converge` without a `check` on each side, a
label, and a workflow that does not filter by it. platform name that is not unique or not per run, a missing label, and a workflow that does not
filter by it.
- **Scenarios live in `roles/*/molecule/*/` and `extensions/molecule/*/`.** A role scenario that - **Scenarios live in `roles/*/molecule/*/` and `extensions/molecule/*/`.** A role scenario that
must pass on Ubuntu 24.04 and 26.04 takes `image: ${MOLECULE_IMAGE}` or must pass on Ubuntu 24.04 and 26.04 takes `image: ${MOLECULE_IMAGE}` or
`${MOLECULE_IMAGE_2604}` per platform; the image-smoke scenarios are described in `${MOLECULE_IMAGE_2604}` per platform; the image-smoke scenarios are described in
+1 -1
View File
@@ -28,7 +28,7 @@ jobs:
timeout-minutes: 30 timeout-minutes: 30
# The ci image (images/ci, built by image.yml): tag for the release, digest enforced. # The ci image (images/ci, built by image.yml): tag for the release, digest enforced.
container: container:
image: git.rkdr.net/mortis/ci:0.2.45@sha256:922febf5bdccbc773a4f7f52cf118498d029f27a7c56b33c9b6f43ac2b6c2d32 image: git.rkdr.net/mortis/ci:0.2.46@sha256:a03015cc2177bdd6ef7f348f245a89f361893c7c64edc1264d9f9c1387d9defc
env: env:
PIP_DISABLE_PIP_VERSION_CHECK: "1" PIP_DISABLE_PIP_VERSION_CHECK: "1"
steps: steps:
+1 -1
View File
@@ -44,7 +44,7 @@ jobs:
# The ci image (images/ci, built by image.yml), at the pin of lint.yml: tag for the # 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. # release, digest enforced. Only its /opt/venv Python (with PyYAML) is used here.
container: container:
image: git.rkdr.net/mortis/ci:0.2.45@sha256:922febf5bdccbc773a4f7f52cf118498d029f27a7c56b33c9b6f43ac2b6c2d32 image: git.rkdr.net/mortis/ci:0.2.46@sha256:a03015cc2177bdd6ef7f348f245a89f361893c7c64edc1264d9f9c1387d9defc
steps: steps:
# The container has no Node, so JavaScript actions such as actions/checkout # The container has no Node, so JavaScript actions such as actions/checkout
# cannot run; clone with git and the job token. # cannot run; clone with git and the job token.
+1 -1
View File
@@ -31,7 +31,7 @@ jobs:
# The tag says which release, the digest is what is enforced (bump both together # The tag says which release, the digest is what is enforced (bump both together
# when image.yml publishes a new version). # when image.yml publishes a new version).
container: container:
image: git.rkdr.net/mortis/ci:0.2.45@sha256:922febf5bdccbc773a4f7f52cf118498d029f27a7c56b33c9b6f43ac2b6c2d32 image: git.rkdr.net/mortis/ci:0.2.46@sha256:a03015cc2177bdd6ef7f348f245a89f361893c7c64edc1264d9f9c1387d9defc
env: env:
PIP_DISABLE_PIP_VERSION_CHECK: "1" PIP_DISABLE_PIP_VERSION_CHECK: "1"
PRE_COMMIT_HOME: /opt/pre-commit PRE_COMMIT_HOME: /opt/pre-commit
+1 -1
View File
@@ -54,7 +54,7 @@ jobs:
env: env:
# The tools and collections molecule runs with: the image Lint and Build use. # The tools and collections molecule runs with: the image Lint and Build use.
CI_IMAGE: >- CI_IMAGE: >-
git.rkdr.net/mortis/ci:0.2.45@sha256:922febf5bdccbc773a4f7f52cf118498d029f27a7c56b33c9b6f43ac2b6c2d32 git.rkdr.net/mortis/ci:0.2.46@sha256:a03015cc2177bdd6ef7f348f245a89f361893c7c64edc1264d9f9c1387d9defc
# Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run # Used by the scenarios as `image: ${MOLECULE_IMAGE}`; set it the same way to run
# one locally. # one locally.
MOLECULE_IMAGE: >- MOLECULE_IMAGE: >-
+14
View File
@@ -4,6 +4,20 @@ mortis.kamino Release Notes
.. contents:: Topics .. contents:: Topics
v3.0.0
======
Minor Changes
-------------
- cloudflared, docker, fail2ban, gitea, gitea_runner, pihole, sshd, system_baseline, systemd_hardening, traefik, ufw, user_management - Declare and are tested on Ubuntu 26.04 (``resolute``) next to 24.04 (``noble``).
Breaking Changes / Porting Guide
--------------------------------
- docker - Declares Ubuntu 24.04 (``noble``) and 26.04 (``resolute``) instead of every Ubuntu release (``all``).
- sshd, system_baseline, systemd_hardening, ufw, user_management - No longer declare Ubuntu 22.04 (``jammy``). A platform a role declares is one it passes Molecule on in CI.
v2.2.0 v2.2.0
====== ======
+4 -4
View File
@@ -2,10 +2,10 @@
An Ansible Collection of reusable, hardened roles for a self-hosted home lab: An Ansible Collection of reusable, hardened roles for a self-hosted home lab:
`cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`,
`pihole`, `pve_lxc`, `sshd`, `system_baseline`, `systemd_hardening`, `traefik`, `ufw` and `pihole`, `pve_lxc`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`, `ufw` and
`user_management`, plus the internal `_binary_update`. Roles still to come are listed under [Roadmap](#roadmap). `user_management`, plus the internal `_binary_update`. Roles still to come are listed under [Roadmap](#roadmap).
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). Status: roles arrive in waves. Release 3.0.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 ## Consuming
@@ -17,7 +17,7 @@ name (FQCN) only, `mortis.kamino.<role>`:
collections: collections:
- name: https://git.rkdr.net/mortis/kamino.git - name: https://git.rkdr.net/mortis/kamino.git
type: git type: git
version: v2.2.0 version: v3.0.0
``` ```
Its dependencies (`community.general`, `ansible.posix`, `community.proxmox`) are declared in `galaxy.yml`, so Its dependencies (`community.general`, `ansible.posix`, `community.proxmox`) are declared in `galaxy.yml`, so
@@ -41,7 +41,7 @@ when its own prerequisites (tests, a safe cutover wherever the role already runs
Still to come: Still to come:
- Wave 2: `pve_vm`, `tailscale`. - Wave 2: `pve_vm`.
- Wave 3: `rke2`, `proxmox_host`. - Wave 3: `rke2`, `proxmox_host`.
- Later, wave not yet assigned: `opnsense`, `proxmox_firewall`. - Later, wave not yet assigned: `opnsense`, `proxmox_firewall`.
+1 -1
View File
@@ -81,4 +81,4 @@ plugins:
strategy: {} strategy: {}
test: {} test: {}
vars: {} vars: {}
version: 2.2.0 version: 3.0.0
+16
View File
@@ -430,3 +430,19 @@ releases:
- 386-community-proxmox-dependency.yml - 386-community-proxmox-dependency.yml
- pve-lxc-role.yml - pve-lxc-role.yml
release_date: '2026-11-25' release_date: '2026-11-25'
3.0.0:
changes:
breaking_changes:
- docker - Declares Ubuntu 24.04 (``noble``) and 26.04 (``resolute``) instead
of every Ubuntu release (``all``).
- sshd, system_baseline, systemd_hardening, ufw, user_management - No longer
declare Ubuntu 22.04 (``jammy``). A platform a role declares is one it passes
Molecule on in CI.
minor_changes:
- cloudflared, docker, fail2ban, gitea, gitea_runner, pihole, sshd, system_baseline,
systemd_hardening, traefik, ufw, user_management - Declare and are tested
on Ubuntu 26.04 (``resolute``) next to 24.04 (``noble``).
fragments:
- 133-drop-jammy-and-ubuntu-all.yml
- 133-ubuntu-2604.yml
release_date: '2026-11-26'
+17
View File
@@ -0,0 +1,17 @@
---
bugfixes:
- >-
cloudflared - Do not fail under ``--check`` on a host where the cloudflared account or systemd
unit does not exist yet.
- >-
docker - Do not fail under ``--check`` on a host where the Docker repository and packages are
not installed yet.
- >-
gitea - Do not fail under ``--check`` on a host where Gitea is not installed yet.
- >-
gitea_runner - Do not fail under ``--check`` on a host where the runner account, Docker or the
systemd unit does not exist yet.
- >-
traefik - Do not fail under ``--check`` on a host where Traefik is not installed yet.
- >-
user_management - Do not fail under ``--check`` when a managed user does not exist yet.
+9
View File
@@ -0,0 +1,9 @@
---
minor_changes:
- >-
tailscale - New role. Installs Tailscale from the upstream APT repository with the keyring pinned by sha256,
sets ``--tun=userspace-networking`` in the ``tailscaled`` flags when ``tailscale_userspace_networking`` is true,
enables ``tailscaled`` and, with ``tailscale_up`` (default ``true``), runs ``tailscale up`` with
``tailscale_auth_key`` while the node is not Running; it can also update to the APT candidate version and remove
or purge. Declares Ubuntu noble and resolute; the molecule scenario installs the real package but does not join a
tailnet.
+1 -1
View File
@@ -3,7 +3,7 @@
A disposable **Ubuntu 26.04** test target for the molecule scenarios of the A disposable **Ubuntu 26.04** test target for the molecule scenarios of the
[`mortis.kamino`](https://git.rkdr.net/mortis/kamino) Ansible Collection: a container that behaves like a small [`mortis.kamino`](https://git.rkdr.net/mortis/kamino) Ansible Collection: a container that behaves like a small
26.04 host (systemd as PID 1), so a role can be converged and verified in it without a VM. 26.04 host (systemd as PID 1), so a role can be converged and verified in it without a VM.
It is the release the hosts are moving to; the roles are tested on it next to 24.04. It is the release the hosts are moving to; every role scenario whose role declares `resolute` runs on it next to 24.04.
## What is in it ## What is in it
@@ -33,6 +33,7 @@
- ufw - ufw
- fail2ban - fail2ban
- openssh-server - openssh-server
- gnupg
- name: Query the units a role scenario relies on - name: Query the units a role scenario relies on
ansible.builtin.systemd: ansible.builtin.systemd:
@@ -56,3 +57,14 @@
- name: NET_ADMIN is granted, so the firewall tools can work - name: NET_ADMIN is granted, so the firewall tools can work
ansible.builtin.command: iptables -S ansible.builtin.command: iptables -S
changed_when: false changed_when: false
- name: Run a task with become, as the role scenarios do
ansible.builtin.command: id -u
become: true
changed_when: false
register: kamino_smoke_become
- name: Become reaches root
ansible.builtin.assert:
that: kamino_smoke_become.stdout == '0'
quiet: true
+2 -2
View File
@@ -1,14 +1,14 @@
--- ---
namespace: mortis namespace: mortis
name: kamino name: kamino
version: 2.2.0 version: 3.0.0
readme: README.md readme: README.md
authors: authors:
- Defame1297 - Defame1297
description: >- description: >-
Reusable, hardened Ansible roles for a self-hosted home lab (cloudflared, docker, fail2ban, Reusable, hardened Ansible roles for a self-hosted home lab (cloudflared, docker, fail2ban,
gitea, gitea_runner, network_interfaces, pihole, pve_lxc, sshd, system_baseline, gitea, gitea_runner, network_interfaces, pihole, pve_lxc, sshd, system_baseline,
systemd_hardening, traefik, ufw, user_management; _binary_update is internal). systemd_hardening, tailscale, traefik, ufw, user_management; _binary_update is internal).
license: license:
- GPL-3.0-or-later - GPL-3.0-or-later
tags: tags:
+3 -3
View File
@@ -240,9 +240,9 @@ anyio==4.16.0 \
# via # via
# httpx2 # httpx2
# openai # openai
apm-cli==0.37.0 \ apm-cli==0.38.0 \
--hash=sha256:1078dc4d5bd7d797f4924548f684daffd026df740b31f99b17fc13958e5da762 \ --hash=sha256:6dfac2fdc8ab68586afb2b1a5a6db3c1b7ab569ff0edc525448aa85d0f92bd38 \
--hash=sha256:87cbcb6a864aa8251ffea446fc34fd439caa6d01d51df1a9399669bed5fab576 --hash=sha256:aa51a98867ae6aef11e92143dd9ca2a994d3dd6cbd7224eae58fb7b8078fc3b1
# via -r requirements-dev.txt # via -r requirements-dev.txt
attrs==23.2.0 \ attrs==23.2.0 \
--hash=sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30 \ --hash=sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30 \
+1 -1
View File
@@ -19,4 +19,4 @@ molecule-plugins[docker]==26.11.0
proxmoxer==2.3.0 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): # 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. # 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 apm-cli==0.38.0
+15 -11
View File
@@ -18,7 +18,7 @@ names a check that does not exist yet and its backlog issue.
*Why:* a consumer finds the same thing in the same place. *Held:* review. *Why:* a consumer finds the same thing in the same place. *Held:* review.
- **Complexity.** A task file stays within ansible-lint's `complexity` limit, `max_tasks` 100 - **Complexity.** A task file stays within ansible-lint's `complexity` limit, `max_tasks` 100
(40 once ansible-lint accepts the key). *Why:* a long task file is hard to review. *Held:* (40 once ansible-lint accepts the key). *Why:* a long task file is hard to review. *Held:*
review until the Lint job enables `complexity` and fails on it (#138). control, ansible-lint `complexity` in the Lint job.
- **Roadmap.** The pull request that adds a role removes it from the README "Roadmap" list, and - **Roadmap.** The pull request that adds a role removes it from the README "Roadmap" list, and
the section goes when the list is empty. *Why:* the list is useful only if true. *Held:* review. the section goes when the list is empty. *Why:* the list is useful only if true. *Held:* review.
@@ -76,9 +76,8 @@ names a check that does not exist yet and its backlog issue.
- **Declared means tested.** A platform in `meta/main.yml` is one the role passes Molecule on in - **Declared means tested.** A platform in `meta/main.yml` is one the role passes Molecule on in
CI; one used but untested goes only in a README "Untested platforms" line. Accepted until the CI; one used but untested goes only in a README "Untested platforms" line. Accepted until the
Debian image (#226) and the platform cleanup (#133) land: `trixie` declared untested, and Debian image (#226) lands: `trixie` declared untested, and Debian `all` in network_interfaces.
`jammy` or `all` still declared. *Why:* no tool reads the declaration, so it is worth something *Why:* no tool reads the declaration, so it is worth something only if true. *Held:* review.
only if true. *Held:* review.
- **Platforms follow the target hosts.** Ubuntu-targeting roles declare exactly `noble` and - **Platforms follow the target hosts.** Ubuntu-targeting roles declare exactly `noble` and
`resolute`; Proxmox-targeting roles declare Debian `trixie`; each is tested on its own OS. `resolute`; Proxmox-targeting roles declare Debian `trixie`; each is tested on its own OS.
*Why:* testing on hosts a role never runs on proves nothing. *Held:* review. *Why:* testing on hosts a role never runs on proves nothing. *Held:* review.
@@ -96,12 +95,16 @@ names a check that does not exist yet and its backlog issue.
- **Negative tests.** Every validation has one in `verify.yml` (or a file it includes): - **Negative tests.** Every validation has one in `verify.yml` (or a file it includes):
block/rescue/assert matching the expected error message, run last or failing before any block/rescue/assert matching the expected error message, run last or failing before any
change. *Why:* a bare "it failed" passes for the wrong error. *Held:* review. change. *Why:* a bare "it failed" passes for the wrong error. *Held:* review.
- **Check mode.** Every scenario runs `check` before and after converge. The only guards are - **Check mode.** Every scenario runs `check` before and after converge. Guards:
`check_mode: false` on read-only probes and `when: not ansible_check_mode`; `--check` is the `check_mode: false` on read-only probes, and `when: not ansible_check_mode`, alone or as
supported preview, and the README says a play-level `check_mode: true` is not supported. A role `not ansible_check_mode or <condition>` where the condition shows the task can run (such as a
that cannot support check mode says why in README Notes and drops the step. *Why:* check-mode registered result that is not changed). README: `--check` is the supported preview and a
breakage is a frequent fix, and one guard pattern is reviewable. *Held:* review until every play-level `check_mode: true` is not supported; a role whose `--check` needs its package
scenario's `test_sequence` runs `check` (#134). installed says so in Notes and keeps the step; a role that cannot support check mode at all
says why in Notes and drops the step, which also needs an exception in the test named below.
*Why:* check-mode breakage is a frequent fix, and one guard pattern is reviewable. *Held:*
Molecule for the run passing, `tests/scripts/test_run_molecule_scenarios.py` for the steps
being there; review for the guards.
## Roles calling roles ## Roles calling roles
@@ -122,4 +125,5 @@ names a check that does not exist yet and its backlog issue.
review that each new internal role has it. review that each new internal role has it.
- **`role-name` for internal roles.** An internal role is exempted from ansible-lint `role-name` - **`role-name` for internal roles.** An internal role is exempted from ansible-lint `role-name`
by its own line in `.ansible-lint-ignore`. *Why:* a misnamed public role must still fail. by its own line in `.ansible-lint-ignore`. *Why:* a misnamed public role must still fail.
*Held:* review; until #138 replaces it, `.ansible-lint` skips `role-name` repository-wide. *Held:* control, ansible-lint `role-name` in the Lint job; review that each new internal role
has its line.
+9 -4
View File
@@ -9,6 +9,9 @@ calling role does the download and the verification (a checksum, a signature, a
each upstream differs) and stages the verified file next to the live binary before it includes each upstream differs) and stages the verified file next to the live binary before it includes
this role, so a slow or failed download never stops the service. this role, so a slow or failed download never stops the service.
It covers Ubuntu only: only the Collection's Ubuntu-targeting roles call it, so it does not
cover Debian trixie.
Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml),
which is the source of truth. which is the source of truth.
@@ -63,11 +66,13 @@ itself always stops and starts the service.
## Testing ## Testing
Two molecule scenarios run on Ubuntu 24.04 (noble) against stub binaries (shell scripts) under Two molecule scenarios run in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and
a stub unit, with no network: `default` covers a successful bump, its idempotence, a binary `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). They run against stub binaries (shell scripts) under a
that cannot start, a binary that reports another version (both rolled back), a run with nothing stub unit, with no network: `default` covers a successful bump, its idempotence, a binary that
cannot start, a binary that reports another version (both rolled back), a run with nothing
staged (the service is not stopped), a direct call from a play (refused) and a first install staged (the service is not stopped), a direct call from a play (refused) and a first install
with nothing to back up. `check_mode` runs the bump under `--check` against a stopped service with nothing to back up, and runs `check` before the converge (on a fresh host) and after it
(on the configured host). `check_mode` runs the bump under `--check` against a stopped service
and checks that nothing changed. The calling roles' own scenarios cover a real upstream binary. and checks that nothing changed. The calling roles' own scenarios cover a real upstream binary.
Idempotent: yes. Idempotent: yes.
+1
View File
@@ -11,6 +11,7 @@ galaxy_info:
- name: Ubuntu - name: Ubuntu
versions: versions:
- noble - noble
- resolute
galaxy_tags: galaxy_tags:
- systemd - systemd
- update - update
@@ -1,8 +1,9 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). Needs no network: the "binaries" # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# are stub shell scripts written by ../resources/prepare.yml, run by a stub systemd unit. The # .gitea/workflows/molecule.yml. Needs no network: the "binaries" are stub shell scripts written by
# test caller role lives in ../resources/roles, because the role refuses a call from a play. # ../resources/prepare.yml, run by a stub systemd unit. The test caller role lives in
# ../resources/roles, because the role refuses a call from a play.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -21,6 +22,21 @@ platforms:
- /run/lock - /run/lock
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-binary-update-check-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
env: env:
@@ -1,8 +1,9 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). Needs no network: the "binaries" # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# are stub shell scripts written by ../resources/prepare.yml, run by a stub systemd unit. The # .gitea/workflows/molecule.yml. Needs no network: the "binaries" are stub shell scripts written by
# test caller role lives in ../resources/roles, because the role refuses a call from a play. # ../resources/prepare.yml, run by a stub systemd unit. The test caller role lives in
# ../resources/roles, because the role refuses a call from a play.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -21,6 +22,21 @@ platforms:
- /run/lock - /run/lock
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-binary-update-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
env: env:
@@ -30,13 +46,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
+3 -2
View File
@@ -4,7 +4,7 @@ Installs cloudflared as a systemd service for a locally managed Cloudflare Tunne
## Supported platforms ## Supported platforms
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. The role downloads the `cloudflared-linux-amd64` binary only, so other architectures are unsupported, and it needs `systemd`. The tasks that call the Cloudflare API run on the controller (`delegate_to: localhost`) and need the `community.general` collection (`cloudflare_dns`) there; the `mint` entry point also needs the `openssl` command on the controller. The target needs outbound access to github.com and to Cloudflare's edge; the role defines no firewall rules because the daemon only connects outbound. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The role downloads the `cloudflared-linux-amd64` binary only, so other architectures are unsupported, and it needs `systemd`. The tasks that call the Cloudflare API run on the controller (`delegate_to: localhost`) and need the `community.general` collection (`cloudflare_dns`) there; the `mint` entry point also needs the `openssl` command on the controller. The target needs outbound access to github.com and to Cloudflare's edge; the role defines no firewall rules because the daemon only connects outbound.
The role targets Ubuntu hosts that run the tunnel daemon, not Proxmox nodes, so it does not cover Debian trixie. The role targets Ubuntu hosts that run the tunnel daemon, not Proxmox nodes, so it does not cover Debian trixie.
@@ -106,7 +106,7 @@ Remove with `-e "cloudflared_remove=true cloudflared_remove_data=true"`; only `c
## Tests ## Tests
The `default` molecule scenario runs on one platform, Ubuntu 24.04 (noble) (`${MOLECULE_IMAGE}`), without Cloudflare: a stub cloudflared binary stands in for the daemon, the downloads come from local `file://` URLs, and a stub of the Cloudflare API on the controller's loopback (`molecule/default/files/cloudflare_api_stub.py`, reached through `cloudflared_api_base_url`) answers the tunnel, zone and DNS record calls. It covers the converge with `cloudflared_manage_dns` false and an update through `_binary_update` (and its idempotence), the rendered `config.yml`, credentials file and unit, a stale credentials file, a failed checksum that leaves the daemon running, the input asserts, the deleted-tunnel and DNS guards, the `mint` entry point (confirm guard, CI refusal, no-op, check mode and a mint against the stub, run as child processes) and the remove path. The `community.general.cloudflare_dns` calls, which cannot be pointed at the stub, are not covered: creating, pruning and deleting records. The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It runs without Cloudflare: a stub cloudflared binary stands in for the daemon, the downloads come from local `file://` URLs, and a stub of the Cloudflare API on the controller's loopback (`molecule/default/files/cloudflare_api_stub.py`, reached through `cloudflared_api_base_url`) answers the tunnel, zone and DNS record calls. It covers the converge with `cloudflared_manage_dns` false and an update through `_binary_update` (and its idempotence), the rendered `config.yml`, credentials file and unit, a stale credentials file, a failed checksum that leaves the daemon running, the input asserts, the deleted-tunnel and DNS guards, the `mint` entry point (confirm guard, CI refusal, no-op, check mode and a mint against the stub, run as child processes) and the remove path. The `community.general.cloudflare_dns` calls, which cannot be pointed at the stub, are not covered: creating, pruning and deleting records. It runs `check` before the converge (a fresh host) and after it (a configured host).
## Notes ## Notes
@@ -120,3 +120,4 @@ The `default` molecule scenario runs on one platform, Ubuntu 24.04 (noble) (`${M
- The `Restart cloudflared` handler runs when `config.yml` or the credentials file changes. cloudflared's own ingress check (`ingress validate`) runs after `config.yml` is written. - The `Restart cloudflared` handler runs when `config.yml` or the credentials file changes. cloudflared's own ingress check (`ingress validate`) runs after `config.yml` is written.
- Update: the version is compared as `YYYY.M.P` against `cloudflared --version`. The new binary is downloaded and checksum-verified into `cloudflared.new` before the service is stopped, so a failed download leaves it running; a configured hash that equals the installed binary's is refused with a message, since it means the hash was not bumped with the version. A binary that reports no version is replaced too. - Update: the version is compared as `YYYY.M.P` against `cloudflared --version`. The new binary is downloaded and checksum-verified into `cloudflared.new` before the service is stopped, so a failed download leaves it running; a configured hash that equals the installed binary's is refused with a message, since it means the hash was not bumped with the version. A binary that reports no version is replaced too.
- The play fails when `cloudflared` is not `active` after start. - The play fails when `cloudflared` is not `active` after start.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. Under `--check`, the config directory task is skipped when the `cloudflared` group or user is new. When the systemd unit is new or would change, the start, the running check, the `Restart cloudflared` handler and the update swap are skipped.
+2
View File
@@ -4,3 +4,5 @@
ansible.builtin.systemd: ansible.builtin.systemd:
name: cloudflared name: cloudflared
state: restarted state: restarted
# Under --check a new unit is only simulated, so systemd would not find it.
when: not ansible_check_mode or __cloudflared_unit_file | default({}) is not changed
+1
View File
@@ -10,6 +10,7 @@ galaxy_info:
- name: Ubuntu - name: Ubuntu
versions: versions:
- noble - noble
- resolute
galaxy_tags: galaxy_tags:
- cloudflared - cloudflared
- cloudflare - cloudflare
@@ -1,12 +1,12 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). No Cloudflare and no real # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# cloudflared: prepare.yml starts a stub of the Cloudflare API on the controller's loopback # .gitea/workflows/molecule.yml. No Cloudflare and no real cloudflared: prepare.yml starts a stub of
# (files/cloudflare_api_stub.py, reached through cloudflared_api_base_url; cleanup.yml stops it) # the Cloudflare API on the controller's loopback (files/cloudflare_api_stub.py, reached through
# and seeds a stub cloudflared binary that reports an older version, so the update downloads its # cloudflared_api_base_url; cleanup.yml stops it) and seeds a stub cloudflared binary that reports
# new stub from local file:// URLs. The scenario downloads nothing. cloudflared_manage_dns is # an older version, so the update downloads its new stub from local file:// URLs. The scenario
# false here because community.general.cloudflare_dns cannot be pointed at the stub; the DNS # downloads nothing. cloudflared_manage_dns is false here because community.general.cloudflare_dns
# guards in front of it are run with it true in verify.yml. # cannot be pointed at the stub; the DNS guards in front of it are run with it true in verify.yml.
# The container runs systemd as PID 1 with a writable cgroup; no privileged mode. # The container runs systemd as PID 1 with a writable cgroup; no privileged mode.
driver: driver:
name: docker name: docker
@@ -26,6 +26,21 @@ platforms:
- /run/lock - /run/lock
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-cloudflared-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
# One source for every play, so a verify play that runs the role again renders the same # One source for every play, so a verify play that runs the role again renders the same
@@ -75,13 +90,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
+7 -1
View File
@@ -281,6 +281,7 @@
owner: root owner: root
group: root group: root
mode: "0644" mode: "0644"
register: __cloudflared_unit_file
- name: Reload systemd daemon - name: Reload systemd daemon
ansible.builtin.systemd: ansible.builtin.systemd:
@@ -291,6 +292,8 @@
name: cloudflared name: cloudflared
enabled: true enabled: true
state: started state: started
# Under --check a new unit is only simulated, so systemd would not find it.
when: not ansible_check_mode or __cloudflared_unit_file is not changed
- name: Check cloudflared service status - name: Check cloudflared service status
ansible.builtin.systemd: ansible.builtin.systemd:
@@ -301,5 +304,8 @@
- name: Fail if cloudflared service is not running - name: Fail if cloudflared service is not running
ansible.builtin.fail: ansible.builtin.fail:
msg: "cloudflared service is not running" msg: "cloudflared service is not running"
when: __cloudflared_service_status.status.ActiveState != "active" when:
- __cloudflared_service_status.status.ActiveState != "active"
# The start above is skipped under --check for a new unit.
- not ansible_check_mode or __cloudflared_unit_file | default({}) is not changed
tags: [cloudflared, configure, health] tags: [cloudflared, configure, health]
+4
View File
@@ -4,6 +4,7 @@
ansible.builtin.group: ansible.builtin.group:
name: "{{ cloudflared_group }}" name: "{{ cloudflared_group }}"
system: true system: true
register: __cloudflared_group_account
tags: [cloudflared, prereqs, always] tags: [cloudflared, prereqs, always]
- name: Create cloudflared user - name: Create cloudflared user
@@ -15,6 +16,7 @@
comment: "Cloudflare Tunnel daemon" comment: "Cloudflare Tunnel daemon"
system: true system: true
create_home: false create_home: false
register: __cloudflared_user_account
tags: [cloudflared, prereqs, always] tags: [cloudflared, prereqs, always]
- name: Create cloudflared config directory - name: Create cloudflared config directory
@@ -25,6 +27,8 @@
owner: "{{ cloudflared_user }}" owner: "{{ cloudflared_user }}"
group: "{{ cloudflared_group }}" group: "{{ cloudflared_group }}"
mode: "0750" mode: "0750"
# Under --check a new account is only simulated, so an existing directory cannot be chowned to it.
when: not ansible_check_mode or (__cloudflared_group_account is not changed and __cloudflared_user_account is not changed)
tags: [cloudflared, prereqs, always] tags: [cloudflared, prereqs, always]
- name: Check if cloudflared binary exists - name: Check if cloudflared binary exists
+3 -1
View File
@@ -80,7 +80,8 @@
cloudflared was not stopped and still runs {{ __cloudflared_installed_version }}. cloudflared was not stopped and still runs {{ __cloudflared_installed_version }}.
tags: [cloudflared, update] tags: [cloudflared, update]
# An include does not pass its tags on to the included tasks, hence apply. # An include does not pass its tags on to the included tasks, hence apply. Under --check a
# new unit is only simulated, so the stop and start of the swap would not find it.
- name: Swap in the staged cloudflared binary - name: Swap in the staged cloudflared binary
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino._binary_update name: mortis.kamino._binary_update
@@ -93,6 +94,7 @@
_binary_update_version_command: ["{{ cloudflared_install_dir }}/cloudflared", --version] _binary_update_version_command: ["{{ cloudflared_install_dir }}/cloudflared", --version]
_binary_update_expected_version: "{{ cloudflared_version }}" _binary_update_expected_version: "{{ cloudflared_version }}"
_binary_update_version_regex: '([0-9]{4}\.[0-9]+\.[0-9]+)' _binary_update_version_regex: '([0-9]{4}\.[0-9]+\.[0-9]+)'
when: not ansible_check_mode or __cloudflared_unit_file | default({}) is not changed
tags: [cloudflared, update] tags: [cloudflared, update]
always: always:
+3 -4
View File
@@ -4,9 +4,7 @@ Installs Docker Engine from the upstream Docker APT repository, optionally updat
## Supported platforms ## Supported platforms
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. The key and repository URLs point at `download.docker.com/linux/ubuntu`, and the source line uses `ansible_distribution_release`. The apt architecture is derived from the host (`x86_64` gives `amd64`, `aarch64` gives `arm64`); any other architecture fails the play until `docker_apt_arch` is set. A limited molecule scenario covers the role's own logic (see [Tests](#tests)); the real Docker Engine is not tested. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The key and repository URLs point at `download.docker.com/linux/ubuntu`, and the source line uses `ansible_distribution_release`. The apt architecture is derived from the host (`x86_64` gives `amd64`, `aarch64` gives `arm64`); any other architecture fails the play until `docker_apt_arch` is set. A limited molecule scenario covers the role's own logic (see [Tests](#tests)); the real Docker Engine is not tested.
Untested platforms: Ubuntu releases other than 24.04; `meta/main.yml` declares Ubuntu `all`.
The role targets Ubuntu hosts only: it installs from Docker's Ubuntu repository, so it does not cover Debian trixie (Proxmox hosts). The role targets Ubuntu hosts only: it installs from Docker's Ubuntu repository, so it does not cover Debian trixie (Proxmox hosts).
@@ -88,7 +86,7 @@ With any of `docker_daemon_options`, `docker_live_restore`, `docker_log_driver`,
## Tests ## Tests
`molecule/default` runs in CI only (`.gitea/workflows/molecule.yml`, no local runner), on one platform: Ubuntu 24.04 (noble), the `molecule-ubuntu2404` test container (`${MOLECULE_IMAGE}`). A real Docker Engine cannot run there: `dockerd` needs the bridge, iptables rules and a delegated cgroup, and the container has no privileged mode. So the scenario builds a local APT repository, signs it with a throwaway key, and points the role at it with `docker_gpg_url` and `docker_repo_base_url`. The repository holds empty stand-ins for `docker-ce`, `docker-ce-cli` and `containerd.io`. The stand-in `docker-ce` ships a stub `docker.service` (`sleep infinity`) and creates the `docker` group, as the real package does. `molecule/default` runs in CI only (`.gitea/workflows/molecule.yml`, no local runner), on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). A real Docker Engine cannot run there: `dockerd` needs the bridge, iptables rules and a delegated cgroup, and the container has no privileged mode. So the scenario builds a local APT repository, signs it with a throwaway key, and points the role at it with `docker_gpg_url` and `docker_repo_base_url`. The repository holds empty stand-ins for `docker-ce`, `docker-ce-cli` and `containerd.io`. The stand-in `docker-ce` ships a stub `docker.service` (`sleep infinity`) and creates the `docker` group, as the real package does. It runs `check` before the converge (on a fresh host) and after it (on the configured host).
What it shows, with the role's tasks running unchanged: What it shows, with the role's tasks running unchanged:
@@ -106,6 +104,7 @@ What it does not show: what the units do at a real boot or shutdown (the contain
## Notes ## Notes
- Idempotent: yes. - Idempotent: yes.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. On a host where the Docker source line is not written yet, the package install, the service start, adding `docker_users` to `docker_group` and the `docker_update` tasks are skipped under `--check`, because the repository they need is only simulated.
- `docker_remove` is checked first: when true, only `remove.yml` runs. - `docker_remove` is checked first: when true, only `remove.yml` runs.
- Removal with `docker_remove_data` is destructive. It deletes `/var/lib/docker`. - Removal with `docker_remove_data` is destructive. It deletes `/var/lib/docker`.
- The update task resolves each package's candidate with `apt-cache policy` and fails if a package has none. It installs `package=version`, never `latest`. - The update task resolves each package's candidate with `apt-cache policy` and fails if a package has none. It installs `package=version`, never `latest`.
+2 -1
View File
@@ -9,7 +9,8 @@ galaxy_info:
platforms: platforms:
- name: Ubuntu - name: Ubuntu
versions: versions:
- all - noble
- resolute
galaxy_tags: galaxy_tags:
- docker - docker
- containers - containers
+26 -5
View File
@@ -1,9 +1,10 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). No privileged mode: systemd needs a # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# writable cgroup, nothing else. NET_ADMIN is kept so the platform matches the other scenarios; # .gitea/workflows/molecule.yml. No privileged mode: systemd needs a writable cgroup, nothing else.
# this role does not need it, because the Docker Engine is a stand-in package and no daemon, # NET_ADMIN is kept so the platform matches the other scenarios; this role does not need it,
# bridge or iptables rule is created. # because the Docker Engine is a stand-in package and no daemon, bridge or iptables rule is
# created.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -24,6 +25,23 @@ platforms:
- NET_ADMIN - NET_ADMIN
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-docker-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
capabilities:
- NET_ADMIN
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
verifier: verifier:
@@ -31,13 +49,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
@@ -12,6 +12,12 @@
docker_molecule_repo: /srv/docker-stub-repo docker_molecule_repo: /srv/docker-stub-repo
docker_molecule_work: /var/tmp/docker-stub-work docker_molecule_work: /var/tmp/docker-stub-work
tasks: tasks:
# The image ships without apt lists, and --check does not refresh them, so the fresh-host
# check finds the packages the role installs.
- name: Refresh the apt cache
ansible.builtin.apt:
update_cache: true
- name: Copy the repository builder - name: Copy the repository builder
ansible.builtin.copy: ansible.builtin.copy:
src: build-stub-repo.sh src: build-stub-repo.sh
+6
View File
@@ -32,6 +32,7 @@
content: | content: |
deb [arch={{ __docker_apt_arch }} signed-by={{ docker_keyring_path }}] {{ docker_repo_base_url }} {{ ansible_distribution_release }} stable deb [arch={{ __docker_apt_arch }} signed-by={{ docker_keyring_path }}] {{ docker_repo_base_url }} {{ ansible_distribution_release }} stable
mode: "0644" mode: "0644"
register: __docker_apt_source
tags: [docker, install] tags: [docker, install]
- name: Install Docker Engine packages - name: Install Docker Engine packages
@@ -40,7 +41,10 @@
name: "{{ docker_packages }}" name: "{{ docker_packages }}"
state: present state: present
update_cache: true update_cache: true
register: __docker_packages
notify: Restart docker notify: Restart docker
# Under --check a new source line is only simulated, so apt would find no Docker package.
when: not ansible_check_mode or __docker_apt_source is not changed
tags: [docker, install] tags: [docker, install]
- name: Enable and start Docker service - name: Enable and start Docker service
@@ -49,4 +53,6 @@
name: "{{ docker_service }}" name: "{{ docker_service }}"
enabled: true enabled: true
state: started state: started
# Under --check on a host without the packages there is no unit to start yet.
when: not ansible_check_mode or (__docker_apt_source is not changed and __docker_packages is not changed)
tags: [docker, install] tags: [docker, install]
+6 -1
View File
@@ -24,6 +24,8 @@
when: when:
- not (docker_remove | default(false) | bool) - not (docker_remove | default(false) | bool)
- docker_update | bool - docker_update | bool
# Under --check a new source line is only simulated, so no package would have a candidate.
- not ansible_check_mode or __docker_apt_source | default({}) is not changed
tags: [docker, update] tags: [docker, update]
- name: Add configured users to the docker group - name: Add configured users to the docker group
@@ -33,7 +35,10 @@
groups: "{{ docker_group }}" groups: "{{ docker_group }}"
append: true append: true
loop: "{{ docker_users }}" loop: "{{ docker_users }}"
when: not (docker_remove | default(false) | bool) when:
- not (docker_remove | default(false) | bool)
# Under --check on a host without the packages the group does not exist yet.
- not ansible_check_mode or (__docker_apt_source | default({}) is not changed and __docker_packages | default({}) is not changed)
tags: [docker, configure] tags: [docker, configure]
- name: Install or remove the boot and shutdown units - name: Install or remove the boot and shutdown units
+3 -2
View File
@@ -4,7 +4,7 @@ Installs Fail2Ban, writes `/etc/fail2ban/jail.local` from `fail2ban_jails`, ensu
## Supported platforms ## Supported platforms
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. The default `sshd` jail reads the systemd journal because sshd logs there on that release. The role installs `python3-systemd`, which `backend = systemd` jails need. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The default `sshd` jail reads the systemd journal because sshd logs there on those releases. The role installs `python3-systemd`, which `backend = systemd` jails need.
Ubuntu hosts only: the role targets the Ubuntu guests whose `system_baseline` profiles install `fail2ban`; Proxmox hosts are not targeted. Ubuntu hosts only: the role targets the Ubuntu guests whose `system_baseline` profiles install `fail2ban`; Proxmox hosts are not targeted.
@@ -82,7 +82,7 @@ Main entry point: `fail2ban` (everything), `fail2ban_install`, `fail2ban_validat
## Tests ## Tests
The scenario `molecule/default/` runs in CI only, on one platform: `${MOLECULE_IMAGE}`, an Ubuntu 24.04 (noble) container. The sequence runs prepare, converge, idempotence, side effect and verify; it has no check-mode step. The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It runs `check` before the converge (a fresh host, where the image already has fail2ban installed) and after it (a configured host).
- Converge applies the main entry point with an extra `fail2ban_ignoreip` network and calls `service_jail` twice, one jail with a `logpath` and one with a `journalmatch`. - Converge applies the main entry point with an extra `fail2ban_ignoreip` network and calls `service_jail` twice, one jail with a `logpath` and one with a `journalmatch`.
- Converge also runs inputs that must be refused: a service filter without `failregex`, and a `fail2ban_ignoreip` entry with whitespace, a plain string instead of a list, and an entry starting with `;`. The `fail2ban_ignoreip` refusals are matched on their message. - Converge also runs inputs that must be refused: a service filter without `failregex`, and a `fail2ban_ignoreip` entry with whitespace, a plain string instead of a list, and an entry starting with `;`. The `fail2ban_ignoreip` refusals are matched on their message.
@@ -94,6 +94,7 @@ Not covered: no failure is sent through a jail, so a ban triggered by `failregex
## Notes ## Notes
- Idempotent: yes. - Idempotent: yes.
- Check mode: `--check` previews a host where fail2ban is already installed; a play-level `check_mode: true` is not supported. On a host without fail2ban it fails at the configuration and service tasks: the package is not installed under `--check`, so `/etc/fail2ban`, `fail2ban-client` and the unit are missing.
- `fail2ban_ignoreip` lives in the `[DEFAULT]` section of `jail.local`, so it also applies to the jails that `service_jail` writes to `jail.d`. The exemption only exists once the main entry point has written `jail.local` on that host: `service_jail` does not read `fail2ban_ignoreip`, so a host that uses only `service_jail` has none. - `fail2ban_ignoreip` lives in the `[DEFAULT]` section of `jail.local`, so it also applies to the jails that `service_jail` writes to `jail.d`. The exemption only exists once the main entry point has written `jail.local` on that host: `service_jail` does not read `fail2ban_ignoreip`, so a host that uses only `service_jail` has none.
- `fail2ban_ignoreip` replaces an `ignoreip` set in `jail.conf` or `jail.d/*.conf`, which Fail2Ban reads before `jail.local`; a `jail.d/*.local` file is read after it and can still override it for one jail. Entries must not contain whitespace, `;` or `%` (a `;` after whitespace starts a comment in Fail2Ban's config files and a `%` is interpolation syntax). - `fail2ban_ignoreip` replaces an `ignoreip` set in `jail.conf` or `jail.d/*.conf`, which Fail2Ban reads before `jail.local`; a `jail.d/*.local` file is read after it and can still override it for one jail. Entries must not contain whitespace, `;` or `%` (a `;` after whitespace starts a comment in Fail2Ban's config files and a `%` is interpolation syntax).
- Prefer IP addresses and CIDR networks in `fail2ban_ignoreip`. Fail2Ban resolves a hostname when the jail starts, and a failed lookup leaves that entry ineffective with only a log warning. The validation of `fail2ban_ignoreip` runs under the `fail2ban_validate` tag, so `--tags fail2ban_configure` skips it. - Prefer IP addresses and CIDR networks in `fail2ban_ignoreip`. Fail2Ban resolves a hostname when the jail starts, and a failed lookup leaves that entry ineffective with only a log warning. The validation of `fail2ban_ignoreip` runs under the `fail2ban_validate` tag, so `--tags fail2ban_configure` skips it.
+1
View File
@@ -10,6 +10,7 @@ galaxy_info:
- name: Ubuntu - name: Ubuntu
versions: versions:
- noble - noble
- resolute
galaxy_tags: galaxy_tags:
- fail2ban - fail2ban
- security - security
+24 -3
View File
@@ -1,7 +1,8 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). No privileged mode: systemd needs a # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# writable cgroup and the firewall tools need NET_ADMIN, nothing else. # .gitea/workflows/molecule.yml. No privileged mode: systemd needs a writable cgroup and the
# firewall tools need NET_ADMIN, nothing else.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -22,6 +23,23 @@ platforms:
- NET_ADMIN - NET_ADMIN
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-fail2ban-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
capabilities:
- NET_ADMIN
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
verifier: verifier:
@@ -29,13 +47,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
+4 -3
View File
@@ -4,7 +4,7 @@ Installs the Gitea git service as a systemd-managed binary with a GPG-verified d
## Supported platforms ## Supported platforms
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. The role uses `ansible.builtin.apt`, so Debian-family hosts only, and needs outbound access to dl.gitea.com for the binary and signature and to `gitea_gpg_key_url` (keys.openpgp.org over HTTPS by default) for the signing key. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The role uses `ansible.builtin.apt`, so Debian-family hosts only, and needs outbound access to dl.gitea.com for the binary and signature and to `gitea_gpg_key_url` (keys.openpgp.org over HTTPS by default) for the signing key.
The role targets Ubuntu hosts that serve Gitea, not Proxmox nodes, so it does not cover Debian trixie. The role targets Ubuntu hosts that serve Gitea, not Proxmox nodes, so it does not cover Debian trixie.
@@ -142,13 +142,13 @@ Update or remove: pass `-e gitea_update=true`, or `-e "gitea_remove=true gitea_r
## Tests ## Tests
The `default` molecule scenario runs on one platform, Ubuntu 24.04 (noble) (`${MOLECULE_IMAGE}`). It never installs Gitea: converge applies nothing and every check is in `verify.yml` (see `molecule/default`). It covers: The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It never installs Gitea: converge applies nothing and every check is in `verify.yml` (see `molecule/default`). It covers:
- The guard and no-op paths of the `mint` entry point: the confirm guard, the CI refusal under each of `GITHUB_ACTIONS`, `GITEA_ACTIONS` and `CI`, the no-op when `gitea_api_token` is set, and an empty token treated as missing under `--check`. All but the confirm guard run as child processes with a controlled environment. - The guard and no-op paths of the `mint` entry point: the confirm guard, the CI refusal under each of `GITHUB_ACTIONS`, `GITEA_ACTIONS` and `CI`, the no-op when `gitea_api_token` is set, and an empty token treated as missing under `--check`. All but the confirm guard run as child processes with a controlled environment.
- The signature check of the download, against local files and throwaway keys: a signature by the pinned key places the binary; a signature by another key, a tampered binary and a key file without the pinned key each fail at the expected task; no download directory is left behind. - The signature check of the download, against local files and throwaway keys: a signature by the pinned key places the binary; a signature by another key, a tampered binary and a key file without the pinned key each fail at the expected task; no download directory is left behind.
- The remove path, against a stub unit and binary: both are deleted, the service is no longer active, only the Gitea ufw rules are removed (the SSH rule and a rule without an owner tag stay), and no config or data directory or `gitea_user` account is created. - The remove path, against a stub unit and binary: both are deleted, the service is no longer active, only the Gitea ufw rules are removed (the SSH rule and a rule without an owner tag stay), and no config or data directory or `gitea_user` account is created.
Not covered: install, configure, the admin user, the SSH-key API calls, the update path, the normal-flow assert on `gitea_api_token` (after the service starts) and a mint that creates a token. Not covered: install, configure, the admin user, the SSH-key API calls, the update path, the normal-flow assert on `gitea_api_token` (after the service starts) and a mint that creates a token. The scenario runs `check` before and after the converge, but its converge applies nothing, so neither check runs the role.
## Notes ## Notes
@@ -162,3 +162,4 @@ Not covered: install, configure, the admin user, the SSH-key API calls, the upda
- The SSH-key API calls go to `gitea_http_addr:gitea_http_port` (wildcard becomes loopback, IPv6 is bracketed), not to `gitea_domain`. - The SSH-key API calls go to `gitea_http_addr:gitea_http_port` (wildcard becomes loopback, IPv6 is bracketed), not to `gitea_domain`.
- Handlers: `Reload Gitea` restarts the service when `app.ini` changes, and `main.yml` flushes handlers at the end so a later failure in the same play does not drop the restart. The `Reload Systemd` handler is defined but no task in the role notifies it. - Handlers: `Reload Gitea` restarts the service when `app.ini` changes, and `main.yml` flushes handlers at the end so a later failure in the same play does not drop the restart. The `Reload Systemd` handler is defined but no task in the role notifies it.
- The play fails when the service is not `active` after start. - The play fails when the service is not `active` after start.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. Under `--check` on a host without the binary, the binary assert and the bash completion tasks are skipped. When the systemd unit is new or would change, the start, the running check, the `Reload Gitea` handler and the update swap are skipped. The check-mode path is not tested.
+2
View File
@@ -9,3 +9,5 @@
ansible.builtin.systemd: ansible.builtin.systemd:
name: gitea name: gitea
state: restarted state: restarted
# Under --check a new unit is only simulated, so systemd would not find it.
when: not ansible_check_mode or __gitea_unit_file | default({}) is not changed
+1
View File
@@ -10,6 +10,7 @@ galaxy_info:
- name: Ubuntu - name: Ubuntu
versions: versions:
- noble - noble
- resolute
galaxy_tags: galaxy_tags:
- gitea - gitea
- git - git
+29 -9
View File
@@ -1,13 +1,13 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). Tests the guard and no-op paths of # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# the role's `mint` entry point, the signature check of the download against local files and # .gitea/workflows/molecule.yml. Tests the guard and no-op paths of the role's `mint` entry point,
# throwaway keys, and the remove path with its ufw rules. Gitea is never installed, so the # the signature check of the download against local files and throwaway keys, and the remove path
# normal-flow assert on gitea_api_token (after the service starts) is not # with its ufw rules. Gitea is never installed, so the normal-flow assert on gitea_api_token (after
# covered. The mint tasks only assert, but the remove-path play at the end of verify.yml needs # the service starts) is not covered. The mint tasks only assert, but the remove-path play at the
# systemd (it stops and disables a stub unit) and ufw (it deletes the Gitea rules), so the # end of verify.yml needs systemd (it stops and disables a stub unit) and ufw (it deletes the Gitea
# container runs systemd as PID 1 with a writable cgroup and NET_ADMIN. No privileged mode. The # rules), so the container runs systemd as PID 1 with a writable cgroup and NET_ADMIN. No
# image has ufw and gnupg preinstalled, so the scenario downloads nothing. # privileged mode. Both images have ufw and gnupg preinstalled, so the scenario downloads nothing.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -28,6 +28,23 @@ platforms:
- NET_ADMIN - NET_ADMIN
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-gitea-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
capabilities:
- NET_ADMIN
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
inventory: inventory:
@@ -40,13 +57,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
+10 -1
View File
@@ -92,6 +92,8 @@
changed_when: false changed_when: false
# Read-only: the script is only generated to be written by the next task, so it must also run in --check. # Read-only: the script is only generated to be written by the next task, so it must also run in --check.
check_mode: false check_mode: false
# Under --check on a fresh host there is no binary to run.
when: not ansible_check_mode or gitea_installed
tags: [gitea, configure] tags: [gitea, configure]
- name: Write bash completion to system directory - name: Write bash completion to system directory
@@ -102,6 +104,7 @@
owner: root owner: root
group: root group: root
mode: "0644" mode: "0644"
when: not ansible_check_mode or gitea_installed
tags: [gitea, configure] tags: [gitea, configure]
- name: Create systemd service file for Gitea - name: Create systemd service file for Gitea
@@ -127,6 +130,7 @@
owner: root owner: root
group: root group: root
mode: "0644" mode: "0644"
register: __gitea_unit_file
tags: [gitea, configure] tags: [gitea, configure]
- name: Reload systemd daemon - name: Reload systemd daemon
@@ -164,6 +168,8 @@
name: gitea name: gitea
enabled: true enabled: true
state: started state: started
# Under --check a new unit is only simulated, so systemd would not find it.
when: not ansible_check_mode or __gitea_unit_file is not changed
tags: [gitea, configure] tags: [gitea, configure]
- name: Check Gitea service status - name: Check Gitea service status
@@ -176,7 +182,10 @@
- name: Fail if Gitea service is not running - name: Fail if Gitea service is not running
ansible.builtin.fail: ansible.builtin.fail:
msg: "Gitea service is not running" msg: "Gitea service is not running"
when: gitea_service_status.status.ActiveState != "active" when:
- gitea_service_status.status.ActiveState != "active"
# The start above is skipped under --check for a new unit.
- not ansible_check_mode or __gitea_unit_file | default({}) is not changed
tags: [gitea, configure, health] tags: [gitea, configure, health]
# The token is minted by the opt-in mint entry point, never here. This sits after the # The token is minted by the opt-in mint entry point, never here. This sits after the
+2
View File
@@ -39,4 +39,6 @@
that: that:
- gitea_binary.stat.exists - gitea_binary.stat.exists
fail_msg: "Gitea binary not found after download" fail_msg: "Gitea binary not found after download"
# Nothing is downloaded under --check.
when: not ansible_check_mode
tags: [gitea, install, health, update] tags: [gitea, install, health, update]
+3 -1
View File
@@ -64,7 +64,8 @@
Gitea was not stopped and still runs {{ gitea_installed_version }}. Gitea was not stopped and still runs {{ gitea_installed_version }}.
tags: [gitea, update] tags: [gitea, update]
# An include does not pass its tags on to the included tasks, hence apply. # An include does not pass its tags on to the included tasks, hence apply. Under --check a
# new unit is only simulated, so the stop and start of the swap would not find it.
- name: Swap in the staged Gitea binary - name: Swap in the staged Gitea binary
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino._binary_update name: mortis.kamino._binary_update
@@ -76,6 +77,7 @@
_binary_update_staged_path: "{{ gitea_staging_dir }}/gitea" _binary_update_staged_path: "{{ gitea_staging_dir }}/gitea"
_binary_update_version_command: ["{{ gitea_install_dir }}/gitea", --version] _binary_update_version_command: ["{{ gitea_install_dir }}/gitea", --version]
_binary_update_expected_version: "{{ gitea_version }}" _binary_update_expected_version: "{{ gitea_version }}"
when: not ansible_check_mode or __gitea_unit_file | default({}) is not changed
tags: [gitea, update] tags: [gitea, update]
always: always:
+3 -2
View File
@@ -4,7 +4,7 @@ Installs a Gitea Actions runner (`gitea-runner`) with Docker as a systemd servic
## Supported platforms ## Supported platforms
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. The role uses `ansible.builtin.apt` and installs `docker.io`, so Debian-family hosts only, and needs outbound access to dl.gitea.com and Docker Hub (the Docker check pulls `ubuntu:24.04`). On an unprivileged LXC host, Docker needs nesting enabled on the container. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The role uses `ansible.builtin.apt` and installs `docker.io`, so Debian-family hosts only, and needs outbound access to dl.gitea.com and Docker Hub (the Docker check pulls `ubuntu:24.04`). On an unprivileged LXC host, Docker needs nesting enabled on the container.
The role targets Ubuntu hosts that run CI jobs, not Proxmox nodes, so it does not cover Debian trixie. The role targets Ubuntu hosts that run CI jobs, not Proxmox nodes, so it does not cover Debian trixie.
@@ -89,7 +89,7 @@ Change the registration scope of a registered runner: set `gitea_runner_registra
## Tests ## Tests
The `default` molecule scenario runs on one platform, Ubuntu 24.04 (noble) (`${MOLECULE_IMAGE}`), without a Gitea server and without Docker: a stub `docker.service`, a stub runner binary and a seeded `.runner` stand in for them, and the downloads come from local `file://` URLs. It covers the converge with the prune timer and an update through `_binary_update` (and its idempotence), the rendered `config.yaml` and unit, the prune gate script, the count prune and the disk check against a stub `docker` CLI, turning the pressure prune off, a failed checksum that leaves the runner running, the input asserts, the CI refusal of a forced re-registration and the mint-before-drop order, and the remove path. Registration, the Docker install and the host packages of the host-executor label are not covered. The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It runs without a Gitea server and without Docker: a stub `docker.service`, a stub runner binary and a seeded `.runner` stand in for them, and the downloads come from local `file://` URLs. It covers the converge with the prune timer and an update through `_binary_update` (and its idempotence), the rendered `config.yaml` and unit, the prune gate script, the count prune and the disk check against a stub `docker` CLI, turning the pressure prune off, a failed checksum that leaves the runner running, the input asserts, the CI refusal of a forced re-registration and the mint-before-drop order, and the remove path. Registration, the Docker install and the host packages of the host-executor label are not covered. It runs `check` before the converge (a fresh host) and after it (a configured host).
## Notes ## Notes
@@ -101,4 +101,5 @@ The `default` molecule scenario runs on one platform, Ubuntu 24.04 (noble) (`${M
- The Docker prune units (`gitea-runner-docker-prune.{service,timer}`) are written only while `gitea_runner_docker_prune_enabled` is true. Setting it back to false leaves them in place: run `systemctl disable --now gitea-runner-docker-prune.timer` by hand. `gitea_runner_remove` deletes them, the pressure units and the prune scripts. A run skipped because a job was running is not retried until the next timer elapse: shorten `gitea_runner_docker_prune_schedule` (e.g. `*-*-* 04:30:00`) if that happens. - The Docker prune units (`gitea-runner-docker-prune.{service,timer}`) are written only while `gitea_runner_docker_prune_enabled` is true. Setting it back to false leaves them in place: run `systemctl disable --now gitea-runner-docker-prune.timer` by hand. `gitea_runner_remove` deletes them, the pressure units and the prune scripts. A run skipped because a job was running is not retried until the next timer elapse: shorten `gitea_runner_docker_prune_schedule` (e.g. `*-*-* 04:30:00`) if that happens.
- The pressure prune (`gitea-runner-docker-prune-pressure.{service,timer}`) runs once per check while usage is above the threshold; it has no low watermark, so usage that stays high needs a smaller count or a larger disk. A threshold set back to `0` stops its timer and removes its units and the disk check script. The age prunes and the count prune both apply: an image either one removes is gone. - The pressure prune (`gitea-runner-docker-prune-pressure.{service,timer}`) runs once per check while usage is above the threshold; it has no low watermark, so usage that stays high needs a smaller count or a larger disk. A threshold set back to `0` stops its timer and removes its units and the disk check script. The age prunes and the count prune both apply: an image either one removes is gone.
- The play fails when `gitea-runner` is not `active` after start. - The play fails when `gitea-runner` is not `active` after start.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. Under `--check`, the work directory ownership task is skipped when the runner group or user is new, and starting Docker when `docker.io` is not installed yet. When the systemd unit is new or would change, the start, the running check, the `Restart Gitea Runner` handler and the update swap are skipped.
- `no_log` covers the token mint, the token fact and the registration command. - `no_log` covers the token mint, the token fact and the registration command.
+2
View File
@@ -4,3 +4,5 @@
ansible.builtin.systemd: ansible.builtin.systemd:
name: gitea-runner name: gitea-runner
state: restarted state: restarted
# Under --check a new unit is only simulated, so systemd would not find it.
when: not ansible_check_mode or __gitea_runner_unit_file | default({}) is not changed
+1
View File
@@ -10,6 +10,7 @@ galaxy_info:
- name: Ubuntu - name: Ubuntu
versions: versions:
- noble - noble
- resolute
galaxy_tags: galaxy_tags:
- gitea - gitea
- actions - actions
@@ -1,9 +1,10 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). No Gitea server and no Docker # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# daemon: prepare.yml seeds a stub docker.service, a stub runner binary that reports an older # .gitea/workflows/molecule.yml. No Gitea server and no Docker daemon: prepare.yml seeds a stub
# version, and a .runner file, so the role skips the Docker install and the registration, and # docker.service, a stub runner binary that reports an older version, and a .runner file, so the
# the update downloads its new stub from local file:// URLs. The scenario downloads nothing. # role skips the Docker install and the registration, and the update downloads its new stub from
# local file:// URLs. The scenario downloads nothing.
# The container runs systemd as PID 1 with a writable cgroup; no privileged mode. # The container runs systemd as PID 1 with a writable cgroup; no privileged mode.
driver: driver:
name: docker name: docker
@@ -23,6 +24,21 @@ platforms:
- /run/lock - /run/lock
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-runner-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
# One source for every play, so a verify play that runs the role again renders the same # One source for every play, so a verify play that runs the role again renders the same
@@ -50,13 +66,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
+11 -1
View File
@@ -17,6 +17,10 @@
owner: "{{ gitea_runner_user }}" owner: "{{ gitea_runner_user }}"
group: "{{ gitea_runner_group }}" group: "{{ gitea_runner_group }}"
recurse: true recurse: true
# Under --check a new account is only simulated, so an existing directory cannot be chowned to it.
when: >-
not ansible_check_mode or
(__gitea_runner_group_account | default({}) is not changed and __gitea_runner_user_account | default({}) is not changed)
tags: [gitea_runner, configure] tags: [gitea_runner, configure]
- name: Check current runner registration file state - name: Check current runner registration file state
@@ -62,6 +66,7 @@
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
register: __gitea_runner_unit_file
tags: [gitea_runner, configure] tags: [gitea_runner, configure]
- name: Reload systemd - name: Reload systemd
@@ -76,6 +81,8 @@
name: gitea-runner name: gitea-runner
enabled: true enabled: true
state: started state: started
# Under --check a new unit is only simulated, so systemd would not find it.
when: not ansible_check_mode or __gitea_runner_unit_file is not changed
tags: [gitea_runner, configure] tags: [gitea_runner, configure]
- name: Check runner service status - name: Check runner service status
@@ -88,5 +95,8 @@
- name: Fail if runner service is not running - name: Fail if runner service is not running
ansible.builtin.fail: ansible.builtin.fail:
msg: "Gitea runner service is not running" msg: "Gitea runner service is not running"
when: gitea_runner_service_status.status.ActiveState != "active" when:
- gitea_runner_service_status.status.ActiveState != "active"
# The start above is skipped under --check for a new unit.
- not ansible_check_mode or __gitea_runner_unit_file | default({}) is not changed
tags: [gitea_runner, configure, health] tags: [gitea_runner, configure, health]
+5
View File
@@ -17,6 +17,7 @@
name: name:
- docker.io - docker.io
state: present state: present
register: __gitea_runner_docker_package
tags: [gitea_runner, docker, install] tags: [gitea_runner, docker, install]
- name: Enable and start Docker - name: Enable and start Docker
@@ -25,6 +26,8 @@
name: docker name: docker
enabled: true enabled: true
state: started state: started
# Under --check a new package is only simulated, so there is no docker unit yet.
when: not ansible_check_mode or __gitea_runner_docker_package is not changed
tags: [gitea_runner, docker, install] tags: [gitea_runner, docker, install]
- name: Add the runner user to the docker group - name: Add the runner user to the docker group
@@ -33,6 +36,8 @@
name: "{{ gitea_runner_user }}" name: "{{ gitea_runner_user }}"
groups: docker groups: docker
append: true append: true
# Under --check a new docker.io creates no docker group, and user fails on a missing group.
when: not ansible_check_mode or __gitea_runner_docker_package is not changed
tags: [gitea_runner, docker, install] tags: [gitea_runner, docker, install]
# Pulls ubuntu:24.04 from Docker Hub. Also proves Docker runs inside a container host # Pulls ubuntu:24.04 from Docker Hub. Also proves Docker runs inside a container host
+2
View File
@@ -6,6 +6,7 @@
ansible.builtin.group: ansible.builtin.group:
name: "{{ gitea_runner_group }}" name: "{{ gitea_runner_group }}"
system: true system: true
register: __gitea_runner_group_account
tags: [gitea_runner, prereqs, always] tags: [gitea_runner, prereqs, always]
- name: Ensure runner user exists - name: Ensure runner user exists
@@ -16,6 +17,7 @@
home: "{{ gitea_runner_home }}" home: "{{ gitea_runner_home }}"
create_home: true create_home: true
system: true system: true
register: __gitea_runner_user_account
tags: [gitea_runner, prereqs, always] tags: [gitea_runner, prereqs, always]
- name: Check if runner is installed - name: Check if runner is installed
+3 -1
View File
@@ -54,7 +54,8 @@
The runner was not stopped and still runs {{ gitea_runner_installed_version }}. The runner was not stopped and still runs {{ gitea_runner_installed_version }}.
tags: [gitea_runner, update] tags: [gitea_runner, update]
# An include does not pass its tags on to the included tasks, hence apply. # An include does not pass its tags on to the included tasks, hence apply. Under --check a
# new unit is only simulated, so the stop and start of the swap would not find it.
- name: Swap in the staged runner binary - name: Swap in the staged runner binary
ansible.builtin.include_role: ansible.builtin.include_role:
name: mortis.kamino._binary_update name: mortis.kamino._binary_update
@@ -66,6 +67,7 @@
_binary_update_staged_path: "{{ gitea_runner_staged_binary }}" _binary_update_staged_path: "{{ gitea_runner_staged_binary }}"
_binary_update_version_command: ["{{ gitea_runner_install_dir }}/gitea-runner", --version] _binary_update_version_command: ["{{ gitea_runner_install_dir }}/gitea-runner", --version]
_binary_update_expected_version: "{{ gitea_runner_version }}" _binary_update_expected_version: "{{ gitea_runner_version }}"
when: not ansible_check_mode or __gitea_runner_unit_file | default({}) is not changed
tags: [gitea_runner, update] tags: [gitea_runner, update]
always: always:
+2 -1
View File
@@ -57,7 +57,7 @@ None. The role does not tag its tasks, so only a play-level tag applies.
## Tests ## Tests
`molecule/default` runs in CI only, on one platform: Ubuntu 24.04 (noble), the `molecule-ubuntu2404` image (`${MOLECULE_IMAGE}`). The image has no `ifupdown2`, and a real reload could cut the container's own network, so the validate command is `/bin/true` and the apply command appends to a marker file; the rest of the role runs unchanged. Prepare seeds `/etc/network/interfaces` with a legacy body, so the converge has a change to make and a backup to take. `molecule/default` runs in CI only, on one platform: Ubuntu 24.04 (noble), the `molecule-ubuntu2404` image (`${MOLECULE_IMAGE}`). The image has no `ifupdown2`, and a real reload could cut the container's own network, so the validate command is `/bin/true` and the apply command appends to a marker file; the rest of the role runs unchanged. Prepare seeds `/etc/network/interfaces` with a legacy body, so the converge has a change to make and a backup to take. The scenario runs `check` before the converge (fresh host) and after it (configured host).
Verify checks: Verify checks:
@@ -76,4 +76,5 @@ It does not test `ifreload`, so no Debian release or `ifupdown2` version is veri
- On change the order is: copy the current file to `network_interfaces_backup`, write the new file (notifies `Reload Interfaces`), run the validate command, flush handlers. Any failure in that block restores the backup and fails with "Invalid network configuration detected. Previous config restored." The restore does not reload the interfaces. - On change the order is: copy the current file to `network_interfaces_backup`, write the new file (notifies `Reload Interfaces`), run the validate command, flush handlers. Any failure in that block restores the backup and fails with "Invalid network configuration detected. Previous config restored." The restore does not reload the interfaces.
- The validate command runs after the file is written, and the reload runs right after it. A configuration that passes validation but breaks connectivity is not detected. - The validate command runs after the file is written, and the reload runs right after it. A configuration that passes validation but breaks connectivity is not detected.
- With `method: static`, `address` and `netmask` are required by the template. - With `method: static`, `address` and `netmask` are required by the template.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. Under `--check` the new file is not written, so the validate command and the reload are skipped; the preview shows whether the file would change, not whether it is valid.
- `no_log` is not used: the role handles no secrets. - `no_log` is not used: the role handles no secrets.
@@ -29,13 +29,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
+2 -4
View File
@@ -4,9 +4,7 @@ Installs [Pi-hole](https://pi-hole.net) v6 by cloning the upstream repository an
## Supported platforms ## Supported platforms
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. The role asserts that the host is Ubuntu before any change. The package dependencies come from `ansible.builtin.apt`. The host needs outbound access to the upstream Pi-hole repository (`repo.remote` in the merged settings) and to the apt mirrors. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The role asserts that the host is Ubuntu before any change. The package dependencies come from `ansible.builtin.apt`. The host needs outbound access to the upstream Pi-hole repository (`repo.remote` in the merged settings) and to the apt mirrors.
Untested platforms: Ubuntu 26.04 (resolute). The apt dependencies exist there, but the scenario does not run on it yet.
The role targets Ubuntu hosts that serve DNS, not Proxmox nodes, so it does not cover Debian trixie: the upstream installer is run on the Ubuntu hosts it is tested on. The role targets Ubuntu hosts that serve DNS, not Proxmox nodes, so it does not cover Debian trixie: the upstream installer is run on the Ubuntu hosts it is tested on.
@@ -60,7 +58,7 @@ The input asserts carry `always` (and `assert`), so they run whatever tags are s
## Tests ## Tests
The `default` molecule scenario runs on noble. It replaces the upstream repository with a local stub whose installer only logs its arguments and creates the database file, so it tests the merge, the asserts, the user, the configuration directory and the rendered `pihole.toml` (owner, group and mode), the clone's checked-out version, the installer sequence (install once, then reconfigure from the handler) and idempotence, not Pi-hole itself: no pihole-FTL service runs, so that the service loaded the configuration is not verified. It runs `check` before the converge (a first-run preview) and after the idempotence run. Negative tests in `verify.yml` cover a host without Ubuntu facts, a missing `pihole_web_password`, an unset interface, empty upstreams, a non-string password and the placeholder password. The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It replaces the upstream repository with a local stub whose installer only logs its arguments and creates the database file, so it tests the merge, the asserts, the user, the configuration directory and the rendered `pihole.toml` (owner, group and mode), the clone's checked-out version, the installer sequence (install once, then reconfigure from the handler) and idempotence, not Pi-hole itself: no pihole-FTL service runs, so that the service loaded the configuration is not verified. It runs `check` before the converge (a fresh host) and after it (a configured host). Negative tests in `verify.yml` cover a host without Ubuntu facts, a missing `pihole_web_password`, an unset interface, empty upstreams, a non-string password and the placeholder password.
## Notes ## Notes
+1
View File
@@ -10,6 +10,7 @@ galaxy_info:
- name: Ubuntu - name: Ubuntu
versions: versions:
- noble - noble
- resolute
galaxy_tags: galaxy_tags:
- pihole - pihole
- dns - dns
+23 -7
View File
@@ -1,9 +1,10 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). Needs outbound network for the apt packages. The upstream # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# Pi-hole repository is replaced by a local stub whose installer only logs its arguments # .gitea/workflows/molecule.yml. Needs outbound network for the apt packages. The upstream Pi-hole
# (prepare.yml), so the scenario tests the role's own logic, not Pi-hole itself. # repository is replaced by a local stub whose installer only logs its arguments (prepare.yml), so
# The containers run systemd as PID 1 with a writable cgroup; no privileged mode. # the scenario tests the role's own logic, not Pi-hole itself. The containers run systemd as PID 1
# with a writable cgroup; no privileged mode.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -22,6 +23,21 @@ platforms:
- /run/lock - /run/lock
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-pihole-resolute
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
# One source for every play, so the converge and the negative tests in verify.yml start from # One source for every play, so the converge and the negative tests in verify.yml start from
@@ -47,7 +63,7 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys (scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys (scripts/run_molecule_scenarios.sh removes the
# containers as soon as this scenario ends; after a local run, run `molecule destroy` yourself), # containers as soon as this scenario ends; after a local run, run `molecule destroy` yourself),
# plus two check steps: one before the converge (first-run preview), one after the idempotence run. # plus a check before the converge (fresh host) and one after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
@@ -56,8 +72,8 @@ scenario:
- prepare - prepare
- check - check
- converge - converge
- idempotence
- check - check
- idempotence
- side_effect - side_effect
- verify - verify
- cleanup - cleanup
+1 -1
View File
@@ -92,7 +92,7 @@ The input validation (`tasks/validate.yml`) carries `always`, so it runs whateve
## Tests ## Tests
The `default` molecule scenario runs in CI on Ubuntu 24.04 (noble), the `molecule-ubuntu2404` image, which stands in for the Proxmox node. The API lifecycle (detect, create, update, resize, start, stop, delete and the restarts) is not exercised: there is no Proxmox API in the scenario. The converge includes the internal task files `main.yml` runs on the node side, in its order (`validate`, `firewall`, `raw_config`), with `pve_lxc_state: stopped`, under which the role never restarts the container. Prepare seeds a container config with stale `lxc.*` lines, blockinfile markers and a snapshot section, and backup copies of two containers' configs. Verify checks the reconciled config byte for byte (Proxmox's lines kept in order, the desired `lxc.*` lines after them, the snapshot section untouched), the rendered firewall file, and that only this container's backups were removed. It runs `check` before the converge and after the idempotence run. Negative tests cover a state outside the spec, missing API credentials and a missing network prefix through `main`, and raw config given as a string, outside the `lxc.` namespace or with two lines in one item, a malformed firewall rule and an unknown policy through `validate`; a run with `pve_lxc_manage_lifecycle: false` checks the presence facts. No Proxmox service runs, so pmxcfs's handling of the files and `pve-firewall` loading the rules are not verified. The `default` molecule scenario runs in CI on Ubuntu 24.04 (noble), the `molecule-ubuntu2404` image, which stands in for the Proxmox node. The API lifecycle (detect, create, update, resize, start, stop, delete and the restarts) is not exercised: there is no Proxmox API in the scenario. The converge includes the internal task files `main.yml` runs on the node side, in its order (`validate`, `firewall`, `raw_config`), with `pve_lxc_state: stopped`, under which the role never restarts the container. Prepare seeds a container config with stale `lxc.*` lines, blockinfile markers and a snapshot section, and backup copies of two containers' configs. Verify checks the reconciled config byte for byte (Proxmox's lines kept in order, the desired `lxc.*` lines after them, the snapshot section untouched), the rendered firewall file, and that only this container's backups were removed. It runs `check` before the converge (a fresh host) and after it (a configured host). Negative tests cover a state outside the spec, missing API credentials and a missing network prefix through `main`, and raw config given as a string, outside the `lxc.` namespace or with two lines in one item, a malformed firewall rule and an unknown policy through `validate`; a run with `pve_lxc_manage_lifecycle: false` checks the presence facts. No Proxmox service runs, so pmxcfs's handling of the files and `pve-firewall` loading the rules are not verified.
## Notes ## Notes
+2 -2
View File
@@ -57,7 +57,7 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys (scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys (scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends; after a local run, run `molecule destroy` yourself), # container as soon as this scenario ends; after a local run, run `molecule destroy` yourself),
# plus two check steps: one before the converge (first-run preview), one after the idempotence run. # plus a check before the converge (fresh host) and one after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
@@ -66,8 +66,8 @@ scenario:
- prepare - prepare
- check - check
- converge - converge
- idempotence
- check - check
- idempotence
- side_effect - side_effect
- verify - verify
- cleanup - cleanup
+4 -3
View File
@@ -4,9 +4,9 @@ Writes a hardened sshd drop-in, selected by a profile, and refuses configuration
## Supported platforms ## Supported platforms
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on.
Untested platforms: Ubuntu 22.04 (jammy) and Debian trixie (Proxmox VE 9 nodes, the `pve` profile), listed in `meta/main.yml` but not converged by a test. Untested platforms: Debian trixie (Proxmox VE 9 nodes, the `pve` profile), listed in `meta/main.yml` but not converged by a test.
The role targets Ubuntu guests (the `ubuntu_lxc` and `ubuntu_vm` profiles) and Proxmox VE nodes (the `pve` profile). The role targets Ubuntu guests (the `ubuntu_lxc` and `ubuntu_vm` profiles) and Proxmox VE nodes (the `pve` profile).
@@ -59,7 +59,7 @@ The role defines none.
## Tests ## Tests
The scenario `molecule/default/`, run by the Collection's CI, runs on one platform: `${MOLECULE_IMAGE}`, an Ubuntu 24.04 (noble) container that ships openssh-server. The sequence runs converge, idempotence and verify; it has no check-mode step. The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). Both images ship openssh-server. It runs `check` before the converge (a fresh host) and after it (a configured host).
- Converge applies the `ubuntu_lxc` profile. It then loads the defaults through `tasks_from: validate.yml` without changing the host: every profile (`pve`, `ubuntu_lxc`, `ubuntu_vm`) passes validation and keeps its root login policy and key algorithms, a consumer `sshd_settings` override wins over the profile, and the `pve` guard accepts each value that allows root key login. - Converge applies the `ubuntu_lxc` profile. It then loads the defaults through `tasks_from: validate.yml` without changing the host: every profile (`pve`, `ubuntu_lxc`, `ubuntu_vm`) passes validation and keeps its root login policy and key algorithms, a consumer `sshd_settings` override wins over the profile, and the `pve` guard accepts each value that allows root key login.
- Verify first checks the refusals: a run without `sshd_profile`, `PubkeyAuthentication no` (lock-out), a `pve` profile with `PermitRootLogin no` or `forced-commands-only`, a `pve` profile without `rsa-sha2-512`, SHA-1 `ssh-rsa`, and an unknown profile. Each but the missing profile is matched on its message. - Verify first checks the refusals: a run without `sshd_profile`, `PubkeyAuthentication no` (lock-out), a `pve` profile with `PermitRootLogin no` or `forced-commands-only`, a `pve` profile without `rsa-sha2-512`, SHA-1 `ssh-rsa`, and an unknown profile. Each but the missing profile is matched on its message.
@@ -71,6 +71,7 @@ Not covered: the `pve` profile is not converged and no SSH login is attempted.
## Notes ## Notes
- Idempotent: yes. - Idempotent: yes.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported.
- `tasks/validate.yml` fails the play for an unknown profile, an empty merged result, `PasswordAuthentication no` without `PubkeyAuthentication yes`, a `pve` profile whose `PermitRootLogin` does not allow root key login (`prohibit-password`, its alias `without-password`, or `yes`; `no` and `forced-commands-only` are refused), a `pve` profile whose `HostKeyAlgorithms` or `PubkeyAcceptedAlgorithms` lacks `rsa-sha2-512` (the `+`/`-`/`^` list forms are not parsed and fail; write the full list), and any profile that lists SHA-1 `ssh-rsa` in either. - `tasks/validate.yml` fails the play for an unknown profile, an empty merged result, `PasswordAuthentication no` without `PubkeyAuthentication yes`, a `pve` profile whose `PermitRootLogin` does not allow root key login (`prohibit-password`, its alias `without-password`, or `yes`; `no` and `forced-commands-only` are refused), a `pve` profile whose `HostKeyAlgorithms` or `PubkeyAcceptedAlgorithms` lacks `rsa-sha2-512` (the `+`/`-`/`^` list forms are not parsed and fail; write the full list), and any profile that lists SHA-1 `ssh-rsa` in either.
- The drop-in is installed with `validate: sshd -t -f %s`. The handler named `Restart SSH` reloads the service, and is skipped in check mode or when `sshd_reload` is false. - The drop-in is installed with `validate: sshd -t -f %s`. The handler named `Restart SSH` reloads the service, and is skipped in check mode or when `sshd_reload` is false.
- `ssh-keygen -A` runs on every play and always reports ok. - `ssh-keygen -A` runs on every play and always reports ok.
+1 -1
View File
@@ -9,8 +9,8 @@ galaxy_info:
platforms: platforms:
- name: Ubuntu - name: Ubuntu
versions: versions:
- jammy
- noble - noble
- resolute
- name: Debian - name: Debian
versions: versions:
- trixie - trixie
+1 -1
View File
@@ -1,5 +1,5 @@
--- ---
# The production profile: Ubuntu 24.04 LXCs. Only the profile name and the user are supplied. # The production profile: Ubuntu LXCs. Only the profile name and the user are supplied.
- name: Converge the role with a valid profile - name: Converge the role with a valid profile
hosts: all hosts: all
vars: vars:
+24 -4
View File
@@ -1,8 +1,8 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml), which ships openssh-server. No # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# privileged mode: systemd needs a writable cgroup; NET_ADMIN keeps the container the same as # .gitea/workflows/molecule.yml; both ship openssh-server. No privileged mode: systemd
# the other role scenarios. # needs a writable cgroup; NET_ADMIN keeps the container the same as the other role scenarios.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -23,6 +23,23 @@ platforms:
- NET_ADMIN - NET_ADMIN
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-sshd-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
capabilities:
- NET_ADMIN
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
verifier: verifier:
@@ -30,13 +47,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
+4 -2
View File
@@ -237,8 +237,10 @@
- name: Root logs in with keys only, passwords stay off - name: Root logs in with keys only, passwords stay off
ansible.builtin.assert: ansible.builtin.assert:
that: that:
# sshd -T prints the first alias in its table for prohibit-password: without-password. # sshd -T prints prohibit-password under one of its names, by OpenSSH version.
- sshd_verify_pve_effective.stdout_lines is contains('permitrootlogin without-password') - >-
'permitrootlogin prohibit-password' in sshd_verify_pve_effective.stdout_lines
or 'permitrootlogin without-password' in sshd_verify_pve_effective.stdout_lines
- sshd_verify_pve_effective.stdout_lines is contains('passwordauthentication no') - sshd_verify_pve_effective.stdout_lines is contains('passwordauthentication no')
- sshd_verify_pve_effective.stdout_lines is contains('pubkeyauthentication yes') - sshd_verify_pve_effective.stdout_lines is contains('pubkeyauthentication yes')
quiet: true quiet: true
+5 -3
View File
@@ -4,9 +4,9 @@ Applies an OS baseline chosen by `system_baseline_system_type`: apt upgrade, pac
## Supported platforms ## Supported platforms
Ubuntu 24.04 (noble) passes the molecule scenario. The tasks use apt and the reboot check is limited to the Debian family. See `meta/main.yml`. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The tasks use apt and the reboot check is limited to the Debian family. See `meta/main.yml`.
Untested platforms: Debian 13 (trixie, Proxmox hosts), not verified by a test; Ubuntu 22.04 (jammy), listed in `meta/main.yml` but neither supported nor tested. Untested platforms: Debian 13 (trixie, Proxmox hosts), listed in `meta/main.yml` but not verified by a test.
The role targets Ubuntu guests (the `ubuntu_lxc` and `ubuntu_vm` profiles) and Proxmox VE hosts on Debian (the `pve` profile). The role targets Ubuntu guests (the `ubuntu_lxc` and `ubuntu_vm` profiles) and Proxmox VE hosts on Debian (the `pve` profile).
@@ -124,7 +124,7 @@ The two task files besides `main` are a supported interface, for a caller that d
## Tests ## Tests
The scenario `molecule/default/` runs in CI only, on one platform: `${MOLECULE_IMAGE}`, an Ubuntu 24.04 (noble) container. It installs packages from the Ubuntu mirrors, so the runner needs outbound network. The sequence runs prepare, converge, idempotence and verify; it has no check-mode step. The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It installs packages from the Ubuntu mirrors, so the runner needs outbound network. It runs `check` before the converge (a fresh host) and after it (a configured host).
- Converge first checks that the role refuses a bad input with its own message before any change: an unknown `system_baseline_system_type`, an unknown `system_baseline_apt_upgrade` (main flow and `update` entry point), a negative reboot throttle or a negative or boolean post-reboot delay (main flow and `reboot` entry point), a line break in `system_baseline_apt_daily_timeout`, and a bad package blacklist (a quote, a null item, a bare string). - Converge first checks that the role refuses a bad input with its own message before any change: an unknown `system_baseline_system_type`, an unknown `system_baseline_apt_upgrade` (main flow and `update` entry point), a negative reboot throttle or a negative or boolean post-reboot delay (main flow and `reboot` entry point), a line break in `system_baseline_apt_daily_timeout`, and a bad package blacklist (a quote, a null item, a bare string).
- Converge then applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`, and only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, asserting the resolved inputs. - Converge then applies the `ubuntu_lxc` profile, with tmux autostart and `system_baseline_apt_daily_timeout: 1h`, and only resolves the `pve` and `ubuntu_vm` profiles and a consumer override, asserting the resolved inputs.
@@ -207,6 +207,8 @@ The upgrade runs over the SSH connection Ansible uses. An `openssh-server` upgra
In a dry run (`--check`) the main flow does not run the apt upgrade: a package that is only waiting for the next patch run, or a package cache older than an hour, is not drift, and the package module reports both as `changed`, so a scheduled dry run would flag every host whenever a package landed in between. The autoremove and autoclean step still runs, and is checked: a leftover package it would remove is reported as `changed`, on purpose. `apt-get autoclean` runs in this step in a real run, in the main flow and in the `update` entry point. The `update` entry point is unchanged: it is an explicit request to update, so in check mode it still previews the upgrade. In a dry run (`--check`) the main flow does not run the apt upgrade: a package that is only waiting for the next patch run, or a package cache older than an hour, is not drift, and the package module reports both as `changed`, so a scheduled dry run would flag every host whenever a package landed in between. The autoremove and autoclean step still runs, and is checked: a leftover package it would remove is reported as `changed`, on purpose. `apt-get autoclean` runs in this step in a real run, in the main flow and in the `update` entry point. The `update` entry point is unchanged: it is an explicit request to update, so in check mode it still previews the upgrade.
`--check` is the supported preview; a play-level `check_mode: true` is not supported.
### Unattended-upgrades origins ### Unattended-upgrades origins
A profile's `unattended_upgrade_origins` list pins the origins unattended-upgrades may install from. apt merges every file in `/etc/apt/apt.conf.d` and appends list entries across files, so a later file that only lists origins would widen the distribution's `50unattended-upgrades`, never narrow it. A non-empty list is therefore written to `/etc/apt/apt.conf.d/90unattended-upgrades-origins`, which sorts after `50unattended-upgrades`, clears `Unattended-Upgrade::Allowed-Origins` and `Unattended-Upgrade::Origins-Pattern` (apt's `#clear` directive) and sets only the listed patterns. The origin lists in `50unattended-upgrades` itself are not edited. An empty or missing list removes the drop-in. A profile's `unattended_upgrade_origins` list pins the origins unattended-upgrades may install from. apt merges every file in `/etc/apt/apt.conf.d` and appends list entries across files, so a later file that only lists origins would widen the distribution's `50unattended-upgrades`, never narrow it. A non-empty list is therefore written to `/etc/apt/apt.conf.d/90unattended-upgrades-origins`, which sorts after `50unattended-upgrades`, clears `Unattended-Upgrade::Allowed-Origins` and `Unattended-Upgrade::Origins-Pattern` (apt's `#clear` directive) and sets only the listed patterns. The origin lists in `50unattended-upgrades` itself are not edited. An empty or missing list removes the drop-in.
+1 -1
View File
@@ -9,8 +9,8 @@ galaxy_info:
platforms: platforms:
- name: Ubuntu - name: Ubuntu
versions: versions:
- jammy
- noble - noble
- resolute
- name: Debian - name: Debian
versions: versions:
- trixie - trixie
@@ -1,10 +1,10 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). Unlike the other scenarios # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# this one installs packages (the role's system_baseline_essential_packages list) from the Ubuntu # .gitea/workflows/molecule.yml. Unlike the other scenarios this one installs packages (the
# mirrors during prepare and converge, so the runner needs outbound network. No # role's system_baseline_essential_packages list) from the Ubuntu mirrors during prepare and
# privileged mode: systemd needs a writable cgroup and the firewall tools need # converge, so the runner needs outbound network. No privileged mode: systemd needs a writable
# NET_ADMIN, nothing else. # cgroup and the firewall tools need NET_ADMIN, nothing else.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -25,6 +25,23 @@ platforms:
- NET_ADMIN - NET_ADMIN
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-system-baseline-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
capabilities:
- NET_ADMIN
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
options: options:
@@ -36,13 +53,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
+4 -3
View File
@@ -4,9 +4,9 @@ Disables and masks risky services, writes a systemd manager hardening drop-in an
## Supported platforms ## Supported platforms
The molecule scenario passes on Ubuntu 24.04 (noble); see [Tests](#tests). The role is meant for hosts with systemd: Ubuntu 24.04 (noble) LXCs, Ubuntu VMs and Debian 13 (trixie) Proxmox hosts. The role is applied to the three system types in `systemd_hardening_profiles`: `pve` (Proxmox hosts), `ubuntu_lxc` and `ubuntu_vm`. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on; see [Tests](#tests). The role is meant for hosts with systemd: Ubuntu LXCs, Ubuntu VMs and Debian 13 (trixie) Proxmox hosts. The role is applied to the three system types in `systemd_hardening_profiles`: `pve` (Proxmox hosts), `ubuntu_lxc` and `ubuntu_vm`.
Untested platforms: Debian 13 (trixie), and Ubuntu 22.04 (jammy), which is listed in `meta/main.yml` but neither supported nor tested. Untested platforms: Debian 13 (trixie), listed in `meta/main.yml` but not verified by a test.
## Requirements and run order ## Requirements and run order
@@ -52,11 +52,12 @@ Only `always` (the `systemd_hardening_system_type` assert) works as intended. `d
## Tests ## Tests
`molecule/default` runs in CI only, on one platform: Ubuntu 24.04 (noble), the `molecule-ubuntu2404` image (`${MOLECULE_IMAGE}`). It runs the `ubuntu_lxc` profile against stub unit files (a socket and a service for the ones that ship both, a service only and a socket only for the others), because the test image installs none of the services the role disables or masks. It checks that the stub sockets and services end up stopped and disabled or masked, that a listed unit that does not exist is skipped, the manager and service drop-ins (loaded by systemd after the reload) and the refusals: a missing or unknown `systemd_hardening_system_type`, and a `systemd_hardening_services` entry or value that is not a mapping. It cannot show that a real `rpcbind` or similar stops. The `pve` and `ubuntu_vm` profiles and Debian 13 are not verified by a test. `molecule/default` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It runs the `ubuntu_lxc` profile against stub unit files (a socket and a service for the ones that ship both, a service only and a socket only for the others), because the test images install none of the services the role disables or masks. It checks that the stub sockets and services end up stopped and disabled or masked, that a listed unit that does not exist is skipped, the manager and service drop-ins (loaded by systemd after the reload) and the refusals: a missing or unknown `systemd_hardening_system_type`, and a `systemd_hardening_services` entry or value that is not a mapping. It runs `check` before the converge (fresh host) and after it (configured host). It cannot show that a real `rpcbind` or similar stops. The `pve` and `ubuntu_vm` profiles and Debian 13 are not verified by a test.
## Notes ## Notes
- Idempotent: yes. - Idempotent: yes.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported.
- Every name in `systemd_hardening_disable_services` and `systemd_hardening_mask_services` is looked up as a socket and as a service, with or without the `.service` or `.socket` suffix. Only units that systemd has a unit file for (`LoadState` is not `not-found`) are disabled or masked, the socket first: a stopped service whose socket still listens is started again by the next connection. A name with only a service, only a socket, or neither is fine. The role asks about the listed units only, with one `systemctl show`, and does not list every unit file. A template name such as `[email protected]` is not supported: that call fails. - Every name in `systemd_hardening_disable_services` and `systemd_hardening_mask_services` is looked up as a socket and as a service, with or without the `.service` or `.socket` suffix. Only units that systemd has a unit file for (`LoadState` is not `not-found`) are disabled or masked, the socket first: a stopped service whose socket still listens is started again by the next connection. A name with only a service, only a socket, or neither is fine. The role asks about the listed units only, with one `systemctl show`, and does not list every unit file. A template name such as `[email protected]` is not supported: that call fails.
- `systemctl disable` does nothing for a static unit (one with no `[Install]` section), so the systemd module can report `changed` on every run for it; list only names whose units can be enabled, and note that this now applies to a listed name's socket as well. - `systemctl disable` does nothing for a static unit (one with no `[Install]` section), so the systemd module can report `changed` on every run for it; list only names whose units can be enabled, and note that this now applies to a listed name's socket as well.
- The manager drop-in (`DefaultLimitNOFILE`, `DefaultLimitNPROC`, `DefaultLimitCORE`, and task, memory and CPU accounting) is written verbatim by `tasks/harden_manager.yml` and has no variable. - The manager drop-in (`DefaultLimitNOFILE`, `DefaultLimitNPROC`, `DefaultLimitCORE`, and task, memory and CPU accounting) is written verbatim by `tasks/harden_manager.yml` and has no variable.
+1 -1
View File
@@ -9,8 +9,8 @@ galaxy_info:
platforms: platforms:
- name: Ubuntu - name: Ubuntu
versions: versions:
- jammy
- noble - noble
- resolute
- name: Debian - name: Debian
versions: versions:
- trixie - trixie
@@ -1,7 +1,8 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). No privileged mode: systemd needs a # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# writable cgroup and the firewall tools need NET_ADMIN, nothing else. # .gitea/workflows/molecule.yml. No privileged mode: systemd needs a writable cgroup and the
# firewall tools need NET_ADMIN, nothing else.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -22,6 +23,23 @@ platforms:
- NET_ADMIN - NET_ADMIN
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-systemd-hardening-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
capabilities:
- NET_ADMIN
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
verifier: verifier:
@@ -29,13 +47,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
+73
View File
@@ -0,0 +1,73 @@
# tailscale
Installs [Tailscale](https://tailscale.com) from the upstream APT repository with the keyring pinned by sha256, sets the `tailscaled` flags, enables `tailscaled` and brings the node onto the tailnet with an auth key. It can also update to the APT candidate version, and remove or purge. Variables and their types are defined in [`meta/argument_specs.yml`](meta/argument_specs.yml), which is the source of truth.
## Supported platforms
Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The role asserts that the host is Ubuntu before any change, and the repository suite follows the host's release (`tailscale_apt_release`). The host needs outbound access to pkgs.tailscale.com.
The role targets Ubuntu hosts, not Proxmox nodes, so it does not cover Debian trixie: it asserts Ubuntu and is tested only there.
## Requirements and run order
- Use it by its fully qualified name, `mortis.kamino.tailscale`, in a play that gathers facts: the Ubuntu assert and the default of `tailscale_apt_release` read them.
- Role dependencies: none.
- `tailscale_auth_key` has no default. With `tailscale_up: true` it must be a non-empty string whenever the node is not Running (a new node, a logged-out one, or any run with `tailscale_remove`) and the run includes the configure tasks; this is asserted before any change. See Tags for which runs need it. Source it from a vaulted variable.
- A container needs `/dev/net/tun` passed through from its host, or `tailscale_userspace_networking: true`.
- The role owns no firewall rule: Tailscale makes outbound connections (UDP 41641 by default) and needs no inbound one.
- `become` is used for every task that changes the host.
## Role variables
| Variable | Default | Description |
|---|---|---|
| `tailscale_up` | `true` | Run `tailscale up` when the backend state is not Running. False installs and runs `tailscaled` without joining a tailnet. |
| `tailscale_auth_key` | none | Auth key for `tailscale up`. No default; see Requirements. `no_log`. |
| `tailscale_update` | `false` | Install the package's APT candidate version. |
| `tailscale_remove` | `false` | Log out, stop and disable `tailscaled`, remove the package, the source list and the keyring, then install and configure again. |
| `tailscale_remove_data` | `false` | With `tailscale_remove`: purge the package and delete `tailscale_state_dir`. |
| `tailscale_userspace_networking` | `false` | Add `--tun=userspace-networking` to `FLAGS` in `/etc/default/tailscaled`; false removes it again. |
| `tailscale_package` | `tailscale` | APT package name. |
| `tailscale_apt_distribution` | `ubuntu` | Repository distribution directory. |
| `tailscale_apt_release` | the host's release (`ansible_facts['distribution_release']`) | Repository suite and keyring release. |
| `tailscale_repo_url` | `https://pkgs.tailscale.com/stable/<tailscale_apt_distribution>` | APT repository URL in the source list. |
| `tailscale_keyring_url` | `<tailscale_repo_url>/<tailscale_apt_release>.noarmor.gpg` | Keyring download URL. |
| `tailscale_keyring_checksum` | sha256 of the current Tailscale keyring | Expected sha256 of the keyring; a mismatch fails the download. |
| `tailscale_keyring_path` | `/usr/share/keyrings/tailscale-archive-keyring.gpg` | Keyring destination. |
| `tailscale_apt_list_path` | `/etc/apt/sources.list.d/tailscale.list` | APT source list destination. |
| `tailscale_state_dir` | `/var/lib/tailscale` | Deleted when `tailscale_remove_data` is true. |
## Tags
The input validation (`tasks/validate.yml`) carries `always`, so it runs whatever tags are selected. `tailscale` selects every other task; `install`, `configure`, `update` and `remove` select their task files. `health` is only on the include of the configure tasks, whose own tasks carry `tailscale` and `configure`, so `--tags health` runs none of them.
The auth key is needed only by runs that include the configure tasks: no tag selection, `--tags tailscale` or `--tags configure` (and `tagged`), unless `--skip-tags` names `tailscale`, `configure` or `health`. `--tags remove`, `--tags install` and `--tags update` run without it.
## Example play
```yaml
- name: Join the tailnet
hosts: tailnet_nodes
roles:
- role: mortis.kamino.tailscale
vars:
tailscale_auth_key: "{{ vault_tailscale_auth_key }}"
```
Removal and update are explicit: `-e tailscale_remove=true` (add `tailscale_remove_data=true` to purge) removes and then reinstalls, while `--tags remove` runs only the removal; `-e tailscale_update=true --tags update` updates.
## Tests
The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It installs the real package from pkgs.tailscale.com with `tailscale_up: false` and `tailscale_userspace_networking: true`. `tailscale up` (joining a tailnet) is not exercised: the scenario has no auth key and no tailnet. Verify checks the keyring checksum against the published hash, the APT source line, the package installed from that repository, `tailscaled` enabled and active, the `FLAGS` line in `/etc/default/tailscaled` with the package's `PORT` line kept, the running daemon's command line carrying `--tun=userspace-networking`, and a backend state that is not Running. It then downgrades the package to an older version from the repository and runs the role with `tailscale_update` (the candidate is installed again), Removal is run twice. First the remove tasks alone, as `--tags remove` runs them, without `tailscale_remove_data`: the package and the source list go, while a marker in the state directory and a line added to the defaults file stay. A second removal, with no `tailscaled` unit left, passes, and the role then installs Tailscale again with the state kept. Second, the role with `tailscale_remove` and `tailscale_remove_data` and a `tailscale_state_dir` other than `/var/lib/tailscale`, which the package's own purge deletes: that directory is gone, the defaults file is the package's fresh copy, and the role installed and configured Tailscale again. Verify waits for `tailscaled` to be active after each restart. It runs `check` before the converge (a fresh host) and after it (a configured host). Negative tests cover a host without Ubuntu facts, a `tailscale_up` that is not a boolean, and `tailscale_up: true` without an auth key or with an empty one. Switching `tailscale_userspace_networking` back to false is not run: `tailscaled` cannot start without `/dev/net/tun` in the container.
## Notes
- Idempotent: yes, with `tailscale_up: false` (the scenario checks it). With `tailscale_up: true`, `tailscale up` runs only while the node is not Running.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. On a host without the package, the package install, the `FLAGS` edit, the service start and the update are skipped under `--check`, because the new source line is only simulated. `tailscale up` is always skipped under `--check`. The auth key is still asserted.
- The auth key is passed as `--auth-key=file:<path>` from a root-owned 0600 temporary file, so it never appears in argv. The file is always removed, and the write and `tailscale up` tasks use `no_log`.
- `tailscale up` runs only when `tailscale status --json` reports a state other than `Running` (an unreadable status counts as not running).
- No Tailscale SSH flag and no ACL tag are set: the node gets a plain tailnet IP.
- `tailscale_userspace_networking` edits only the `--tun=userspace-networking` token of the `FLAGS` line; other flags and the rest of `/etc/default/tailscaled` (a conffile of the package, which also holds `PORT`) are kept. A change, or a `tailscaled` that is not active, restarts it at once after clearing its failure state (`systemctl reset-failed`): the package starts it with the flags it ships, which fails without a TUN device and can run into systemd's start limit. The flag belongs to `tailscaled`, not to `tailscale up`.
- The `Restart tailscaled` handler runs after a package install or update.
- Removal tolerates a host with no `tailscaled` unit, so a repeated `--tags remove` passes.
- `tailscale logout` during removal is best effort. A removal without `tailscale_remove_data` keeps the state directory and the defaults file.
+24
View File
@@ -0,0 +1,24 @@
---
# tailscale_auth_key has no default: it is a secret, required whenever tailscale up has to run.
tailscale_up: true
tailscale_update: false
tailscale_remove: false
tailscale_remove_data: false
# Runs tailscaled without a TUN device, for hosts (containers) that have no /dev/net/tun.
tailscale_userspace_networking: false
tailscale_package: tailscale
tailscale_apt_distribution: ubuntu
# The default keeps argument validation from failing on a play without facts, so the Ubuntu assert
# in tasks/validate.yml gives the reason instead.
tailscale_apt_release: "{{ ansible_facts['distribution_release'] | default('') }}"
tailscale_repo_url: "https://pkgs.tailscale.com/stable/{{ tailscale_apt_distribution }}"
tailscale_keyring_url: "{{ tailscale_repo_url }}/{{ tailscale_apt_release }}.noarmor.gpg"
# sha256 of Tailscale's package signing key (2596A99EAAB33821893C0A79458CA832957F5868), the same
# file for noble and resolute. Static on purpose: a rotated key fails the install until a person
# has checked the new one and updated this hash.
tailscale_keyring_checksum: "3e03dacf222698c60b8e2f990b809ca1b3e104de127767864284e6c228f1fb39"
tailscale_keyring_path: /usr/share/keyrings/tailscale-archive-keyring.gpg
tailscale_apt_list_path: /etc/apt/sources.list.d/tailscale.list
tailscale_state_dir: /var/lib/tailscale
+6
View File
@@ -0,0 +1,6 @@
---
- name: Restart tailscaled
become: true
ansible.builtin.systemd:
name: tailscaled
state: restarted
+101
View File
@@ -0,0 +1,101 @@
---
argument_specs:
main:
short_description: Install Tailscale and bring the node up
description:
- >-
Asserts an Ubuntu host, optionally removes Tailscale first, installs the package from the upstream APT repository
with the keyring pinned by sha256, sets the C(tailscaled) flags, enables C(tailscaled), runs C(tailscale up) when
C(tailscale_up) is true and the backend state is not Running, and optionally updates the package to the APT
candidate version.
- Needs gathered facts. It owns no firewall rule. No Tailscale SSH flag and no ACL tag are set.
options:
tailscale_up:
type: bool
default: true
description:
- >-
Runs C(tailscale up) when the backend state is not Running. C(tailscale_auth_key) must then be a non-empty
string; this is asserted before any change. False installs and runs C(tailscaled) without joining a tailnet.
tailscale_auth_key:
type: str
no_log: true
description:
- >-
Auth key for C(tailscale up), handed over through a root-owned 0600 temporary file that is always removed
afterwards. No default. Required, non-empty, when C(tailscale_up) is true and the node is not Running (or
C(tailscale_remove) is true); otherwise not read.
tailscale_update:
type: bool
default: false
description:
- Refreshes the APT cache and installs the package's candidate version, pinned as package=version.
tailscale_remove:
type: bool
default: false
description:
- >-
Logs out (best effort), stops and disables C(tailscaled), removes the package, the APT source list and the
keyring, then installs and configures Tailscale again.
tailscale_remove_data:
type: bool
default: false
description:
- Only used with C(tailscale_remove). Purges the package and deletes C(tailscale_state_dir).
tailscale_userspace_networking:
type: bool
default: false
description:
- >-
Adds C(--tun=userspace-networking) to C(FLAGS) in C(/etc/default/tailscaled) and restarts C(tailscaled), for
hosts without C(/dev/net/tun). False removes that flag again. Other flags in C(FLAGS) are kept.
tailscale_package:
type: str
default: tailscale
description:
- APT package installed, updated or removed.
tailscale_apt_distribution:
type: str
default: ubuntu
description:
- Distribution directory of the Tailscale repository, used in C(tailscale_repo_url) and the source list comment.
tailscale_apt_release:
type: raw
description:
- >-
Release codename of the repository suite and of the keyring file name. The role default is the Jinja
expression C(ansible_facts['distribution_release']), the host's own release.
tailscale_repo_url:
type: raw
description:
- >-
APT repository URL written to the source list. The role default is a Jinja expression built from
C(tailscale_apt_distribution) (C(https://pkgs.tailscale.com/stable/ubuntu)).
tailscale_keyring_url:
type: raw
description:
- >-
Download URL of the APT keyring. The role default is a Jinja expression built from C(tailscale_repo_url) and
C(tailscale_apt_release) (C(https://pkgs.tailscale.com/stable/ubuntu/<release>.noarmor.gpg)).
tailscale_keyring_checksum:
type: str
default: 3e03dacf222698c60b8e2f990b809ca1b3e104de127767864284e6c228f1fb39
description:
- >-
sha256 (hex) of the keyring at C(tailscale_keyring_url). The download fails on a mismatch, so a rotated
upstream key stops the install until the new key is checked and the hash updated.
tailscale_keyring_path:
type: path
default: /usr/share/keyrings/tailscale-archive-keyring.gpg
description:
- Destination of the downloaded keyring.
tailscale_apt_list_path:
type: path
default: /etc/apt/sources.list.d/tailscale.list
description:
- Destination of the APT source list.
tailscale_state_dir:
type: path
default: /var/lib/tailscale
description:
- State directory of C(tailscaled), deleted when C(tailscale_remove_data) is true.
+18
View File
@@ -0,0 +1,18 @@
---
galaxy_info:
role_name: tailscale
namespace: mortis
author: Defame1297
license: GPL-3.0-or-later
description: Install Tailscale from the upstream APT repository and bring the node up with an auth key.
min_ansible_version: "2.22"
platforms:
- name: Ubuntu
versions:
- noble
- resolute
galaxy_tags:
- tailscale
- vpn
- networking
dependencies: []
@@ -0,0 +1,8 @@
---
# tailscale_up false and userspace networking come from molecule.yml: the node installs and runs
# tailscaled but never joins a tailnet.
- name: Converge
hosts: all
gather_facts: true
roles:
- role: mortis.kamino.tailscale
@@ -0,0 +1,72 @@
---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# .gitea/workflows/molecule.yml. Needs outbound network: the role installs the real package from
# pkgs.tailscale.com. The node never joins a tailnet (tailscale_up false), and tailscaled runs with
# userspace networking because a container may have no /dev/net/tun. The containers run systemd as
# PID 1 with a writable cgroup; no privileged mode.
driver:
name: docker
platforms:
- name: ${KAMINO_RUN_ID:-local}-tailscale-noble
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
capabilities:
- NET_ADMIN
security_opts:
- apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-tailscale-resolute
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
capabilities:
- NET_ADMIN
security_opts:
- apparmor=unconfined
provisioner:
name: ansible
# One source for every play, so the converge and the plays in verify.yml start from the same
# valid input.
inventory:
group_vars:
all:
tailscale_up: false
tailscale_userspace_networking: true
verifier:
name: ansible
scenario:
# molecule's default sequence minus both destroys (scripts/run_molecule_scenarios.sh removes the
# containers as soon as this scenario ends; after a local run, run `molecule destroy` yourself),
# plus a check before the converge (fresh host) and one after it (configured host).
test_sequence:
- dependency
- cleanup
- syntax
- create
- prepare
- check
- converge
- check
- idempotence
- side_effect
- verify
- cleanup
@@ -0,0 +1,21 @@
---
# One failing run: includes the role with the inputs the caller sets on the include, and asserts
# that the expected message, not something else, stopped it. Input: tailscale_test_case (name,
# expect).
- name: "Run the role, case {{ tailscale_test_case.name }}"
block:
- name: "Include the role, case {{ tailscale_test_case.name }}"
ansible.builtin.include_role:
name: mortis.kamino.tailscale
# Only reached when the include returned. The message must not contain the expected
# text, so the rescue below cannot mistake it for the failure under test.
- name: "Fail because the include returned, case {{ tailscale_test_case.name }}"
ansible.builtin.fail:
msg: The role accepted the input
rescue:
- name: "The expected failure stopped the run, case {{ tailscale_test_case.name }}"
ansible.builtin.assert:
that: tailscale_test_case.expect in (ansible_failed_result.msg | default(''))
fail_msg: "Expected '{{ tailscale_test_case.expect }}', got: {{ ansible_failed_result.msg | default('') }}"
quiet: true
+385
View File
@@ -0,0 +1,385 @@
---
# Runs first, before any play gathers facts: the role refuses a host it cannot identify as
# Ubuntu, before any change.
- name: Refuse a host without Ubuntu facts
hosts: all
gather_facts: false
tasks:
- name: Run the role without gathered facts
ansible.builtin.include_tasks: tasks/failed_run.yml
vars:
tailscale_test_case:
name: no-facts
expect: tailscale supports Ubuntu only
# Negative tests: each validation stops the role before any change. The node is not Running (it
# never joined a tailnet), so tailscale_up true needs an auth key.
- name: Refuse invalid input
hosts: all
gather_facts: true
tasks:
- name: Refuse tailscale_up that is not a boolean
ansible.builtin.include_tasks: tasks/failed_run.yml
vars:
tailscale_up: maybe
tailscale_test_case:
name: up-not-bool
expect: "argument 'tailscale_up' is of type str and we were unable to convert to bool"
- name: Refuse tailscale_up without an auth key
ansible.builtin.include_tasks: tasks/failed_run.yml
vars:
tailscale_up: true
tailscale_test_case:
name: up-without-key
expect: tailscale_auth_key must be a non-empty string
- name: Refuse tailscale_up with an empty auth key
ansible.builtin.include_tasks: tasks/failed_run.yml
vars:
tailscale_up: true
tailscale_auth_key: ""
tailscale_test_case:
name: up-empty-key
expect: tailscale_auth_key must be a non-empty string
- name: Verify the install
hosts: all
gather_facts: true
tasks:
- name: Stat the keyring
ansible.builtin.stat:
path: /usr/share/keyrings/tailscale-archive-keyring.gpg
checksum_algorithm: sha256
register: tailscale_test_keyring
# The hash of Tailscale's package signing key as published, written out here rather than read
# from the role defaults, so a changed default cannot pass by itself.
- name: The keyring is the pinned key, world-readable for apt
ansible.builtin.assert:
that:
- tailscale_test_keyring.stat.checksum == '3e03dacf222698c60b8e2f990b809ca1b3e104de127767864284e6c228f1fb39'
- tailscale_test_keyring.stat.mode == '0644'
quiet: true
- name: Read the APT source list
ansible.builtin.slurp:
src: /etc/apt/sources.list.d/tailscale.list
register: tailscale_test_source
- name: The source line names the keyring and the host's release
ansible.builtin.assert:
that:
- >-
('deb [signed-by=/usr/share/keyrings/tailscale-archive-keyring.gpg] https://pkgs.tailscale.com/stable/ubuntu '
~ ansible_facts['distribution_release'] ~ ' main')
in (tailscale_test_source.content | b64decode).splitlines()
quiet: true
- name: Ask apt where tailscale comes from
ansible.builtin.command: apt-cache policy tailscale
register: tailscale_test_policy
changed_when: false
- name: Ask dpkg for the package state
ansible.builtin.command:
argv: [dpkg-query, --show, --showformat, "${db:Status-Status}", tailscale]
register: tailscale_test_dpkg
changed_when: false
- name: The package is installed from pkgs.tailscale.com
ansible.builtin.assert:
that:
- tailscale_test_dpkg.stdout == 'installed'
- "'Installed: (none)' not in tailscale_test_policy.stdout"
- "'https://pkgs.tailscale.com/stable/ubuntu ' ~ ansible_facts['distribution_release'] in tailscale_test_policy.stdout"
quiet: true
# tailscaled may still be starting after a restart.
- name: Wait for tailscaled
ansible.builtin.systemd:
name: tailscaled
register: tailscale_test_unit
check_mode: true
until: tailscale_test_unit.status.ActiveState == 'active'
retries: 10
delay: 3
- name: Tailscaled is enabled and running
ansible.builtin.assert:
that:
- tailscale_test_unit.status.UnitFileState == 'enabled'
- tailscale_test_unit.status.ActiveState == 'active'
quiet: true
- name: Read the tailscaled defaults file
ansible.builtin.slurp:
src: /etc/default/tailscaled
register: tailscale_test_defaults
- name: FLAGS carries userspace networking and the package's PORT line is kept
ansible.builtin.assert:
that:
- tailscale_test_defaults_lines | select('match', '^FLAGS=') | list == ['FLAGS="--tun=userspace-networking"']
- "'PORT=\"41641\"' in tailscale_test_defaults_lines"
quiet: true
vars:
tailscale_test_defaults_lines: "{{ (tailscale_test_defaults.content | b64decode).splitlines() }}"
# The effect on the service, not only the file: the running daemon got the flag.
- name: Read the main PID of tailscaled
ansible.builtin.command: systemctl show --property=MainPID --value tailscaled # noqa: command-instead-of-module
register: tailscale_test_pid
changed_when: false
- name: Read the command line of the running daemon
ansible.builtin.slurp:
src: /proc/{{ tailscale_test_pid.stdout }}/cmdline
register: tailscale_test_cmdline
- name: The running daemon uses userspace networking
ansible.builtin.assert:
that:
- "'--tun=userspace-networking' in (tailscale_test_cmdline.content | b64decode)"
quiet: true
- name: Ask tailscaled for its backend state
ansible.builtin.command: tailscale status --json
register: tailscale_test_status
changed_when: false
failed_when: false
# tailscale_up is false: the daemon answers, and the node did not join a tailnet.
- name: The daemon answers and the node is not up
ansible.builtin.assert:
that:
- (tailscale_test_status.stdout | from_json).BackendState is defined
- (tailscale_test_status.stdout | from_json).BackendState != 'Running'
quiet: true
# The role pins the update to the APT candidate: downgrade to an older version from the same
# repository, then run with tailscale_update.
- name: Verify the update path
hosts: all
gather_facts: true
tasks:
- name: List the versions the repository offers
ansible.builtin.command: apt-cache madison tailscale
register: tailscale_test_madison
changed_when: false
- name: Read the candidate version
ansible.builtin.command: apt-cache policy tailscale
register: tailscale_test_policy
changed_when: false
- name: Pick the candidate and the newest older version
ansible.builtin.set_fact:
tailscale_test_candidate: "{{ tailscale_test_candidate_v }}"
tailscale_test_older: "{{ tailscale_test_versions | reject('equalto', tailscale_test_candidate_v) | first }}"
vars:
tailscale_test_candidate_v: "{{ tailscale_test_policy.stdout | regex_search('Candidate:\\s+(\\S+)', '\\1') | first }}"
tailscale_test_versions: "{{ tailscale_test_madison.stdout_lines | map('split', '|') | map(attribute=1) | map('trim') | list }}"
- name: Downgrade tailscale
ansible.builtin.apt:
name: "tailscale={{ tailscale_test_older }}"
allow_downgrade: true
state: present
- name: Read the installed version after the downgrade
ansible.builtin.command:
argv: [dpkg-query, --show, --showformat, "${Version}", tailscale]
register: tailscale_test_downgraded
changed_when: false
- name: The downgrade took effect
ansible.builtin.assert:
that: tailscale_test_downgraded.stdout == tailscale_test_older
quiet: true
- name: Run the role with tailscale_update
ansible.builtin.include_role:
name: mortis.kamino.tailscale
vars:
tailscale_update: true
- name: Read the installed version after the update
ansible.builtin.command:
argv: [dpkg-query, --show, --showformat, "${Version}", tailscale]
register: tailscale_test_updated
changed_when: false
# tailscaled may still be starting after a restart.
- name: Wait for tailscaled after the update
ansible.builtin.systemd:
name: tailscaled
register: tailscale_test_unit
check_mode: true
until: tailscale_test_unit.status.ActiveState == 'active'
retries: 10
delay: 3
- name: The candidate is installed and tailscaled runs
ansible.builtin.assert:
that:
- tailscale_test_updated.stdout == tailscale_test_candidate
- tailscale_test_unit.status.ActiveState == 'active'
quiet: true
# A removal without tailscale_remove_data, through the role's remove tasks alone (as --tags remove
# runs them): the package goes, while the state directory and the defaults file (a conffile) stay.
# A second removal finds no tailscaled unit and must still pass. The role then installs it again.
- name: Verify removal without purge
hosts: all
gather_facts: true
tasks:
- name: Put a marker in the state directory
ansible.builtin.copy:
content: marker
dest: /var/lib/tailscale/molecule-marker
mode: "0600"
- name: Add a marker line to the defaults file
ansible.builtin.lineinfile:
path: /etc/default/tailscaled
line: "# molecule-marker"
- name: Run the remove tasks
ansible.builtin.include_role:
name: mortis.kamino.tailscale
tasks_from: remove
vars:
tailscale_remove: true
- name: Ask dpkg for the package state
ansible.builtin.command:
argv: [dpkg-query, --show, --showformat, "${db:Status-Status}", tailscale]
register: tailscale_test_dpkg
changed_when: false
failed_when: false
- name: Stat the state marker and the source list
ansible.builtin.stat:
path: "{{ item }}"
loop:
- /var/lib/tailscale/molecule-marker
- /etc/apt/sources.list.d/tailscale.list
register: tailscale_test_kept
- name: Read the defaults file
ansible.builtin.slurp:
src: /etc/default/tailscaled
register: tailscale_test_defaults
- name: The package and the source list are gone, the state and the defaults file are kept
ansible.builtin.assert:
that:
- tailscale_test_dpkg.stdout != 'installed'
- tailscale_test_kept.results | map(attribute='stat.exists') | list == [true, false]
- "'# molecule-marker' in (tailscale_test_defaults.content | b64decode).splitlines()"
quiet: true
- name: Run the remove tasks again, with no tailscaled unit left
ansible.builtin.include_role:
name: mortis.kamino.tailscale
tasks_from: remove
vars:
tailscale_remove: true
- name: Install again
ansible.builtin.include_role:
name: mortis.kamino.tailscale
- name: Wait for tailscaled
ansible.builtin.systemd:
name: tailscaled
register: tailscale_test_unit
check_mode: true
until: tailscale_test_unit.status.ActiveState == 'active'
retries: 10
delay: 3
- name: Stat the state marker again
ansible.builtin.stat:
path: /var/lib/tailscale/molecule-marker
register: tailscale_test_marker
- name: The reinstall kept the state
ansible.builtin.assert:
that:
- tailscale_test_marker.stat.exists
- tailscale_test_unit.status.UnitFileState == 'enabled'
quiet: true
# tailscale_remove with tailscale_remove_data purges the package and deletes tailscale_state_dir,
# then the role installs it again. The package's own purge deletes /var/lib/tailscale, so the state
# directory here is another one: only the role removes it. The marker line in the defaults file (a
# conffile, so only a purge replaces it) shows the purge.
- name: Verify removal with purge
hosts: all
gather_facts: true
vars:
tailscale_test_state_dir: /srv/tailscale-molecule-state
tasks:
- name: Create the state directory
ansible.builtin.file:
path: "{{ tailscale_test_state_dir }}"
state: directory
mode: "0700"
- name: Put a marker in the state directory
ansible.builtin.copy:
content: marker
dest: "{{ tailscale_test_state_dir }}/molecule-marker"
mode: "0600"
- name: Add a marker line to the defaults file
ansible.builtin.lineinfile:
path: /etc/default/tailscaled
line: "# molecule-marker"
- name: Run the role with removal and data removal
ansible.builtin.include_role:
name: mortis.kamino.tailscale
vars:
tailscale_remove: true
tailscale_remove_data: true
tailscale_state_dir: "{{ tailscale_test_state_dir }}"
- name: Stat the state directory
ansible.builtin.stat:
path: "{{ tailscale_test_state_dir }}"
register: tailscale_test_state
- name: Read the defaults file
ansible.builtin.slurp:
src: /etc/default/tailscaled
register: tailscale_test_defaults
- name: Ask dpkg for the package state
ansible.builtin.command:
argv: [dpkg-query, --show, --showformat, "${db:Status-Status}", tailscale]
register: tailscale_test_dpkg
changed_when: false
- name: Wait for tailscaled
ansible.builtin.systemd:
name: tailscaled
register: tailscale_test_unit
check_mode: true
until: tailscale_test_unit.status.ActiveState == 'active'
retries: 10
delay: 3
- name: The data went, and the role installed and configured tailscale again
ansible.builtin.assert:
that:
- not tailscale_test_state.stat.exists
- "'# molecule-marker' not in tailscale_test_defaults_lines"
- "'FLAGS=\"--tun=userspace-networking\"' in tailscale_test_defaults_lines"
- tailscale_test_dpkg.stdout == 'installed'
- tailscale_test_unit.status.UnitFileState == 'enabled'
quiet: true
vars:
tailscale_test_defaults_lines: "{{ (tailscale_test_defaults.content | b64decode).splitlines() }}"
+174
View File
@@ -0,0 +1,174 @@
---
# --tun=userspace-networking is a tailscaled flag. The package's systemd unit passes $FLAGS from
# /etc/default/tailscaled (a conffile that also holds PORT), so the role edits only that one flag
# in the FLAGS line and keeps everything else.
- name: Check for the tailscaled defaults file
ansible.builtin.stat:
path: /etc/default/tailscaled
register: __tailscale_defaults_stat
check_mode: false
tags: [tailscale, configure]
- name: Read the tailscaled defaults file
become: true
ansible.builtin.slurp:
src: /etc/default/tailscaled
register: __tailscale_defaults
when: __tailscale_defaults_stat.stat.exists
tags: [tailscale, configure]
- name: Work out the tailscaled flags
ansible.builtin.set_fact:
__tailscale_flags: >-
{{ __tailscale_current_flags | reject('equalto', '--tun=userspace-networking') | list
+ (['--tun=userspace-networking'] if tailscale_userspace_networking | bool else []) }}
vars:
__tailscale_flags_line: >-
{{ (__tailscale_defaults.content | default('') | b64decode).splitlines()
| select('match', '^FLAGS=') | list | last | default('FLAGS=', true) }}
__tailscale_current_flags: >-
{{ __tailscale_flags_line | regex_replace('^FLAGS=', '') | trim
| regex_replace('^"(.*)"$', '\1') | regex_replace("^'(.*)'$", '\1') | split }}
tags: [tailscale, configure]
# Under --check the unit exists only when the package is installed and this run did not just
# (simulate) installing it; the defaults file ships with the package.
- name: Work out whether the tailscaled unit can be managed
ansible.builtin.set_fact:
__tailscale_unit_present: >-
{{ not ansible_check_mode
or (__tailscale_defaults_stat.stat.exists
and __tailscale_apt_source | default({}) is not changed
and __tailscale_package_install | default({}) is not changed) }}
tags: [tailscale, configure]
- name: Set the tailscaled flags
become: true
ansible.builtin.lineinfile:
path: /etc/default/tailscaled
regexp: "^FLAGS="
line: FLAGS="{{ __tailscale_flags | join(' ') }}"
register: __tailscale_flags_file
# The package ships the file; under --check on a host without the package it does not exist yet.
when: not ansible_check_mode or __tailscale_defaults_stat.stat.exists
tags: [tailscale, configure]
- name: Read the state of tailscaled
become: true
ansible.builtin.systemd:
name: tailscaled
register: __tailscale_unit
check_mode: true
when: __tailscale_unit_present | bool
tags: [tailscale, configure]
# The package starts tailscaled with the flags it ships. Without a TUN device that start fails and
# Restart=on-failure can run into the start limit, which refuses a later plain start. So when the
# flags changed or the unit is not active, clear the failure state and restart now, not at the end
# of the play.
- name: Restart tailscaled with the current flags
when:
- __tailscale_unit_present | bool
- __tailscale_flags_file is changed or __tailscale_unit.status.ActiveState | default('') != 'active'
tags: [tailscale, configure]
block:
- name: Clear the failure state of tailscaled
become: true
ansible.builtin.command: systemctl reset-failed tailscaled # noqa: command-instead-of-module
register: __tailscale_reset_failed
changed_when: false
# systemd unloads an inactive unit nothing references (a disabled one the package did not
# start, e.g. after a removal without purge); it then has no failure state to clear, and the
# restart below loads it.
failed_when:
- __tailscale_reset_failed.rc != 0
- "'not loaded' not in __tailscale_reset_failed.stderr | default('')"
# Not run under --check: the restart below only reports what it would do there.
when: not ansible_check_mode
- name: Restart tailscaled
become: true
ansible.builtin.systemd:
name: tailscaled
state: restarted
- name: Enable and start tailscaled service
become: true
ansible.builtin.systemd:
name: tailscaled
enabled: true
state: started
when: __tailscale_unit_present | bool
tags: [tailscale, configure]
- name: Check current Tailscale backend status
become: true
ansible.builtin.command: tailscale status --json
register: __tailscale_status
changed_when: false
# Failure with empty stdout (daemon not up yet) yields NoState below; a logged-out node reports
# its own non-Running state. Any state other than Running makes the next block run tailscale up;
# a real fault surfaces there.
failed_when: false
when: tailscale_up | bool
tags: [tailscale, configure]
# No Tailscale SSH flag and no ACL tag: the node gets a plain tailnet IP.
# The auth key is handed over as --auth-key=file:<path> instead of on argv, where it would be
# readable in ps and /proc/<pid>/cmdline; tailscale up does not read TS_AUTHKEY. The 0600
# root-owned temporary file is always removed, also on failure.
# Skipped under --check: tempfile does not support check mode, so the later steps would have no
# path to work on.
- name: Bring Tailscale node up
when:
- tailscale_up | bool
- (__tailscale_status.stdout | default('{}', true) | from_json).BackendState | default('NoState') != 'Running'
- not ansible_check_mode
tags: [tailscale, configure]
block:
# validate.yml asserts this already from the state before any change; the state is read again
# here, so the key is checked against the state tailscale up actually acts on.
- name: Require an auth key for tailscale up
ansible.builtin.assert:
that:
- tailscale_auth_key is defined
- tailscale_auth_key is string
- tailscale_auth_key | trim | length > 0
fail_msg: >-
tailscale_auth_key must be a non-empty string: tailscale_up is true and the node is not Running,
so the role runs tailscale up. Set the key, normally from a vaulted variable, or set tailscale_up to false.
quiet: true
- name: Create temporary file for the Tailscale auth key
become: true
ansible.builtin.tempfile:
state: file
prefix: tsauthkey.
register: __tailscale_authkey_file
changed_when: false
- name: Write Tailscale auth key to the temporary file
become: true
no_log: true
diff: false
ansible.builtin.copy:
content: "{{ tailscale_auth_key }}"
dest: "{{ __tailscale_authkey_file.path }}"
owner: root
group: root
mode: "0600"
changed_when: false
- name: Run tailscale up
become: true
no_log: true
ansible.builtin.command: tailscale up --auth-key=file:{{ __tailscale_authkey_file.path }}
changed_when: true
always:
- name: Remove temporary Tailscale auth key file
become: true
ansible.builtin.file:
path: "{{ __tailscale_authkey_file.path }}"
state: absent
when: __tailscale_authkey_file.path is defined
changed_when: false
+41
View File
@@ -0,0 +1,41 @@
---
- name: Ensure APT keyrings directory exists
become: true
ansible.builtin.file:
path: "{{ tailscale_keyring_path | dirname }}"
state: directory
mode: "0755"
tags: [tailscale, install]
- name: Install Tailscale APT keyring
become: true
ansible.builtin.get_url:
url: "{{ tailscale_keyring_url }}"
dest: "{{ tailscale_keyring_path }}"
checksum: "sha256:{{ tailscale_keyring_checksum }}"
mode: "0644"
tags: [tailscale, install]
# Same content as upstream's <release>.tailscale-keyring.list.
- name: Install Tailscale APT source list
become: true
ansible.builtin.copy:
dest: "{{ tailscale_apt_list_path }}"
content: |
# Tailscale packages for {{ tailscale_apt_distribution }} {{ tailscale_apt_release }}
deb [signed-by={{ tailscale_keyring_path }}] {{ tailscale_repo_url }} {{ tailscale_apt_release }} main
mode: "0644"
register: __tailscale_apt_source
tags: [tailscale, install]
- name: Install Tailscale package
become: true
ansible.builtin.apt:
name: "{{ tailscale_package }}"
state: present
update_cache: true
register: __tailscale_package_install
notify: Restart tailscaled
# Under --check a new source line is only simulated, so apt would find no tailscale package.
when: not ansible_check_mode or __tailscale_apt_source is not changed
tags: [tailscale, install]
+30
View File
@@ -0,0 +1,30 @@
---
# Validation first, under always, so a bad input fails before any change whatever tags the run
# selects.
- name: Validate the role inputs
ansible.builtin.import_tasks: validate.yml
tags: always
- name: Remove Tailscale (explicit only)
ansible.builtin.include_tasks: remove.yml
when: tailscale_remove | bool
tags: [tailscale, remove]
- name: Install Tailscale
ansible.builtin.include_tasks: install.yml
tags: [tailscale, install]
- name: Configure Tailscale
ansible.builtin.include_tasks: configure.yml
tags: [tailscale, configure, health]
- name: Ensure Tailscale is up-to-date
ansible.builtin.include_tasks: update.yml
when:
- tailscale_update | bool
# Under --check a new source line is only simulated, so apt would have no candidate.
- not ansible_check_mode or __tailscale_apt_source | default({}) is not changed
tags: [tailscale, update]
- name: Flush handlers
ansible.builtin.meta: flush_handlers
+55
View File
@@ -0,0 +1,55 @@
---
# Run with tailscale_remove=true (and tailscale_remove_data=true to purge), tag: remove. main.yml
# installs and configures Tailscale again afterwards.
- name: Log Tailscale out of the tailnet
become: true
ansible.builtin.command: tailscale logout
register: __tailscale_logout
changed_when: __tailscale_logout.rc == 0
# Best effort: already logged out, tailscaled down or binary missing must not block the removal. A
# failed logout leaves a stale device in the tailnet admin console.
failed_when: false
tags: [tailscale, remove]
- name: Stop and disable tailscaled service
become: true
ansible.builtin.systemd:
name: tailscaled
state: stopped
enabled: false
register: __tailscale_stop
# A host without the package has no unit; there is nothing to stop then.
failed_when:
- __tailscale_stop is failed
- "'Could not find the requested service' not in __tailscale_stop.msg | default('')"
tags: [tailscale, remove]
- name: Remove Tailscale package
become: true
ansible.builtin.apt:
name: "{{ tailscale_package }}"
state: absent
purge: "{{ tailscale_remove_data | bool }}"
tags: [tailscale, remove]
- name: Remove Tailscale APT source list
become: true
ansible.builtin.file:
path: "{{ tailscale_apt_list_path }}"
state: absent
tags: [tailscale, remove]
- name: Remove Tailscale APT keyring
become: true
ansible.builtin.file:
path: "{{ tailscale_keyring_path }}"
state: absent
tags: [tailscale, remove]
- name: Remove Tailscale state directory
become: true
ansible.builtin.file:
path: "{{ tailscale_state_dir }}"
state: absent
when: tailscale_remove_data | bool
tags: [tailscale, remove]
+39
View File
@@ -0,0 +1,39 @@
---
# Run with tailscale_update=true (tag: update).
- name: Refresh APT cache before checking for Tailscale updates
become: true
ansible.builtin.apt:
update_cache: true
tags: [tailscale, update]
- name: Determine latest available Tailscale candidate version
ansible.builtin.command: apt-cache policy {{ tailscale_package | quote }}
register: __tailscale_apt_policy
changed_when: false
# Read-only, so it also runs in the --check preview, which needs its stdout.
check_mode: false
tags: [tailscale, update]
- name: Extract latest Tailscale candidate version
ansible.builtin.set_fact:
__tailscale_candidate_version: >-
{{ __tailscale_apt_policy.stdout | regex_search('Candidate:\s+(\S+)', '\1') | default([''], true) | first }}
tags: [tailscale, update]
- name: Fail if Tailscale has no installable candidate
ansible.builtin.fail:
msg: >-
No installable candidate version found for {{ tailscale_package }} (apt-cache policy reported
'{{ __tailscale_candidate_version }}'). Check that the Tailscale APT repository is reachable.
when: __tailscale_candidate_version in ['', '(none)']
tags: [tailscale, update]
# Pinned to the resolved candidate version (never state=latest), so the task stays idempotent and
# passes ansible-lint's package-latest rule.
- name: Update Tailscale package to latest candidate version
become: true
ansible.builtin.apt:
name: "{{ tailscale_package }}={{ __tailscale_candidate_version }}"
state: present
notify: Restart tailscaled
tags: [tailscale, update]
+52
View File
@@ -0,0 +1,52 @@
---
# Input checks. Imported first in main.yml with tags: always, so a bad input fails before any
# change. The argument spec (types) runs before this file.
# The repository suite and the source list follow the host's release, read from gathered facts.
- name: Require Ubuntu
ansible.builtin.assert:
that:
- ansible_facts['distribution'] | default('') == 'Ubuntu'
fail_msg: >-
tailscale supports Ubuntu only (found: {{ ansible_facts['distribution'] | default('no gathered facts') }}).
The role reads gathered facts, so run it in a play that gathers them.
quiet: true
# tailscale up runs in the configure tasks (tags tailscale and configure), so the key is needed
# only when the run selects them and skips neither.
- name: Work out whether this run brings the node up
ansible.builtin.set_fact:
__tailscale_runs_up: >-
{{ tailscale_up | bool
and (ansible_run_tags | intersect(['all', 'tagged', 'tailscale', 'configure']) | length > 0)
and (ansible_skip_tags | intersect(['tailscale', 'configure', 'health']) | length == 0) }}
# Read-only, so it also runs under --check. A missing binary or a daemon that is not up counts as
# not Running.
- name: Read the Tailscale backend state before any change
become: true
ansible.builtin.command: tailscale status --json
register: __tailscale_status_before
changed_when: false
failed_when: false
check_mode: false
when: __tailscale_runs_up | bool
# tailscale up runs when the node is not Running, and a removal logs it out first, so then the
# key is needed. The configure tasks check it again against the state tailscale up acts on.
- name: Require an auth key when tailscale up will run
ansible.builtin.assert:
that:
- tailscale_auth_key is defined
- tailscale_auth_key is string
- tailscale_auth_key | trim | length > 0
fail_msg: >-
tailscale_auth_key must be a non-empty string: tailscale_up is true and the node is not Running
(or tailscale_remove is true), so the role runs tailscale up. Set the key, normally from a
vaulted variable, or set tailscale_up to false.
quiet: true
when:
- __tailscale_runs_up | bool
- >-
tailscale_remove | bool
or (__tailscale_status_before.stdout | default('{}', true) | from_json).BackendState | default('NoState') != 'Running'
+3 -2
View File
@@ -4,7 +4,7 @@ Installs the Traefik reverse proxy as a systemd-managed binary, renders its stat
## Supported platforms ## Supported platforms
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. The role uses `ansible.builtin.apt`, so Debian-family hosts only, and needs outbound access to github.com for the release archive and checksum file. Only `traefik_install_type: binary` exists. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on. The role uses `ansible.builtin.apt`, so Debian-family hosts only, and needs outbound access to github.com for the release archive and checksum file. Only `traefik_install_type: binary` exists.
The role targets Ubuntu hosts that run the reverse proxy, not Proxmox nodes, so it does not cover Debian trixie. The role targets Ubuntu hosts that run the reverse proxy, not Proxmox nodes, so it does not cover Debian trixie.
@@ -79,7 +79,7 @@ Update or remove: pass `-e traefik_update=true`, or `-e "traefik_remove=true tra
## Tests ## Tests
The `default` molecule scenario runs on one platform, Ubuntu 24.04 (noble) (`${MOLECULE_IMAGE}`). It needs outbound network: the role installs packages with apt and downloads real Traefik releases from GitHub. Converge runs `mortis.kamino.ufw`, then the role. Verify covers: The `default` molecule scenario runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). It needs outbound network: the role installs packages with apt and downloads real Traefik releases from GitHub. Converge runs `mortis.kamino.ufw`, then the role. It runs `check` before the converge (on a fresh host) and after it (on the configured host). Verify covers:
- The input guards, first: one play expects the failure message containing `unauthenticated Traefik dashboard` (the dashboard guard: enabled without valid `user:hash` users); the next expects `collides with the middleware`, raised by the dashboard-auth collision assert, which runs whenever users are set, also with the dashboard off. - The input guards, first: one play expects the failure message containing `unauthenticated Traefik dashboard` (the dashboard guard: enabled without valid `user:hash` users); the next expects `collides with the middleware`, raised by the dashboard-auth collision assert, which runs whenever users are set, also with the dashboard off.
- The install: the pinned version runs, and only the binary is left from the archive. - The install: the pinned version runs, and only the binary is left from the archive.
@@ -94,6 +94,7 @@ The scenario disables the namespace-based sandboxing and the `User=` switch with
## Notes ## Notes
- Idempotent: yes. - Idempotent: yes.
- Check mode: `--check` is the supported preview; a play-level `check_mode: true` is not supported. On a host without the Traefik binary, the ACME file permissions, the service start and its running check, the `Restart Traefik` handler and the `traefik_update` tasks are skipped under `--check`, because nothing is extracted and the unit file is only simulated.
- The role is not a state selector. `main.yml` runs prerequisites and configure unless `traefik_remove` is true; install runs only when the binary is absent; update only when `traefik_update` is true; remove only when `traefik_remove` is true, and then every other task in `main.yml` is skipped. - The role is not a state selector. `main.yml` runs prerequisites and configure unless `traefik_remove` is true; install runs only when the binary is absent; update only when `traefik_update` is true; remove only when `traefik_remove` is true, and then every other task in `main.yml` is skipped.
- Download integrity: the archive SHA-256 must appear in the release's checksum file or the play fails. - Download integrity: the archive SHA-256 must appear in the release's checksum file or the play fails.
- Secrets: `traefik.env` (mode 0600, root) and `dynamic.yml` are rendered with `no_log: true`, and no backups are kept, so `--diff` never shows them. `dynamic.yml` may hold dashboard htpasswd hashes. - Secrets: `traefik.env` (mode 0600, root) and `dynamic.yml` are rendered with `no_log: true`, and no backups are kept, so `--diff` never shows them. `dynamic.yml` may hold dashboard htpasswd hashes.
+2
View File
@@ -9,3 +9,5 @@
ansible.builtin.systemd: ansible.builtin.systemd:
name: traefik name: traefik
state: restarted state: restarted
# Under --check on a first install there is no unit to restart yet.
when: not ansible_check_mode or traefik_installed | bool
+1
View File
@@ -10,6 +10,7 @@ galaxy_info:
- name: Ubuntu - name: Ubuntu
versions: versions:
- noble - noble
- resolute
galaxy_tags: galaxy_tags:
- traefik - traefik
- reverseproxy - reverseproxy
+25 -4
View File
@@ -1,8 +1,9 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). Needs outbound network, unlike most # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# scenarios: the role installs packages with apt and downloads Traefik releases from GitHub. No # .gitea/workflows/molecule.yml. Needs outbound network, unlike most scenarios: the role installs
# privileged mode: systemd needs a writable cgroup and the firewall tools need NET_ADMIN. # packages with apt and downloads Traefik releases from GitHub. No privileged mode: systemd needs a
# writable cgroup and the firewall tools need NET_ADMIN.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -23,6 +24,23 @@ platforms:
- NET_ADMIN - NET_ADMIN
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-traefik-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
capabilities:
- NET_ADMIN
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
# One source for every play in converge.yml and verify.yml. The role renders traefik.yml before # One source for every play in converge.yml and verify.yml. The role renders traefik.yml before
@@ -50,13 +68,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
@@ -14,6 +14,12 @@
hosts: all hosts: all
gather_facts: false gather_facts: false
tasks: tasks:
# The image ships without apt lists, and --check does not refresh them, so the fresh-host
# check finds the packages the role installs.
- name: Refresh the apt cache
ansible.builtin.apt:
update_cache: true
- name: Create the unit drop-in directory - name: Create the unit drop-in directory
ansible.builtin.file: ansible.builtin.file:
path: /etc/systemd/system/traefik.service.d path: /etc/systemd/system/traefik.service.d
+5 -1
View File
@@ -196,6 +196,8 @@
name: traefik name: traefik
enabled: true enabled: true
state: started state: started
# Under --check on a first install the unit file is only simulated, so systemd would not find it.
when: not ansible_check_mode or traefik_installed | bool
tags: [traefik, configure] tags: [traefik, configure]
- name: Check Traefik service status - name: Check Traefik service status
@@ -208,5 +210,7 @@
- name: Fail if Traefik service is not running - name: Fail if Traefik service is not running
ansible.builtin.fail: ansible.builtin.fail:
msg: "Traefik service is not running" msg: "Traefik service is not running"
when: traefik_service_status.status.ActiveState != "active" when:
- not ansible_check_mode or traefik_installed | bool
- traefik_service_status.status.ActiveState != "active"
tags: [traefik, configure, health] tags: [traefik, configure, health]
+5
View File
@@ -21,6 +21,7 @@
cmd: touch {{ traefik_acme_file }} cmd: touch {{ traefik_acme_file }}
args: args:
creates: "{{ traefik_acme_file }}" creates: "{{ traefik_acme_file }}"
register: __traefik_acme_touch
tags: [traefik, install, binary, update] tags: [traefik, install, binary, update]
- name: Ensure correct permissions on ACME file - name: Ensure correct permissions on ACME file
@@ -30,6 +31,8 @@
owner: "{{ traefik_user }}" owner: "{{ traefik_user }}"
group: "{{ traefik_user }}" group: "{{ traefik_user }}"
mode: "0600" mode: "0600"
# Under --check the touch above is skipped, and the file module fails on a missing file.
when: not ansible_check_mode or __traefik_acme_touch is not changed
tags: [traefik, install, binary, update] tags: [traefik, install, binary, update]
- name: Install the Traefik binary - name: Install the Traefik binary
@@ -49,4 +52,6 @@
that: that:
- traefik_binary.stat.exists - traefik_binary.stat.exists
fail_msg: "Traefik binary not found after extraction" fail_msg: "Traefik binary not found after extraction"
# Nothing is extracted under --check.
when: not ansible_check_mode
tags: [traefik, install, binary, health, update] tags: [traefik, install, binary, health, update]
+2
View File
@@ -63,4 +63,6 @@
when: when:
- traefik_update | bool - traefik_update | bool
- not (traefik_remove | default(false) | bool) - not (traefik_remove | default(false) | bool)
# Under --check on a first install no binary is extracted, so the update would try to swap a service that does not exist.
- not ansible_check_mode or traefik_installed | bool
tags: [traefik, update] tags: [traefik, update]
+4 -5
View File
@@ -4,9 +4,7 @@ Installs UFW and applies sysctl overrides, `/etc/ufw/before.rules`, default poli
## Supported platforms ## Supported platforms
Ubuntu 24.04 (noble), the platform the molecule scenario runs on. Ubuntu 24.04 (noble) and 26.04 (resolute), the platforms the molecule scenario runs on.
Untested platforms: Ubuntu 22.04 (jammy), listed in `meta/main.yml` but not verified by a test.
Ubuntu hosts only: the role firewalls Ubuntu guests; the `pve` profile of `system_baseline` does not install ufw, so Proxmox hosts are not targeted. Ubuntu hosts only: the role firewalls Ubuntu guests; the `pve` profile of `system_baseline` does not install ufw, so Proxmox hosts are not targeted.
@@ -138,7 +136,7 @@ Skipping `ufw_aggregate` leaves the lists the later tasks read (`ufw_aggregated_
## Tests ## Tests
The scenario `molecule/default/` runs in CI only, on one platform: `${MOLECULE_IMAGE}`, an Ubuntu 24.04 (noble) container with `NET_ADMIN`. The sequence runs prepare, converge, idempotence and verify; it has no check-mode step. The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_IMAGE}` (Ubuntu 24.04) and `${MOLECULE_IMAGE_2604}` (Ubuntu 26.04). Both containers get `NET_ADMIN`. The sequence runs prepare, `check` before the converge (fresh host), converge, `check` after it (configured host), idempotence and verify.
- Prepare installs ufw and stores rules the role must handle: an untagged manual rule, a manual rule the base list deletes, and tagged rules of service owners that are stale, removed or orphaned, some of them looking like an SSH path (port 22 with a source, no port, a range, an application profile named like SSH). - Prepare installs ufw and stores rules the role must handle: an untagged manual rule, a manual rule the base list deletes, and tagged rules of service owners that are stale, removed or orphaned, some of them looking like an SSH path (port 22 with a source, no port, a range, an application profile named like SSH).
- Converge applies the base `ufw_rules` (one entry with `delete: true`), then calls `service_rules` for several owners (purge on, purge off, `absent`), and `orphan_rules` with no list, an empty list, report only and purge. - Converge applies the base `ufw_rules` (one entry with `delete: true`), then calls `service_rules` for several owners (purge on, purge off, `absent`), and `orphan_rules` with no list, an empty list, report only and purge.
@@ -147,7 +145,7 @@ The scenario `molecule/default/` runs in CI only, on one platform: `${MOLECULE_I
- Verify checks `before.rules`: the loopback accept, the INVALID-state drop behind its logging rule and in its place among the input rules. - Verify checks `before.rules`: the loopback accept, the INVALID-state drop behind its logging rule and in its place among the input rules.
- Verify runs `service_rules` under the `check_mode` keyword and checks that the rule list did not change. - Verify runs `service_rules` under the `check_mode` keyword and checks that the rule list did not change.
Not covered: `ufw_before_rules` entries and `ufw_sysctl_overrides` are never set, and `orphan_rules` is not run in check mode. Not covered: `ufw_before_rules` entries and `ufw_sysctl_overrides` are never set, and `orphan_rules` runs in check mode only under `--check` (the `check` steps), not under the `check_mode` keyword.
## Notes ## Notes
@@ -158,4 +156,5 @@ Not covered: `ufw_before_rules` entries and `ufw_sysctl_overrides` are never set
- Rule schema is asserted before anything changes: `rule` must be allow, deny, reject or limit, `port` a positive integer, `proto` tcp or udp, and each rule needs `port`, `from`, `to` or `interface`. - Rule schema is asserted before anything changes: `rule` must be allow, deny, reject or limit, `port` a positive integer, `proto` tcp or udp, and each rule needs `port`, `from`, `to` or `interface`.
- UFW is only re-enabled when `ufw status verbose` shows it inactive or the logging line differs, because the module rewrites rules and re-applies sysctl on every call. - UFW is only re-enabled when `ufw status verbose` shows it inactive or the logging line differs, because the module rewrites rules and re-applies sysctl on every call.
- The `Reload UFW` handler runs `ufw reload`. - The `Reload UFW` handler runs `ufw reload`.
- Check mode: `--check` previews a host where ufw is already installed; a play-level `check_mode: true` is not supported. On a host without ufw it fails at the default policy tasks: the package is not installed under `--check`, and the module needs the `ufw` binary.
- `no_log` is not used: the role handles no secrets. - `no_log` is not used: the role handles no secrets.
+1 -1
View File
@@ -9,8 +9,8 @@ galaxy_info:
platforms: platforms:
- name: Ubuntu - name: Ubuntu
versions: versions:
- jammy
- noble - noble
- resolute
galaxy_tags: galaxy_tags:
- firewall - firewall
- ufw - ufw
+2 -2
View File
@@ -110,8 +110,8 @@
# svc_o2 that looks like the SSH rule, and a rule of svc_m. The managed owners below are # svc_o2 that looks like the SSH rule, and a rule of svc_m. The managed owners below are
# the ones used above plus svc_m (listed but never called), so svc_o1 and svc_o2 are # the ones used above plus svc_m (listed but never called), so svc_o1 and svc_o2 are
# orphans. The cases that must change nothing run first and the purge last, so the # orphans. The cases that must change nothing run first and the purge last, so the
# idempotence run finds nothing left to delete. Check mode is not exercised: whether it # idempotence run finds nothing left to delete. Under --check the role's own skipped probe
# reaches the tasks of an include_role is not verified. # keeps the purge from deleting, and orphan_check.yml skips its counts.
- name: Report and purge the rules of unmanaged owners - name: Report and purge the rules of unmanaged owners
hosts: all hosts: all
gather_facts: false gather_facts: false
+24 -3
View File
@@ -1,7 +1,8 @@
--- ---
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404 image # Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
# (MOLECULE_IMAGE, the pin in .gitea/workflows/molecule.yml). No privileged mode: systemd needs a # (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
# writable cgroup and the firewall tools need NET_ADMIN, nothing else. # .gitea/workflows/molecule.yml. No privileged mode: systemd needs a writable cgroup and the
# firewall tools need NET_ADMIN, nothing else.
driver: driver:
name: docker name: docker
platforms: platforms:
@@ -22,6 +23,23 @@ platforms:
- NET_ADMIN - NET_ADMIN
security_opts: security_opts:
- apparmor=unconfined - apparmor=unconfined
- name: ${KAMINO_RUN_ID:-local}-ufw-2604-instance
labels:
net.rkdr.mortis.molecule-run: "${KAMINO_RUN_ID:-local}"
image: ${MOLECULE_IMAGE_2604}
pre_build_image: true
pull: true
command: /sbin/init
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
capabilities:
- NET_ADMIN
security_opts:
- apparmor=unconfined
provisioner: provisioner:
name: ansible name: ansible
verifier: verifier:
@@ -29,13 +47,16 @@ verifier:
scenario: scenario:
# molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the # molecule's default sequence minus both destroys: scripts/run_molecule_scenarios.sh removes the
# container as soon as this scenario ends. After a local run, run `molecule destroy` yourself. # container as soon as this scenario ends. After a local run, run `molecule destroy` yourself.
# A check runs before the converge (fresh host) and after it (configured host).
test_sequence: test_sequence:
- dependency - dependency
- cleanup - cleanup
- syntax - syntax
- create - create
- prepare - prepare
- check
- converge - converge
- check
- idempotence - idempotence
- side_effect - side_effect
- verify - verify
@@ -10,6 +10,7 @@
changed_when: false changed_when: false
environment: {LC_ALL: C} environment: {LC_ALL: C}
# Under --check (molecule's check step) nothing was applied or purged, so the counts do not hold.
- name: The seeds are as this case leaves them - name: The seeds are as this case leaves them
ansible.builtin.assert: ansible.builtin.assert:
that: that:
@@ -25,3 +26,4 @@
quiet: true quiet: true
vars: vars:
ufw_conv_o1_count: "{{ ufw_conv_o1_want | default(ufw_conv_o1_initial) }}" ufw_conv_o1_count: "{{ ufw_conv_o1_want | default(ufw_conv_o1_initial) }}"
when: not ansible_check_mode
Loaded 100 of 105 files, more files were not shown because too many files have changed in this diff. Show more