Compare commits
44
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
258cbaf516 | ||
|
|
41820fd9a7 | ||
|
|
e8f739904a | ||
|
|
040dd9fbf2 | ||
|
|
edf31df045 | ||
|
|
6070179126 | ||
|
|
2b221b69a5 | ||
|
|
ec972b90a4 | ||
|
|
922a79a871 | ||
|
|
ac8967f6a5 | ||
|
|
8548ab8c9d | ||
|
|
06853aa6f6 | ||
|
|
035669c26f | ||
|
|
ca62d4aaa8 | ||
|
|
2b2e2c4021 | ||
|
|
876ff2ada5 | ||
|
|
dbcbf3b02d | ||
|
|
53f5df4378 | ||
|
|
40d5c49e33 | ||
|
|
4201300291 | ||
|
|
0779e8b5c7 | ||
|
|
f766666476 | ||
|
|
7bc3cc6bdf | ||
|
|
2865573429 | ||
|
|
be8c3f2ed9 | ||
|
|
716baa19c7 | ||
|
|
0961dfdff4 | ||
|
|
cdc5937e45 | ||
|
|
cd46e9dfb4 | ||
|
|
8c3f9c4594 | ||
|
|
c109d24229 | ||
|
|
faf1c7e36f | ||
|
|
b5a5a4efa1 | ||
|
|
c0c1485470 | ||
|
|
92cf7257d4 | ||
|
|
e34a0eb2e0 | ||
|
|
ef840c8952 | ||
|
|
29db4985fe | ||
|
|
1fedced1d3 | ||
|
|
a2ab13a6e1 | ||
|
|
a185a301db | ||
|
|
c7c38c6bc0 | ||
|
|
fcd2290e14 | ||
|
|
5ce5e3c932 |
No files matched your search
@@ -3,6 +3,11 @@
|
||||
# first on ANSIBLE_COLLECTIONS_PATH, so molecule's per-scenario install is unused.
|
||||
prerun: false
|
||||
provisioner:
|
||||
# Merged over the docker driver's own connection vars, for the container hosts only: localhost
|
||||
# keeps the controller's Python.
|
||||
connection_options:
|
||||
# Both molecule images ship it; a fixed path skips interpreter discovery in every playbook run.
|
||||
ansible_python_interpreter: /usr/bin/python3
|
||||
config_options:
|
||||
connection:
|
||||
# Pipe each module over stdin: without it every task pays extra docker exec and docker cp
|
||||
@@ -11,3 +16,9 @@ provisioner:
|
||||
defaults:
|
||||
# Gather each host's facts once per playbook run, not in every play.
|
||||
gathering: smart
|
||||
# Per-task timings, to see what a scenario's time goes to; ansible.posix is in the ci image
|
||||
# and in requirements.yml, so the controller always has these callbacks.
|
||||
callbacks_enabled: ansible.posix.profile_tasks, ansible.posix.timer
|
||||
callback_profile_tasks:
|
||||
summary_only: true
|
||||
task_output_limit: 20
|
||||
@@ -110,12 +110,20 @@ issue.
|
||||
concurrency group of its own.** Runs may overlap on the runner's Docker daemon: every container
|
||||
is named and labelled by its run (`KAMINO_RUN_ID`). The job first removes labelled containers
|
||||
older than its timeout, which a cancelled run left, and finally its own. The scenarios of one
|
||||
run overlap (`scripts/run_molecule_scenarios.sh`, `MOLECULE_LANES` at a time), so no two
|
||||
scenarios may share a platform name. *Why:* a cancelled run is killed before it can remove its
|
||||
instances, and a younger container may belong to a run still going. *Held:* review; control:
|
||||
the names and labels by the test the `test_sequence` rule below names, and the sweep's age bound
|
||||
equal to the job timeout by `test_the_sweep_spares_containers_younger_than_the_job_timeout` in
|
||||
`tests/scripts/test_run_molecule_scenarios.py`.
|
||||
run overlap (`scripts/run_molecule_scenarios.sh`, `MOLECULE_LANES` at a time, 2 unless a manual
|
||||
dispatch sets its `lanes` input), so no two scenarios may share a platform name. They start
|
||||
longest first by the script's list of last full-run times, an unlisted one first; the logs stay
|
||||
in selection order. A scenario still running at the script's per-scenario limit is stopped and
|
||||
fails. *Why:* a cancelled run is killed before it can remove its instances, a younger container
|
||||
may belong to a run still going, a long scenario started late sets the end of the run, and a
|
||||
hang that fails alone inside the job timeout still lets every scenario's log print. *Held:*
|
||||
review; control: the start order by `test_the_longest_scenarios_start_first` and the input by
|
||||
`LanesInputTest`, both in `tests/scripts/test_run_molecule_scenarios.py`; control: the names and
|
||||
labels by the test the `test_sequence` rule below names, and the sweep's age bound equal to the
|
||||
job timeout by `test_the_sweep_spares_containers_younger_than_the_job_timeout` in
|
||||
`tests/scripts/test_run_molecule_scenarios.py`; control: the limit by
|
||||
`test_a_scenario_past_its_time_limit_fails_alone` and
|
||||
`test_the_default_time_limit_is_inside_the_job_timeout`, in the same file.
|
||||
- **Molecule tests the pull request's pins, as Lint and Build do.** It runs molecule in the pinned
|
||||
`ci` image and, when a pin file differs from `/opt/ci-pins.sha256`, installs the pull request's
|
||||
tools and the collections of `requirements.yml` and `extensions/molecule/requirements.yml` first.
|
||||
|
||||
@@ -24,7 +24,13 @@ on: # yamllint disable-line rule:truthy
|
||||
# drift in the others (a package mirror) would otherwise go unseen. After Renovate's 03:17 run.
|
||||
schedule:
|
||||
- cron: "43 4 * * *"
|
||||
workflow_dispatch: {}
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
lanes:
|
||||
description: Scenarios run at a time (empty for the default of run_molecule_scenarios.sh)
|
||||
required: false
|
||||
type: string
|
||||
default: ""
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
@@ -123,6 +129,8 @@ jobs:
|
||||
EVENT_NAME: ${{ github.event_name }}
|
||||
# The workflow only runs for pull requests to main; lint.yml uses the same constant.
|
||||
BASE_REF: origin/main
|
||||
# Empty outside a dispatch, which the run script reads as its default.
|
||||
MOLECULE_LANES: ${{ inputs.lanes }}
|
||||
run: |
|
||||
# The selector comes from the base branch, so a pull request cannot edit the rules it is
|
||||
# judged by (lint.yml does the same for check_bot_pr_diff.py); the first pull request that
|
||||
@@ -154,7 +162,7 @@ jobs:
|
||||
-v /var/run/docker.sock:/var/run/docker.sock -v "$docker_cli:/usr/local/bin/docker:ro" \
|
||||
-v "$ac_root:$ac_root" -v "$ac_root/passwd:/etc/passwd:ro" -w "$PWD" \
|
||||
-e "AC_ROOT=$ac_root" -e "HOME=$ac_root/home" -e "USER=$(id -un)" \
|
||||
-e MOLECULE_IMAGE -e MOLECULE_IMAGE_2604 -e KAMINO_RUN_ID \
|
||||
-e MOLECULE_IMAGE -e MOLECULE_IMAGE_2604 -e KAMINO_RUN_ID -e MOLECULE_LANES \
|
||||
"$CI_IMAGE" scripts/run_molecule_in_ci_image.sh <<< "$selected"
|
||||
|
||||
# A cancelled run can leave its containers running when the docker client is killed.
|
||||
|
||||
+2
-1
@@ -13,10 +13,11 @@ vault-pass*
|
||||
gitleaks-report.json
|
||||
# galaxy-importer output
|
||||
importer_result.json
|
||||
# APM: apm_modules/ is the dependency cache. Deployed skills and agents stay out
|
||||
# APM: apm_modules/ is the dependency cache. Deployed skills, agents and commands stay out
|
||||
# while their source is private; deployed hooks are committed for review.
|
||||
apm_modules/
|
||||
.claude/skills/
|
||||
.claude/agents/
|
||||
.claude/commands/
|
||||
# Claude Code: personal settings and allowlists, never shared
|
||||
.claude/settings.local.json
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
An Ansible Collection of reusable, hardened roles for a self-hosted home lab:
|
||||
`cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`,
|
||||
`pihole`, `pve_lxc`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`, `ufw` and
|
||||
`nfs_client`, `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).
|
||||
|
||||
Status: roles arrive in waves. Release 3.2.0 holds the `cloudflared`, `docker`, `fail2ban`, `gitea`, `gitea_runner`, `network_interfaces`, `pihole`, `pve_lxc`, `sshd`, `system_baseline`, `systemd_hardening`, `tailscale`, `traefik`, `ufw` and `user_management` roles (and the internal `_binary_update`, which `cloudflared`, `gitea`, `gitea_runner` and `traefik` call).
|
||||
|
||||
+66
-25
@@ -1,6 +1,8 @@
|
||||
lockfile_version: '1'
|
||||
generated_at: '2026-11-22T17:33:38.751913+00:00'
|
||||
apm_version: 0.36.1
|
||||
lockfile_version: '4'
|
||||
generated_at: '2026-11-28T18:36:35.416410+00:00'
|
||||
apm_version: 0.38.1
|
||||
manifest_targets:
|
||||
- claude
|
||||
dependencies:
|
||||
- repo_url: Mortis/Holocron
|
||||
name: git
|
||||
@@ -133,7 +135,11 @@ dependencies:
|
||||
.claude/skills/pc-run/references/failure-patterns.md: sha256:c760a933a937d5c33206f918089a49afd8335de3854093f5c32494e71019378c
|
||||
.claude/skills/pc-run/references/install.md: sha256:71ec08d58b8797b09574a827ea06d2c9656e3394d40534860fdaf333f5c19070
|
||||
.claude/skills/pc-run/references/sources.md: sha256:ed47302b3fa003ca203cf6677905032f687ff5e07e3d551593865116d9ce11f1
|
||||
content_hash: sha256:3fe59051e46ae66e09a62b121342e619720f3a669f9c25b2c1ed7bf7a537f646
|
||||
content_hash: sha256:db45863914da8edc054526af825a3c2354584340f1e46d123b407053587cf05a
|
||||
package_targets:
|
||||
- claude
|
||||
- codex
|
||||
- copilot
|
||||
declared_license: MIT
|
||||
carried_licenses:
|
||||
- path: .apm/skills/git-branches/LICENSE
|
||||
@@ -174,7 +180,33 @@ dependencies:
|
||||
virtual_path: plugins/mattpocock
|
||||
is_virtual: true
|
||||
package_type: apm_package
|
||||
content_hash: sha256:91649428cf594bd911beb982282f92f7b732908db649d484e420c0ba1d6b6b7b
|
||||
content_hash: sha256:2beb7db4336947eeb77c4f8f6ec390ee6a4bdb2ec843d2ecc9bf53b89aafc7f3
|
||||
package_targets:
|
||||
- claude
|
||||
- codex
|
||||
- copilot
|
||||
declared_license: MIT
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
hash: sha256:9d3692e6b35e0e43b81e096352f11c6b884e7004d78d3dcd92768232c6704525
|
||||
- repo_url: Mortis/Holocron
|
||||
name: plan
|
||||
host: git.rkdr.net
|
||||
resolved_commit: e4abbd06dfcbe63100e8fa6db958d029f98b55ff
|
||||
version: 0.1.0
|
||||
virtual_path: plugins/plan
|
||||
is_virtual: true
|
||||
package_type: apm_package
|
||||
deployed_files:
|
||||
- .claude/commands/next.md
|
||||
deployed_file_hashes:
|
||||
.claude/commands/next.md: sha256:12668ef795442d3ced640a2177cabf8df0e046381939a607784006e945bbb4a5
|
||||
content_hash: sha256:a788fa15fbc21c6a78418ed164d1cea93b919d9fc21d91b6736ba6d3a9fe065e
|
||||
package_targets:
|
||||
- claude
|
||||
- codex
|
||||
- copilot
|
||||
declared_license: MIT
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
@@ -200,7 +232,7 @@ dependencies:
|
||||
.claude/skills/code-review/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/code-review/SKILL.md: sha256:9c921a8d88138a41401d8897ca1bb852088ab1b7b605cdd04edc13e3e8aab6dd
|
||||
.claude/skills/code-review/agents/openai.yaml: sha256:8229ca854e11dc8e6aef2131ee03f31fb1561cf905fab9ccc325180cf3331352
|
||||
content_hash: sha256:cf233fee7275f8d00b5d2f11da948738531eee9ae7cc8d5b13f815f39fef1c9f
|
||||
content_hash: sha256:e14d83d727f514a484858272f5a45d83d42ba7f84c078758a0341ffe6e8832e5
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -229,7 +261,7 @@ dependencies:
|
||||
.claude/skills/codebase-design/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/codebase-design/SKILL.md: sha256:2c20617f87ec8af6a434859f381b2f061a69b530444e74eb39e78bb016a6d1e2
|
||||
.claude/skills/codebase-design/agents/openai.yaml: sha256:edebc9e4fcfe102114012575eaa9600b9b5fd08c311664f389c36e7bc717740f
|
||||
content_hash: sha256:667012327c54634ddc0fea22ccdf5d43c797b97038a6d4aadc09de29d50d0185
|
||||
content_hash: sha256:0eece2d6148eede9eebea3989944ea6215b809204352ca82a3a83203b79b78b4
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -256,7 +288,7 @@ dependencies:
|
||||
.claude/skills/diagnosing-bugs/SKILL.md: sha256:849198df88cdb65fd0d97236604c1fca7ff2f22d2f705f9724a800d0266b118d
|
||||
.claude/skills/diagnosing-bugs/agents/openai.yaml: sha256:3e430dbe4334a87597488c060cb3dc3786bb00c9182877d6f5ec41f62490e90b
|
||||
.claude/skills/diagnosing-bugs/scripts/hitl-loop.template.sh: sha256:35103539fc36873eea36074769ad454f9379d6fc8b2dc0e26ce987fd3bfe5503
|
||||
content_hash: sha256:9b24ecaf15dd8d5594f973c590c6904d90dd3b50f8853fefd2341b7fd4a156bf
|
||||
content_hash: sha256:eb364bd413d5b65ec3360466dfc8fe36a2f6c6de6a2c84a3b39bbf60fdbc120d
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -285,7 +317,7 @@ dependencies:
|
||||
.claude/skills/domain-modeling/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/domain-modeling/SKILL.md: sha256:7b925d7b1e341a2eeae33ad68a8a8c0ab889a38ddd22a7598e4c240e5a7556a3
|
||||
.claude/skills/domain-modeling/agents/openai.yaml: sha256:f6bf2aa996c6e6f53fdd0708e18a0d16a56aed8322cca59fedbe3c0d2c75f06b
|
||||
content_hash: sha256:467f5e92529c2a4637440dce99841814b0864a8528714188ec91b78d900df540
|
||||
content_hash: sha256:ab7acbca5aaf6e976caef1ccd1c14bac9459702f5b8e9d6d96e5a8ca8e3c7ee9
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -310,7 +342,7 @@ dependencies:
|
||||
.claude/skills/grill-with-docs/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/grill-with-docs/SKILL.md: sha256:7de372c13488f1ee96cc11cd8907b56b6809cc93eef776eeddd37de6b6cbe3fe
|
||||
.claude/skills/grill-with-docs/agents/openai.yaml: sha256:94cd0ab161fb468a836349f5ed482ba58ce8e709a05c57ce533d739dbd35cca9
|
||||
content_hash: sha256:9e8f732b806727978f1ad8d2fb9ce4467da68f7482d63c4bb5a73f2b1a0c797c
|
||||
content_hash: sha256:8973c3d9463fc9dd708adc36a0f97b01aab4ae7d6a0217c2aa0f0a7ef206b83c
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -335,7 +367,7 @@ dependencies:
|
||||
.claude/skills/implement/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/implement/SKILL.md: sha256:483bdc4ccf4ac31d86ac7beeaa0d0db80313e71e120bb8c59b3196ae5decd53d
|
||||
.claude/skills/implement/agents/openai.yaml: sha256:8970a8596ade0c28ab427f41a4ea242d6bdf6186c59ebf55e1238dbecaab79dc
|
||||
content_hash: sha256:c7c4d38c8dd9a05fcad046f79aeb275c7f31a87d7bceb4f3a133f125e6f4bfbb
|
||||
content_hash: sha256:3465060b2e4776f9e791293720a66869f265c83f9a5323e3ab0115f0558cc65b
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -360,7 +392,7 @@ dependencies:
|
||||
.claude/skills/implement-spec/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/implement-spec/SKILL.md: sha256:8d8300f7f12325dbfc99cad124a4bcc96ac0d02d0b2d73dfb348e9262afacfc4
|
||||
.claude/skills/implement-spec/agents/openai.yaml: sha256:fd41efb42c60c96320d6531be7e4bf15cbf5518cd652d57dff27ccffa46988e9
|
||||
content_hash: sha256:254a8c69719a6644fc462085569251b3fc8365770428738fc7bbb5398a3aa1fb
|
||||
content_hash: sha256:e4d15f81cc620dc479ffe852de453e47090f79edde7dcfe912de64018b183256
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -387,7 +419,7 @@ dependencies:
|
||||
.claude/skills/improve-codebase-architecture/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/improve-codebase-architecture/SKILL.md: sha256:35b03a3db61e0f5aa333ea59b54963e45a3d2ace6649b2ef4f9576603e2582a6
|
||||
.claude/skills/improve-codebase-architecture/agents/openai.yaml: sha256:c8cb20f68ebf0edb4e497bc11ae5fcaa196004e661cd189015b04f4109ced7f1
|
||||
content_hash: sha256:499043a54914592b8d40160e0ecae3787452869aed4fce50c3e574c1926329d8
|
||||
content_hash: sha256:3c72a8a3852beda9b28b6a14ce665506ea57a59a76568cf826873ec17d798c5a
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -416,7 +448,7 @@ dependencies:
|
||||
.claude/skills/prototype/SKILL.md: sha256:714de632d116bb73f65cdb5a882db15b9369a6713b9a47c0fad827848f0bfbe3
|
||||
.claude/skills/prototype/UI.md: sha256:723211e878acbc7b6ff09755263f3295cde724ba902ff0064da41eed51d45ad3
|
||||
.claude/skills/prototype/agents/openai.yaml: sha256:5af65e43ab41a350436697b81e27b7f848d36782043b73c322bb2c9fa9cc55dc
|
||||
content_hash: sha256:090ae76b97353255ca29be783d69bcc1029e0195bdf43118d0b6f7ea9acc89b0
|
||||
content_hash: sha256:6890ef757ada4b0b571e74c28b69fda697ba2e18f564860f4c9373cbbe50535c
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -441,7 +473,7 @@ dependencies:
|
||||
.claude/skills/research/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/research/SKILL.md: sha256:1f629e18ab899412683bc6a1c4efb4339999e27c2fdac328f26ee10a8c031d33
|
||||
.claude/skills/research/agents/openai.yaml: sha256:9b4c470d63221c1f68f22df70b83e2f12401b317babe0d1b7b5f24a974474d0d
|
||||
content_hash: sha256:34a7c3808288b05ea422affe978ee4d301239817d822f4f50687f1957c17cf9a
|
||||
content_hash: sha256:4a52e8e17a984526a0f3f25bc138097b4ca8b5f15e35b7c318fa024c6b04e0fd
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -466,7 +498,7 @@ dependencies:
|
||||
.claude/skills/retro/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/retro/SKILL.md: sha256:33fbc28568e3146f20fd908b12998bc0ab30aa4f4c87288199a40793efa94696
|
||||
.claude/skills/retro/agents/openai.yaml: sha256:cb6fb9d7e6b4be5975f41f6def1dd00a1255bad5d9b02696b124c924a8b8745c
|
||||
content_hash: sha256:e13af4f6dfecd777815adde57811398dc59d0118692a70d996968b59e3d13db8
|
||||
content_hash: sha256:4d42bb16dc68325fe941153ff3341f8be8f770121479bc41921d477d27a45ad5
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -501,7 +533,7 @@ dependencies:
|
||||
.claude/skills/setup-matt-pocock-skills/issue-tracker-gitlab.md: sha256:947602d33a80f98f939fb990995b8f95a3459b114b919c4221d08bd75d7cffe0
|
||||
.claude/skills/setup-matt-pocock-skills/issue-tracker-local.md: sha256:7dcda20a2eb4bdc89b95d1143423c0691309921cadae3132e6424f371030506e
|
||||
.claude/skills/setup-matt-pocock-skills/triage-labels.md: sha256:ae512af838c78b8750471c42cd2b20fa32319553e61d84c9a23d171b40ce14aa
|
||||
content_hash: sha256:f8f92182cd38f90a66bc50b9408da5de83cbda1e4abaffbb8a7428beabcf6f5d
|
||||
content_hash: sha256:fb96a61c2698a9f4299778861547b92f11719d033d1cd5dea7e95a98fe8e438a
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -530,7 +562,7 @@ dependencies:
|
||||
.claude/skills/tdd/agents/openai.yaml: sha256:ea6f01cf1b8c06a4b0f5b649d74b1b8ce8685e72af1b38d70d877693e092af0b
|
||||
.claude/skills/tdd/mocking.md: sha256:3ceb807fdf4a47d6a93d4d9a891e5ba6d362a6247bd08adc451feebfc17361ef
|
||||
.claude/skills/tdd/tests.md: sha256:859f9e592c188fda4fc7277dd180e4ce9c7a2e13f6efe1f6f29eccc9d28c106a
|
||||
content_hash: sha256:ef3cbb31aa8b1f8a3f9b6a042c230dc9312019e84cdc6337f60890f177fd5764
|
||||
content_hash: sha256:cb510a538834fd446bae7cff1e6e46c4b625524d162bfc56c6d64486115a48e3
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -555,7 +587,7 @@ dependencies:
|
||||
.claude/skills/to-spec/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/to-spec/SKILL.md: sha256:43ad9cf318e5e7d3d1fa360253a37021796dc87a0c2e595ad262661a10f85088
|
||||
.claude/skills/to-spec/agents/openai.yaml: sha256:1c5b4d1e3d8e52287ef19cc2742fdbbfae1914ac75d33af3e4c8174f08cc55bb
|
||||
content_hash: sha256:cc5d718c2f810f4c9b081ea888af3ad3eb73bb8db6fc9fa92c3b1729637b7d56
|
||||
content_hash: sha256:7c0ac5892441627cbe76e8587d47cbe3adedc61f779df5c9f82d473588503330
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -580,7 +612,7 @@ dependencies:
|
||||
.claude/skills/to-tickets/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/to-tickets/SKILL.md: sha256:56ec23c5b2782785d4e65bff9e315b6d3aeb4ef977c174a219e99489fada1995
|
||||
.claude/skills/to-tickets/agents/openai.yaml: sha256:21bc6215fffcd7614e9f772bb1760e87cc5fc7dcc707e7d282bc9414267a6090
|
||||
content_hash: sha256:7cca8cd2afe55d1cd8bfc986df6a4cb4ad54411452575200804494b03c871ede
|
||||
content_hash: sha256:7e0aa33c2d0ccd99d92a7b45405243f7a948425e161723d4535f178ee0af3d59
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -609,7 +641,7 @@ dependencies:
|
||||
.claude/skills/triage/OUT-OF-SCOPE.md: sha256:1fbf9b432130c6380aa65813b55553cfda150309b27c595e183f8e335b8a190d
|
||||
.claude/skills/triage/SKILL.md: sha256:917b0baf74be583e74f110857ed45df2766617f75c00baf61fd136d7af515edf
|
||||
.claude/skills/triage/agents/openai.yaml: sha256:2e683717720cf456d165d0bb1a68bb600d0b6a8ccb61841c172e50d26f95351c
|
||||
content_hash: sha256:bf09f37fa24ab64324497772a25a1e0a9b22d06ccb238fefd0cfb12eee473c3d
|
||||
content_hash: sha256:cc3930f2f501738b67c5d3397518d537ffaf252c679bded57b090f2d31de0a22
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -634,7 +666,7 @@ dependencies:
|
||||
.claude/skills/wayfinder/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/wayfinder/SKILL.md: sha256:0c9fa96791aebf3b7d654cf35c6aadde97d81f57c17b07d13b27c14d9c46561f
|
||||
.claude/skills/wayfinder/agents/openai.yaml: sha256:88bc81a11a6d52ac67aeaa76b8b619e387020d47c5133a4dd4927fd15c4ad073
|
||||
content_hash: sha256:eec9b3ec0cd815b708670bf163384d257c7d1350ccb823f66043cbe138794298
|
||||
content_hash: sha256:92acbe1ee44d0ecd91e8ff08d09d8d78dabf8f2d5fa56ef3d977db1cb2a5457a
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -659,7 +691,7 @@ dependencies:
|
||||
.claude/skills/grill-me/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/grill-me/SKILL.md: sha256:caaf8b8de1684f96e26b28f3c29189db5c89cce4b73e1c93d86164f66ef88637
|
||||
.claude/skills/grill-me/agents/openai.yaml: sha256:c061e39c3e0f9d865fb1b97556d485704af2a8a58f4b8221a8917a5c2074a32b
|
||||
content_hash: sha256:fe33aaa8e8dcd606107b1bfe3109f257b4a7e0f4907afd6506b62ccfb73cd1d3
|
||||
content_hash: sha256:eb2880386e9259f4ca51167f518c81cea969850d8f45bd8f79f579dcbbad902e
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -684,7 +716,7 @@ dependencies:
|
||||
.claude/skills/grilling/LICENSE: sha256:0e7ac423bf2c6e223b7c5b156f8cf72da49d748e56a1641402c31f22ad07dbb5
|
||||
.claude/skills/grilling/SKILL.md: sha256:a146842ed93ca43d833550fa9adf02e58cb63c83fea9d4b4522995b82242d4e2
|
||||
.claude/skills/grilling/agents/openai.yaml: sha256:1411d7df7d99b7e621a1ff8283c8133cc2464be63d064e52d8ce169c6800ee9b
|
||||
content_hash: sha256:823f08ad33368a9626991e6782f7ae14b958e39ef8503f6bdb3b98a58d237a58
|
||||
content_hash: sha256:e0e4918ef2675bf3bc0e48fa83c40446cd961c107afdf435cbc2daa774cb0efe
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -711,7 +743,7 @@ dependencies:
|
||||
.claude/skills/writing-for-agents/SKILL-MECHANICS.md: sha256:c768e6307c7c10728c401c213f2c4ba71c542127eeb7ad2956aabd15a0fa0059
|
||||
.claude/skills/writing-for-agents/SKILL.md: sha256:551adca942227b44192edba88acd4e8db911f0121ce58ad16944ccf6a896a74a
|
||||
.claude/skills/writing-for-agents/agents/openai.yaml: sha256:eacb24b2a618cfb81dacb0416f4fdd75ddf3a8060f8ddb99aae1b1e301907e4b
|
||||
content_hash: sha256:8365ebe1d0c343d3d46970526f30fcf7c5e0c5e49fd39a3c882977024626ff3c
|
||||
content_hash: sha256:dfc57c19e0f7a7e9c371966d765700d74ecae7694377c095095ee94f6fd216b3
|
||||
carried_licenses:
|
||||
- path: LICENSE
|
||||
source: LICENSE
|
||||
@@ -726,6 +758,15 @@ deployments:
|
||||
- git.rkdr.net/Mortis/Holocron/plugins/git
|
||||
active_owner: git.rkdr.net/Mortis/Holocron/plugins/git
|
||||
content_hash: sha256:c9122bac28dc079efb041acc720dd097c62fdb49d9b1d9a62b15ac5ee6c47032
|
||||
- kind: project-relative
|
||||
target: claude
|
||||
value: .claude/commands/next.md
|
||||
runtime: null
|
||||
scope: project
|
||||
owners:
|
||||
- git.rkdr.net/Mortis/Holocron/plugins/plan
|
||||
active_owner: git.rkdr.net/Mortis/Holocron/plugins/plan
|
||||
content_hash: sha256:12668ef795442d3ced640a2177cabf8df0e046381939a607784006e945bbb4a5
|
||||
- kind: project-relative
|
||||
target: claude
|
||||
value: .claude/skills/code-review
|
||||
|
||||
@@ -3,8 +3,8 @@ version: 0.1.0
|
||||
description: Ansible Collection mortis.kamino. Consumer-side apm manifest for holocron skills.
|
||||
license: GPL-3.0-or-later
|
||||
|
||||
# git and mattpocock only (#104): bin and core are unused here, and gitea returns once it is
|
||||
# rebuilt on the tea CLI.
|
||||
# git, mattpocock and plan only (#104): bin and core are unused here, and gitea returns once it
|
||||
# is rebuilt on the tea CLI.
|
||||
|
||||
# Hook primitives come from apm; no instruction primitive is deployed until the root AGENTS.md
|
||||
# has a managed section. `apm approve` writes the executables.allow entry into this file, and it
|
||||
@@ -17,4 +17,6 @@ dependencies:
|
||||
path: plugins/git
|
||||
- git: https://git.rkdr.net/Mortis/Holocron.git
|
||||
path: plugins/mattpocock
|
||||
- git: https://git.rkdr.net/Mortis/Holocron.git
|
||||
path: plugins/plan
|
||||
mcp: []
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
minor_changes:
|
||||
- >-
|
||||
nfs_client - New role. Installs ``nfs-common`` and manages NFS mount entries in ``/etc/fstab`` from ``nfs_client_mounts``
|
||||
(``src``, ``path``, optional ``opts`` and ``state`` ``present`` or ``absent``), with ``nfs_client_default_opts``
|
||||
(default ``_netdev,nofail``) for an entry that sets none. It creates each mount point without owner, group or mode,
|
||||
writes only the fstab line, never mounts or unmounts, and reloads systemd after a change. An ``absent`` entry loses its
|
||||
line and nothing else. Declares Ubuntu noble and resolute; the molecule scenario never mounts a share.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
minor_changes:
|
||||
- >-
|
||||
docker - New input ``docker_keyring_checksum``: the Docker APT key is verified against a pinned
|
||||
sha256, and a changed key fails the install until a person has checked it and updated the hash.
|
||||
Set ``docker_keyring_checksum`` too when ``docker_gpg_url`` is overridden.
|
||||
@@ -0,0 +1,4 @@
|
||||
---
|
||||
trivial:
|
||||
- >-
|
||||
system_baseline - Purge the unwanted packages that are installed in one apt call instead of one call per package.
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
minor_changes:
|
||||
- >-
|
||||
traefik - The prerequisites install refreshes the APT cache only when it is older than an hour;
|
||||
before, every run refreshed it. A consumer who adds an APT source just before the role must
|
||||
refresh the cache first.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
trivial:
|
||||
- >-
|
||||
system_baseline - The registered results of the unattended-upgrades check and the reboot-required
|
||||
check carry the internal ``__system_baseline_`` prefix.
|
||||
+2
-2
@@ -7,7 +7,7 @@ authors:
|
||||
- Defame1297
|
||||
description: >-
|
||||
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, nfs_client, pihole, pve_lxc, sshd, system_baseline,
|
||||
systemd_hardening, tailscale, traefik, ufw, user_management; _binary_update is internal).
|
||||
license:
|
||||
- GPL-3.0-or-later
|
||||
@@ -22,7 +22,7 @@ homepage: https://git.rkdr.net/mortis/kamino
|
||||
issues: https://git.rkdr.net/mortis/kamino/issues
|
||||
# CI tests the versions pinned in requirements.yml; the lower bounds here are not tested.
|
||||
# No upper bound, so a consumer's newer pin does not conflict. community.general is used by system_baseline and ufw,
|
||||
# ansible.posix by system_baseline and user_management, community.proxmox by pve_lxc (Proxmox VE guest lifecycle).
|
||||
# ansible.posix by nfs_client, system_baseline and user_management, community.proxmox by pve_lxc (Proxmox VE guest lifecycle).
|
||||
# community.proxmox's modules import the Python library proxmoxer (2.3 or later) on the controller; galaxy.yml
|
||||
# cannot declare a Python dependency, so the README says it and requirements-dev.txt pins it for CI.
|
||||
dependencies:
|
||||
|
||||
@@ -27,6 +27,7 @@ The role targets Ubuntu hosts only: it installs from Docker's Ubuntu repository,
|
||||
| `docker_keyring_path` | `/etc/apt/keyrings/docker.asc` | no | Repository key location. |
|
||||
| `docker_apt_list_path` | `/etc/apt/sources.list.d/docker.list` | no | APT source file. |
|
||||
| `docker_gpg_url` | `https://download.docker.com/linux/ubuntu/gpg` | no | Key URL. |
|
||||
| `docker_keyring_checksum` | sha256 of the current Docker key | no | Expected sha256 (hex, no `sha256:` prefix) of the key at `docker_gpg_url`; set it too when `docker_gpg_url` is overridden; a mismatch fails the download, so a changed key stops the install until this is updated. |
|
||||
| `docker_repo_base_url` | `https://download.docker.com/linux/ubuntu` | no | Repository base URL. |
|
||||
| `docker_apt_arch` | derived from the host | no | Architecture in the APT source. Empty derives it (`x86_64` gives `amd64`, `aarch64` gives `arm64`); another architecture fails until this is set. A value set here is always used; lowercase letters and digits only. |
|
||||
| `docker_start_missed` | `false` | no | Install a boot unit that starts the containers Docker skipped after a reboot (see [Boot and shutdown units](#boot-and-shutdown-units)). |
|
||||
@@ -86,17 +87,18 @@ With any of `docker_daemon_options`, `docker_live_restore`, `docker_log_driver`,
|
||||
|
||||
## Tests
|
||||
|
||||
`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).
|
||||
`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`, `docker_keyring_checksum` (the throwaway key's hash) 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:
|
||||
|
||||
- The key is fetched, stored at `docker_keyring_path` with mode `0644`, and apt really verifies the repository against it (an unsigned or wrongly signed repository would leave no install candidate).
|
||||
- The key is fetched, checked against `docker_keyring_checksum`, stored at `docker_keyring_path` with mode `0644`, and apt really verifies the repository against it (an unsigned or wrongly signed repository would leave no install candidate).
|
||||
- The source line has the architecture, the `signed-by` keyring and `ansible_facts['distribution_release']`.
|
||||
- The packages are installed from that repository, the unit is enabled and active, and `docker_users` join `docker_group`.
|
||||
- `docker_remove` with `docker_remove_data` removes the source line, the keyring, the packages, the unit and `/var/lib/docker`.
|
||||
- Both units are installed, enabled, ordered against `docker.service` as stated, the shutdown unit is active, a unit is removed when its input is `false`, and `docker_remove` removes both.
|
||||
- With the daemon inputs set, `/etc/docker/daemon.json` is valid JSON with exactly the expected keys, mode `0644` and root-owned. A change with `docker_daemon_restart: false` leaves dockerd running (its start time is unchanged); with `true` it restarts it. A key set both in `docker_daemon_options` and by a dedicated input, and a bad log size, driver or file count, are refused before any change.
|
||||
- The argument check refuses a mapping for `docker_users`, a non-boolean `docker_remove` and a `docker_stop_at_shutdown_timeout` of 0.
|
||||
- A key whose hash does not match `docker_keyring_checksum` fails the key download.
|
||||
- A second run changes nothing (molecule's idempotence check).
|
||||
|
||||
What it does not show: what the units do at a real boot or shutdown (the container has no dockerd, no NFS shares and no reboot; the selection logic of `docker-start-missed` is unit-tested in `tests/scripts/test_docker_files.py`), that the upstream repository and key at `download.docker.com` are reachable and valid, that the real packages install, that `dockerd` starts, anything about container networking or iptables, the `docker_update` path (`tasks/update.yml`), and removal without `docker_remove_data` (the removal stops the unit first, so it can run only once per install). It needs the Ubuntu mirrors, for the `curl` the role installs. These gaps are a known residual risk of the role.
|
||||
|
||||
@@ -11,6 +11,10 @@ docker_packages:
|
||||
docker_keyring_path: /etc/apt/keyrings/docker.asc
|
||||
docker_apt_list_path: /etc/apt/sources.list.d/docker.list
|
||||
docker_gpg_url: https://download.docker.com/linux/ubuntu/gpg
|
||||
# sha256 of Docker's package signing key (9DC858229FC7DD38854AE2D88D81803C0EBFCD88), as the ASCII-armored file
|
||||
# docker_gpg_url serves. Static on purpose: a rotated or re-armored key fails the install until a person has checked the
|
||||
# new one and updated this hash.
|
||||
docker_keyring_checksum: "1500c1f56fa9e26b9b8f42452a553675796ade0807cdce11975eb98170b3a570"
|
||||
docker_repo_base_url: https://download.docker.com/linux/ubuntu
|
||||
|
||||
# Architecture written into the APT source. Empty (the default) derives it from the host: x86_64 gives amd64, aarch64 gives arm64, any
|
||||
|
||||
@@ -49,6 +49,14 @@ argument_specs:
|
||||
default: https://download.docker.com/linux/ubuntu/gpg
|
||||
description:
|
||||
- URL of the repository signing key.
|
||||
docker_keyring_checksum:
|
||||
type: str
|
||||
default: 1500c1f56fa9e26b9b8f42452a553675796ade0807cdce11975eb98170b3a570
|
||||
description:
|
||||
- >-
|
||||
sha256 of the key at C(docker_gpg_url), as the hex digest without the C(sha256:) prefix. The download fails
|
||||
on a mismatch, so a rotated or re-armored upstream key stops the install until the new key is checked and
|
||||
the hash updated. Set C(docker_keyring_checksum) too when C(docker_gpg_url) is overridden.
|
||||
docker_repo_base_url:
|
||||
type: str
|
||||
default: https://download.docker.com/linux/ubuntu
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
hosts: all
|
||||
vars:
|
||||
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
|
||||
# The stand-in key is generated per run, so its hash is read here rather than pinned.
|
||||
docker_keyring_checksum: "{{ docker_stub_key.stat.checksum }}"
|
||||
docker_repo_base_url: file:///srv/docker-stub-repo
|
||||
docker_users: [moleculeuser]
|
||||
docker_start_missed: true
|
||||
@@ -18,5 +20,11 @@
|
||||
docker_log_max_file: "3"
|
||||
docker_daemon_options:
|
||||
max-concurrent-downloads: 3
|
||||
pre_tasks:
|
||||
- name: Stat the stand-in repository key
|
||||
ansible.builtin.stat:
|
||||
path: /srv/docker-stub-repo/docker.asc
|
||||
checksum_algorithm: sha256
|
||||
register: docker_stub_key
|
||||
roles:
|
||||
- role: mortis.kamino.docker
|
||||
@@ -0,0 +1,27 @@
|
||||
---
|
||||
# The zeroed hash matches no file, so the key task must be the one that fails.
|
||||
- name: Run the role with a checksum the stand-in key does not have
|
||||
block:
|
||||
- name: Include the role
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
vars:
|
||||
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
|
||||
docker_repo_base_url: file:///srv/docker-stub-repo
|
||||
docker_keyring_path: /tmp/docker-refused-key.asc
|
||||
docker_keyring_checksum: "{{ '0' * 64 }}"
|
||||
- name: Fail when the wrong key was accepted
|
||||
ansible.builtin.fail:
|
||||
msg: MOLECULE-ACCEPTED
|
||||
rescue:
|
||||
- name: The key download stopped the play
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ansible_failed_task.name == 'Install Docker APT GPG key'
|
||||
- "'did not match' in ansible_failed_result.msg | default('')"
|
||||
quiet: true
|
||||
always:
|
||||
- name: Remove the refused key path
|
||||
ansible.builtin.file:
|
||||
path: /tmp/docker-refused-key.asc
|
||||
state: absent
|
||||
@@ -297,41 +297,7 @@
|
||||
changed_when: false
|
||||
failed_when: docker_verify_start_run.rc != 2
|
||||
|
||||
# Switching an input back to false removes that unit and script and leaves the other alone.
|
||||
- name: Verify that a unit is removed when its input is false
|
||||
hosts: all
|
||||
vars:
|
||||
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
|
||||
docker_repo_base_url: file:///srv/docker-stub-repo
|
||||
docker_users: [moleculeuser]
|
||||
docker_start_missed: false
|
||||
docker_stop_at_shutdown: true
|
||||
docker_stop_at_shutdown_timeout: 20
|
||||
tasks:
|
||||
- name: Apply the role with the boot unit off
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
|
||||
- name: Stat the boot unit's files and the shutdown unit's script
|
||||
ansible.builtin.stat:
|
||||
path: "{{ item }}"
|
||||
loop:
|
||||
- /usr/local/sbin/docker-start-missed
|
||||
- /etc/systemd/system/docker-start-missed.service
|
||||
- /usr/local/sbin/docker-stop-at-shutdown
|
||||
register: docker_verify_off
|
||||
|
||||
- name: The boot unit is gone and the shutdown unit is still there
|
||||
ansible.builtin.assert:
|
||||
that: docker_verify_off.results | map(attribute='stat.exists') | list == [false, false, true]
|
||||
quiet: true
|
||||
|
||||
- name: Apply the role again with both inputs on
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
vars:
|
||||
docker_start_missed: true
|
||||
|
||||
# Converge's daemon.json, read before the role runs below change it.
|
||||
- name: Verify the daemon settings
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
@@ -362,31 +328,43 @@
|
||||
- docker_verify_daemon_stat.stat.pw_name == 'root'
|
||||
quiet: true
|
||||
|
||||
# The stand-in docker.service runs for real, so a restart shows in its start time: a changed file with docker_daemon_restart false leaves
|
||||
# it alone, and with true restarts it.
|
||||
- name: Verify that dockerd restarts only when asked
|
||||
# The stand-in docker.service runs for real, so a restart shows in its start time. The first run turns the boot unit off and changes
|
||||
# daemon.json with docker_daemon_restart false: the unit goes, the other stays and dockerd keeps running. The second turns everything
|
||||
# back on with docker_daemon_restart true: the boot unit returns and dockerd restarts.
|
||||
- name: Verify the unit inputs and that dockerd restarts only when asked
|
||||
hosts: all
|
||||
vars:
|
||||
docker_gpg_url: file:///srv/docker-stub-repo/docker.asc
|
||||
docker_keyring_checksum: "{{ docker_stub_key.stat.checksum }}"
|
||||
docker_repo_base_url: file:///srv/docker-stub-repo
|
||||
docker_users: [moleculeuser]
|
||||
docker_start_missed: true
|
||||
docker_stop_at_shutdown: true
|
||||
docker_stop_at_shutdown_timeout: 20
|
||||
docker_log_driver: local
|
||||
docker_log_max_size: 10m
|
||||
docker_log_max_file: "3"
|
||||
docker_live_restore: true
|
||||
docker_verify_unit_paths:
|
||||
- /usr/local/sbin/docker-start-missed
|
||||
- /etc/systemd/system/docker-start-missed.service
|
||||
- /usr/local/sbin/docker-stop-at-shutdown
|
||||
tasks:
|
||||
- name: Stat the stand-in repository key
|
||||
ansible.builtin.stat:
|
||||
path: /srv/docker-stub-repo/docker.asc
|
||||
checksum_algorithm: sha256
|
||||
register: docker_stub_key
|
||||
|
||||
- name: Read the start time of the service
|
||||
ansible.builtin.command: systemctl show -p ActiveEnterTimestampMonotonic docker.service # noqa: command-instead-of-module
|
||||
register: docker_verify_before
|
||||
changed_when: false
|
||||
|
||||
- name: Apply a changed setting with docker_daemon_restart false
|
||||
- name: Apply the boot unit off and a changed setting with docker_daemon_restart false
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
vars:
|
||||
docker_start_missed: false
|
||||
docker_daemon_options: {max-concurrent-downloads: 5}
|
||||
docker_daemon_restart: false
|
||||
|
||||
@@ -395,10 +373,30 @@
|
||||
register: docker_verify_kept
|
||||
changed_when: false
|
||||
|
||||
- name: Apply another change with docker_daemon_restart true
|
||||
- name: Stat the boot unit's files and the shutdown unit's script
|
||||
ansible.builtin.stat:
|
||||
path: "{{ item }}"
|
||||
loop: "{{ docker_verify_unit_paths }}"
|
||||
register: docker_verify_off
|
||||
|
||||
- name: Read daemon.json
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/docker/daemon.json
|
||||
register: docker_verify_daemon_kept
|
||||
|
||||
- name: The boot unit is gone, the shutdown unit is still there, and the changed file left dockerd running
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- docker_verify_off.results | map(attribute='stat.exists') | list == [false, false, true]
|
||||
- (docker_verify_daemon_kept.content | b64decode | from_json)['max-concurrent-downloads'] == 5
|
||||
- docker_verify_kept.stdout == docker_verify_before.stdout
|
||||
quiet: true
|
||||
|
||||
- name: Apply both units on and another change with docker_daemon_restart true
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.docker
|
||||
vars:
|
||||
docker_start_missed: true
|
||||
docker_daemon_options: {max-concurrent-downloads: 6}
|
||||
docker_daemon_restart: true
|
||||
|
||||
@@ -407,19 +405,33 @@
|
||||
register: docker_verify_restarted
|
||||
changed_when: false
|
||||
|
||||
- name: Read daemon.json
|
||||
- name: Stat the unit files again
|
||||
ansible.builtin.stat:
|
||||
path: "{{ item }}"
|
||||
loop: "{{ docker_verify_unit_paths }}"
|
||||
register: docker_verify_on
|
||||
|
||||
- name: Read daemon.json again
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/docker/daemon.json
|
||||
register: docker_verify_daemon_after
|
||||
|
||||
- name: The first change left dockerd alone and the second restarted it
|
||||
- name: Both units are back and the second change restarted dockerd
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- docker_verify_kept.stdout == docker_verify_before.stdout
|
||||
- docker_verify_restarted.stdout != docker_verify_kept.stdout
|
||||
- docker_verify_on.results | map(attribute='stat.exists') | unique | list == [true]
|
||||
- (docker_verify_daemon_after.content | b64decode | from_json)['max-concurrent-downloads'] == 6
|
||||
- docker_verify_restarted.stdout != docker_verify_kept.stdout
|
||||
quiet: true
|
||||
|
||||
# A key that does not match docker_keyring_checksum fails at the key download, so the source line and packages are untouched. It goes to a separate path, so
|
||||
# the installed key stays for the removal below.
|
||||
- name: A key that does not match the pinned checksum is refused
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: Apply the role with a wrong checksum
|
||||
ansible.builtin.include_tasks: tasks/refuse_checksum.yml
|
||||
|
||||
# docker_remove_data is set, so this also covers the destructive path: the packages are
|
||||
# purged and /var/lib/docker, seeded in prepare.yml, is deleted. The removal stops the unit
|
||||
# before the package takes it away, so it can only run once; a second run would fail on the
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
ansible.builtin.get_url:
|
||||
url: "{{ docker_gpg_url }}"
|
||||
dest: "{{ docker_keyring_path }}"
|
||||
checksum: "sha256:{{ docker_keyring_checksum }}"
|
||||
mode: "0644"
|
||||
tags: [docker, install]
|
||||
|
||||
|
||||
@@ -359,23 +359,26 @@
|
||||
loop_var: gitea_runner_test_path
|
||||
|
||||
# 6.0.2 has a wrong checksum file (prepare.yml): the download must fail before anything is
|
||||
# stopped, so the runner keeps running 6.0.1.
|
||||
- name: Verify a failed download leaves the runner running
|
||||
# stopped, so the runner keeps running 6.0.1. The same run sets the disk threshold to 0: prune
|
||||
# runs before update, so the pressure units are already removed when the download fails.
|
||||
- name: Verify a failed download leaves the runner running, and turning the pressure prune off
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Update to a release whose checksum does not match
|
||||
block:
|
||||
- name: Include the role with gitea_runner_version 6.0.2
|
||||
- name: Include the role with gitea_runner_version 6.0.2 and the disk threshold at 0
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.gitea_runner
|
||||
vars:
|
||||
gitea_runner_version: 6.0.2
|
||||
gitea_runner_docker_prune_disk_threshold_percent: 0
|
||||
|
||||
- name: Fail because the include returned
|
||||
ansible.builtin.fail:
|
||||
msg: The role accepted a binary with a wrong checksum
|
||||
rescue:
|
||||
# The message comes only from the staging rescue, so a prune error fails this assert.
|
||||
- name: The staging failed, and nothing else failed first
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
@@ -407,6 +410,31 @@
|
||||
- not gitea_runner_test_staged.stat.exists
|
||||
quiet: true
|
||||
|
||||
- name: Stat the pressure units and script
|
||||
ansible.builtin.stat:
|
||||
path: "{{ gitea_runner_test_path }}"
|
||||
loop:
|
||||
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
|
||||
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
|
||||
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_path
|
||||
register: gitea_runner_test_pressure_off
|
||||
|
||||
- name: Ask systemd about the pressure timer after turning it off
|
||||
ansible.builtin.systemd:
|
||||
name: gitea-runner-docker-prune-pressure.timer
|
||||
register: gitea_runner_test_pressure_timer_off
|
||||
# The module errors for a unit that no longer exists, which is also a pass.
|
||||
failed_when: false
|
||||
|
||||
- name: The pressure units are gone and the timer is not active
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- gitea_runner_test_pressure_off.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
|
||||
- gitea_runner_test_pressure_timer_off.status.ActiveState | default('inactive') != 'active'
|
||||
quiet: true
|
||||
|
||||
# Each input assert, through the main entry point. Every one runs in validate.yml, before any
|
||||
# change.
|
||||
- name: Verify the input asserts
|
||||
@@ -448,8 +476,9 @@
|
||||
label: "{{ gitea_runner_test_refused.name }}"
|
||||
|
||||
# The CI guard and the mint-before-drop order of a forced re-registration, through a child
|
||||
# ansible-playbook against this instance (see force_register.yml). Neither case may touch the
|
||||
# registration or stop the runner.
|
||||
# ansible-playbook against one instance (see force_register.yml). Neither case may touch the
|
||||
# registration or stop the runner. The children run once: what they check is controller state
|
||||
# and group_vars, the same for every host, and run_once gives every host their results.
|
||||
- name: Verify the forced re-registration guards
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
@@ -465,6 +494,7 @@
|
||||
|
||||
- name: Force a re-registration under each CI variable, as a child process with only that one set
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- ansible-playbook
|
||||
@@ -497,6 +527,7 @@
|
||||
|
||||
- name: Force a re-registration outside CI with no token host, as a child process
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- ansible-playbook
|
||||
@@ -550,43 +581,12 @@
|
||||
- gitea_runner_test_unit.status.ActiveState == 'active'
|
||||
quiet: true
|
||||
|
||||
# A threshold of 0 removes the pressure units; the run after it, with the scenario's inputs,
|
||||
# The failed-download run above removed the pressure units; this run, with the scenario's inputs,
|
||||
# puts them back, so the remove path below still has them to remove.
|
||||
- name: Verify turning the pressure prune off
|
||||
- name: Verify turning the pressure prune on again
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Run the role with the disk threshold at 0
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.gitea_runner
|
||||
vars:
|
||||
gitea_runner_docker_prune_disk_threshold_percent: 0
|
||||
|
||||
- name: Stat the pressure units and script
|
||||
ansible.builtin.stat:
|
||||
path: "{{ gitea_runner_test_path }}"
|
||||
loop:
|
||||
- /etc/systemd/system/gitea-runner-docker-prune-pressure.service
|
||||
- /etc/systemd/system/gitea-runner-docker-prune-pressure.timer
|
||||
- /usr/local/sbin/gitea-runner-docker-prune-disk-check
|
||||
loop_control:
|
||||
loop_var: gitea_runner_test_path
|
||||
register: gitea_runner_test_pressure_off
|
||||
|
||||
- name: Ask systemd about the pressure timer after turning it off
|
||||
ansible.builtin.systemd:
|
||||
name: gitea-runner-docker-prune-pressure.timer
|
||||
register: gitea_runner_test_pressure_timer_off
|
||||
# The module errors for a unit that no longer exists, which is also a pass.
|
||||
failed_when: false
|
||||
|
||||
- name: The pressure units are gone and the timer is not active
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- gitea_runner_test_pressure_off.results | map(attribute='stat') | map(attribute='exists') | select | list | length == 0
|
||||
- gitea_runner_test_pressure_timer_off.status.ActiveState | default('inactive') != 'active'
|
||||
quiet: true
|
||||
|
||||
- name: Run the role again with the scenario's inputs
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.gitea_runner
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
# nfs_client
|
||||
|
||||
Installs the NFS client (`nfs-common`) and manages NFS mount entries in `/etc/fstab`. It writes the fstab line, creates the mount point and reloads systemd; it never mounts or unmounts anything. 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 a Debian-family host before any change.
|
||||
|
||||
Untested platforms: Debian 13 (trixie). The role has no OS-specific branch, but no scenario runs on it until the Debian image (#226) exists.
|
||||
|
||||
## Requirements and run order
|
||||
|
||||
- Use it by its fully qualified name, `mortis.kamino.nfs_client`, in a play that gathers facts: the Debian-family assert reads them.
|
||||
- Role dependencies: none. The role calls `ansible.posix.mount`, so the Collection's `ansible.posix` dependency applies.
|
||||
- `become` is used for every task that changes the host.
|
||||
- The role does not set up an NFS server, autofs, CIFS/SMB or Kerberos, and it does not wait for a mount.
|
||||
|
||||
## Role variables
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `nfs_client_mounts` | `[]` | The mounts to manage: a list of entries, each mount point once. With no entries only the client package is installed. |
|
||||
| `nfs_client_default_opts` | `_netdev,nofail` | Options for an entry that sets none. |
|
||||
|
||||
An entry takes these keys:
|
||||
|
||||
| Key | Default | Description |
|
||||
|---|---|---|
|
||||
| `src` | required | The export as `server:/export`, one word without spaces. |
|
||||
| `path` | required | The mount point: absolute, without spaces, not `/`, no trailing slash. |
|
||||
| `opts` | `nfs_client_default_opts` | The fstab options, one comma-separated word. Put the NFS version here, for example `vers=4.2`. |
|
||||
| `state` | `present` | `present` writes the fstab line. `absent` removes it and nothing else. |
|
||||
|
||||
## Tags
|
||||
|
||||
- `nfs_client`: everything the role does.
|
||||
- `install`: the client package.
|
||||
- `configure`: the mount points and the fstab entries.
|
||||
|
||||
Validation runs under `always`, so a bad input fails before any change whatever tags the run selects.
|
||||
|
||||
## Example play
|
||||
|
||||
```yaml
|
||||
- name: NFS client
|
||||
hosts: nfs_clients
|
||||
roles:
|
||||
- role: mortis.kamino.nfs_client
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- src: nas.example:/export/data
|
||||
path: /mnt/data
|
||||
- src: nas.example:/export/media
|
||||
path: /mnt/media
|
||||
opts: _netdev,nofail,ro,vers=4.2
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
`molecule/default` runs on Ubuntu noble and resolute: a check on a fresh host, the converge, a check on the configured host, an idempotence run, and `verify.yml`. The scenario seeds an fstab line for `/mnt/data` that names another server and a line and a directory for `/mnt/old`, so the run shows that a line is replaced once and that an `absent` entry loses only its line.
|
||||
|
||||
`verify.yml` first checks a refusal for each validation on the controller, once, in check mode (a missing or empty `src`, a `src` without an export, a relative path, the root, a trailing slash, options with a space or none, a duplicate path, `mounted` and `remounted`, a host without facts). It then asserts, on each container, the client package, the exact fstab fields, that a new mount point is root's and an existing one keeps its owner and mode, that the removed entry's directory and file are intact, that `/proc/mounts` shows nothing mounted, and that systemd has a mount unit for each new entry and none for the removed one.
|
||||
|
||||
What it does not show: that a real share mounts at boot (the server in the scenario does not exist), that `x-systemd.automount` or any option other than the defaults behaves, and Debian trixie.
|
||||
|
||||
## Notes
|
||||
|
||||
- **Why only the fstab.** `ansible.posix.mount` with `state: mounted` mounts from the play's own process. Where that process runs in a private mount namespace (a hardened sshd unit can), systemd and containers do not see the mount. The role writes the line and reloads systemd, and the share is mounted at the next boot or with `systemctl start <unit>.mount`. New options reach a share that is already mounted only after it is remounted or the host reboots.
|
||||
- **No owner, group or mode on the mount point.** Once a share is mounted the path is the export root, and a `chown` or `chmod` there changes the permissions on the NFS server. A new directory gets the system defaults, and an existing one is left as it is.
|
||||
- **A share that is mounted and unreachable.** On a re-run the role looks at each `present` mount point, and a mounted path whose server is gone can block that look. Fix or unmount the share, or leave that entry out of the run, before running the role again.
|
||||
- **`absent` leaves the share alone.** The entry's line is removed; the share stays mounted until it is unmounted and the mount point is not deleted.
|
||||
- **Default options.** `_netdev` orders the mount after the network and puts it in `remote-fs.target`; `nofail` keeps an unreachable server from holding up the boot. `x-systemd.automount` changes when a mount appears and can hide an unreachable server until first access, so it is left to the host that wants it. The `docker` role's `docker_stop_at_shutdown` relies on the same `remote-fs.target` ordering.
|
||||
- `--check` is the supported preview; a play-level `check_mode: true` is not supported. `apt` and the fstab edit both report what would change.
|
||||
- Idempotent: yes.
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
# Each entry: src (server:/export) and path (absolute mount point) are required; opts falls back
|
||||
# to nfs_client_default_opts; state is present (default) or absent.
|
||||
nfs_client_mounts: []
|
||||
|
||||
# _netdev orders the mount after the network and puts it in remote-fs.target; nofail keeps an
|
||||
# unreachable server from holding up the boot. x-systemd.automount is left to the host that wants it.
|
||||
nfs_client_default_opts: "_netdev,nofail"
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
# systemd builds a mount unit from each fstab line only when it reloads, so the reload is what
|
||||
# makes a changed line known to systemd. It mounts nothing.
|
||||
- name: Reload systemd for the nfs_client fstab entries
|
||||
become: true
|
||||
ansible.builtin.systemd_service:
|
||||
daemon_reload: true
|
||||
@@ -0,0 +1,57 @@
|
||||
---
|
||||
argument_specs:
|
||||
main:
|
||||
short_description: Install the NFS client and manage NFS entries in /etc/fstab
|
||||
description:
|
||||
- >-
|
||||
Asserts a Debian-family host, installs C(nfs-common), creates each mount point of a C(present) entry without
|
||||
owner, group or mode, writes or removes the entry's line in C(/etc/fstab), and reloads systemd after a change
|
||||
so that the mount unit is generated now. Nothing is mounted.
|
||||
- >-
|
||||
It never mounts or unmounts anything. An C(absent) entry only loses its fstab line: the share stays mounted
|
||||
until it is unmounted or the host reboots, and the mount point is not removed. Needs gathered facts.
|
||||
options:
|
||||
nfs_client_mounts:
|
||||
type: list
|
||||
elements: dict
|
||||
default: []
|
||||
description:
|
||||
- >-
|
||||
The NFS mounts to manage. Each mount point may appear once. With the default (no entries) only the client
|
||||
package is installed.
|
||||
options:
|
||||
src:
|
||||
type: str
|
||||
required: true
|
||||
description:
|
||||
- The export as C(server:/export), one word without spaces.
|
||||
path:
|
||||
type: str
|
||||
required: true
|
||||
description:
|
||||
- >-
|
||||
The mount point: an absolute path without spaces, not C(/) and without a trailing slash. Created, when
|
||||
the entry is C(present), with no owner, group or mode.
|
||||
opts:
|
||||
type: str
|
||||
description:
|
||||
- >-
|
||||
The fstab options, one comma-separated word without spaces. Falls back to C(nfs_client_default_opts)
|
||||
when left out or empty. Put the NFS version here, for example C(vers=4.2).
|
||||
state:
|
||||
type: str
|
||||
default: present
|
||||
choices: [present, absent]
|
||||
description:
|
||||
- >-
|
||||
C(present) writes the fstab line. C(absent) removes it and nothing else. The role has no C(mounted),
|
||||
C(unmounted) or C(remounted): mounting is left to systemd, so that a mount made from a play running in a
|
||||
private mount namespace (a hardened sshd unit) cannot go unseen by systemd and by containers.
|
||||
nfs_client_default_opts:
|
||||
type: str
|
||||
default: "_netdev,nofail"
|
||||
description:
|
||||
- >-
|
||||
Options for an entry that sets none. C(_netdev) orders the mount after the network and puts it in
|
||||
C(remote-fs.target); C(nofail) keeps an unreachable server from holding up the boot.
|
||||
C(x-systemd.automount) is not in the default.
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
galaxy_info:
|
||||
role_name: nfs_client
|
||||
namespace: mortis
|
||||
author: Dragonish
|
||||
license: GPL-3.0-or-later
|
||||
description: Install the NFS client and manage NFS mount entries in /etc/fstab, without mounting anything.
|
||||
min_ansible_version: "2.22"
|
||||
platforms:
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- noble
|
||||
- resolute
|
||||
galaxy_tags:
|
||||
- nfs
|
||||
- fstab
|
||||
- storage
|
||||
dependencies: []
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
# The mounts come from molecule.yml.
|
||||
- name: Converge
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
roles:
|
||||
- role: mortis.kamino.nfs_client
|
||||
@@ -0,0 +1,75 @@
|
||||
---
|
||||
# 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 the Ubuntu mirrors: the role installs nfs-common. The
|
||||
# containers run systemd as PID 1 with a writable cgroup, so a daemon-reload builds mount units
|
||||
# from /etc/fstab; no privileged mode. Nothing is ever mounted: the server below does not exist.
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
- name: ${KAMINO_RUN_ID:-local}-nfs-client-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
|
||||
security_opts:
|
||||
- apparmor=unconfined
|
||||
- name: ${KAMINO_RUN_ID:-local}-nfs-client-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:
|
||||
name: ansible
|
||||
# One source for every play, so the converge and the plays in verify.yml start from the same
|
||||
# valid input: a default-options mount, one with its own options, one to remove (prepare.yml
|
||||
# seeds its line), and /mnt/data, whose seeded line has another server and must be replaced.
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
nfs_client_mounts:
|
||||
- src: nas.example:/export/data
|
||||
path: /mnt/data
|
||||
- src: nas.example:/export/media
|
||||
path: /mnt/media
|
||||
opts: _netdev,nofail,ro,vers=4.2
|
||||
- src: nas.example:/export/old
|
||||
path: /mnt/old
|
||||
state: absent
|
||||
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,43 @@
|
||||
---
|
||||
# The state a host has before the role runs: a line for /mnt/data that names another server (the
|
||||
# role must replace it, once) and a line and a mount point for /mnt/old, the entry the converge
|
||||
# removes. The file in /mnt/old shows that removing the line leaves the directory alone.
|
||||
- name: Prepare
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
# The image ships without apt lists, and --check does not refresh them, so without this the
|
||||
# fresh-host check finds no nfs-common to install.
|
||||
- name: Refresh the apt cache
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
|
||||
- name: Seed the fstab lines
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/fstab
|
||||
line: "{{ item }}"
|
||||
create: true
|
||||
mode: "0644"
|
||||
loop:
|
||||
- old-nas.example:/export/data /mnt/data nfs defaults 0 0
|
||||
- nas.example:/export/old /mnt/old nfs _netdev,nofail 0 0
|
||||
|
||||
- name: Create the mount point that the converge leaves alone
|
||||
ansible.builtin.file:
|
||||
path: /mnt/old
|
||||
state: directory
|
||||
mode: "0750"
|
||||
|
||||
- name: Put a file in it
|
||||
ansible.builtin.copy:
|
||||
content: kept
|
||||
dest: /mnt/old/keep
|
||||
mode: "0644"
|
||||
|
||||
# An existing mount point of a present entry: the role must leave its owner and mode alone.
|
||||
- name: Create a mount point with an owner and a mode of its own
|
||||
ansible.builtin.file:
|
||||
path: /mnt/media
|
||||
state: directory
|
||||
owner: daemon
|
||||
mode: "0710"
|
||||
@@ -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: nfs_client_test_case (name,
|
||||
# expect).
|
||||
- name: "Run the role, case {{ nfs_client_test_case.name }}"
|
||||
block:
|
||||
- name: "Include the role, case {{ nfs_client_test_case.name }}"
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.nfs_client
|
||||
|
||||
# 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 {{ nfs_client_test_case.name }}"
|
||||
ansible.builtin.fail:
|
||||
msg: The role accepted the input
|
||||
rescue:
|
||||
- name: "The expected failure stopped the run, case {{ nfs_client_test_case.name }}"
|
||||
ansible.builtin.assert:
|
||||
that: nfs_client_test_case.expect in (ansible_failed_result.msg | default(''))
|
||||
fail_msg: "Expected '{{ nfs_client_test_case.expect }}', got: {{ ansible_failed_result.msg | default('') }}"
|
||||
quiet: true
|
||||
@@ -0,0 +1,247 @@
|
||||
---
|
||||
# The refusals below stop in validation, before any task that changes a host, so they need no
|
||||
# container: they run once, on the controller, in check mode so that a regressed guard cannot
|
||||
# change it.
|
||||
#
|
||||
# Runs first, before any play gathers facts: the role refuses a host it cannot identify as
|
||||
# Debian-family, before any change.
|
||||
- name: Refuse a host without facts
|
||||
hosts: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Run the role without gathered facts
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_test_case:
|
||||
name: no-facts
|
||||
expect: nfs_client supports Debian-family hosts only
|
||||
|
||||
# Negative tests: each validation stops the role before any change, with its own message. The
|
||||
# inputs replace the converge's mounts for one include only.
|
||||
- name: Refuse invalid input
|
||||
hosts: localhost
|
||||
connection: local
|
||||
check_mode: true
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Refuse a state the role does not have
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: "nas.example:/export/data", path: /mnt/data, state: mounted}
|
||||
nfs_client_test_case:
|
||||
name: state-mounted
|
||||
expect: "value of state must be one of: present, absent, got: mounted"
|
||||
|
||||
- name: Refuse remounted
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: "nas.example:/export/data", path: /mnt/data, state: remounted}
|
||||
nfs_client_test_case:
|
||||
name: state-remounted
|
||||
expect: "value of state must be one of: present, absent, got: remounted"
|
||||
|
||||
- name: Refuse an entry without a src
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {path: /mnt/data}
|
||||
nfs_client_test_case:
|
||||
name: src-missing
|
||||
expect: "missing required arguments: src"
|
||||
|
||||
- name: Refuse an empty src
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: "", path: /mnt/data}
|
||||
nfs_client_test_case:
|
||||
name: src-empty
|
||||
expect: nfs_client_mounts src must be one word of the form server:/export
|
||||
|
||||
- name: Refuse a src without an export
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: nas.example, path: /mnt/data}
|
||||
nfs_client_test_case:
|
||||
name: src-no-export
|
||||
expect: nfs_client_mounts src must be one word of the form server:/export
|
||||
|
||||
- name: Refuse a src with a space after the export
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: "nas.example:/export/my data", path: /mnt/data}
|
||||
nfs_client_test_case:
|
||||
name: src-space
|
||||
expect: nfs_client_mounts src must be one word of the form server:/export
|
||||
|
||||
- name: Refuse a mount point with a space
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: "nas.example:/export/data", path: "/mnt/my data"}
|
||||
nfs_client_test_case:
|
||||
name: path-space
|
||||
expect: nfs_client_mounts path must be an absolute path
|
||||
|
||||
- name: Refuse a relative mount point
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: "nas.example:/export/data", path: mnt/data}
|
||||
nfs_client_test_case:
|
||||
name: path-relative
|
||||
expect: nfs_client_mounts path must be an absolute path
|
||||
|
||||
- name: Refuse the root as a mount point
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: "nas.example:/export/data", path: /}
|
||||
nfs_client_test_case:
|
||||
name: path-root
|
||||
expect: nfs_client_mounts path must be an absolute path
|
||||
|
||||
- name: Refuse a trailing slash
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: "nas.example:/export/data", path: /mnt/data/}
|
||||
nfs_client_test_case:
|
||||
name: path-trailing-slash
|
||||
expect: nfs_client_mounts path must be an absolute path
|
||||
|
||||
- name: Refuse options with a space
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: "nas.example:/export/data", path: /mnt/data, opts: "ro, nofail"}
|
||||
nfs_client_test_case:
|
||||
name: opts-space
|
||||
expect: nfs_client_mounts options must be a non-empty comma-separated word
|
||||
|
||||
- name: Refuse an entry with no options when the default is empty
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_default_opts: ""
|
||||
nfs_client_mounts:
|
||||
- {src: "nas.example:/export/data", path: /mnt/data}
|
||||
nfs_client_test_case:
|
||||
name: opts-empty
|
||||
expect: nfs_client_mounts options must be a non-empty comma-separated word
|
||||
|
||||
- name: Refuse the same mount point twice
|
||||
ansible.builtin.include_tasks: tasks/failed_run.yml
|
||||
vars:
|
||||
nfs_client_mounts:
|
||||
- {src: "nas.example:/export/data", path: /mnt/data}
|
||||
- {src: "nas.example:/export/other", path: /mnt/data}
|
||||
nfs_client_test_case:
|
||||
name: duplicate-path
|
||||
expect: nfs_client_mounts lists the same path twice
|
||||
|
||||
- name: Verify the host
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Read the installed packages
|
||||
ansible.builtin.package_facts:
|
||||
manager: apt
|
||||
|
||||
- name: The client package is installed
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'nfs-common' in ansible_facts.packages"
|
||||
quiet: true
|
||||
|
||||
- name: Read fstab
|
||||
ansible.builtin.slurp:
|
||||
src: /etc/fstab
|
||||
register: nfs_client_test_fstab
|
||||
|
||||
# Each line split into its six fields, so the assertions do not depend on the spacing the
|
||||
# module writes.
|
||||
- name: Split the fstab lines into fields
|
||||
ansible.builtin.set_fact:
|
||||
nfs_client_test_rows: >-
|
||||
{{ (nfs_client_test_fstab.content | b64decode).splitlines()
|
||||
| reject('match', '^#')
|
||||
| map('split')
|
||||
| reject('equalto', [])
|
||||
| list }}
|
||||
|
||||
# The seeded line for /mnt/data named another server and the default options: the role
|
||||
# replaces it, so exactly one line is left for the path.
|
||||
- name: The default-options entry replaced the seeded line
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "['nas.example:/export/data', '/mnt/data', 'nfs', '_netdev,nofail', '0', '0'] in nfs_client_test_rows"
|
||||
- nfs_client_test_rows | selectattr('1', 'eq', '/mnt/data') | list | length == 1
|
||||
quiet: true
|
||||
|
||||
- name: The entry with its own options keeps them
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "['nas.example:/export/media', '/mnt/media', 'nfs', '_netdev,nofail,ro,vers=4.2', '0', '0'] in nfs_client_test_rows"
|
||||
quiet: true
|
||||
|
||||
- name: The absent entry lost its line
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- nfs_client_test_rows | selectattr('1', 'eq', '/mnt/old') | list | length == 0
|
||||
quiet: true
|
||||
|
||||
- name: Stat the mount points
|
||||
ansible.builtin.stat:
|
||||
path: "{{ item }}"
|
||||
loop: [/mnt/data, /mnt/media, /mnt/old, /mnt/old/keep]
|
||||
register: nfs_client_test_stat
|
||||
|
||||
# prepare.yml gave /mnt/media an owner and a mode and /mnt/old a mode of its own. The role
|
||||
# created /mnt/data (a new directory is root's) and changed neither of the others, and the
|
||||
# removed entry's directory and the file in it are untouched.
|
||||
- name: The mount points exist, keep their owner and mode, and the removed entry's directory is intact
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- nfs_client_test_stat.results | map(attribute='stat.exists') | min
|
||||
- nfs_client_test_stat.results[0].stat.isdir
|
||||
- nfs_client_test_stat.results[0].stat.pw_name == 'root'
|
||||
- nfs_client_test_stat.results[1].stat.pw_name == 'daemon'
|
||||
- nfs_client_test_stat.results[1].stat.mode == '0710'
|
||||
- nfs_client_test_stat.results[2].stat.mode == '0750'
|
||||
quiet: true
|
||||
|
||||
- name: Read what is mounted
|
||||
ansible.builtin.slurp:
|
||||
src: /proc/mounts
|
||||
register: nfs_client_test_mounts
|
||||
|
||||
- name: Nothing was mounted
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- "'/mnt/data' not in (nfs_client_test_mounts.content | b64decode)"
|
||||
- "'/mnt/media' not in (nfs_client_test_mounts.content | b64decode)"
|
||||
quiet: true
|
||||
|
||||
# The daemon-reload is what turns an fstab line into a unit; the generator ran again, so the
|
||||
# new lines have a unit and the removed one has none. systemctl and not the systemd module,
|
||||
# which fails on a unit that is not loaded, the very state asserted for the removed entry.
|
||||
- name: Ask systemd about the mount units # noqa: command-instead-of-module
|
||||
ansible.builtin.command: "systemctl show --property=LoadState --value {{ item }}"
|
||||
loop: [mnt-data.mount, mnt-media.mount, mnt-old.mount]
|
||||
register: nfs_client_test_units
|
||||
changed_when: false
|
||||
check_mode: false
|
||||
|
||||
- name: Systemd knows the new entries and not the removed one
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- nfs_client_test_units.results[0].stdout == 'loaded'
|
||||
- nfs_client_test_units.results[1].stdout == 'loaded'
|
||||
- nfs_client_test_units.results[2].stdout == 'not-found'
|
||||
quiet: true
|
||||
@@ -0,0 +1,48 @@
|
||||
---
|
||||
# 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: Install the NFS client package
|
||||
become: true
|
||||
ansible.builtin.apt:
|
||||
name: "{{ __nfs_client_package }}"
|
||||
state: present
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
tags: [nfs_client, install]
|
||||
|
||||
# No owner, group or mode: once a share is mounted the path is the export root, and a chown or
|
||||
# chmod there changes the permissions on the NFS server.
|
||||
- name: Create the mount points # noqa: risky-file-permissions
|
||||
become: true
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
state: directory
|
||||
loop: "{{ __nfs_client_entries | selectattr('state', 'eq', 'present') | list }}"
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
tags: [nfs_client, configure]
|
||||
|
||||
# present writes the fstab line and mounts nothing. An absent entry only loses its line:
|
||||
# ansible.posix.mount's own absent would also unmount the share and delete the mount point.
|
||||
- name: Manage the fstab entries
|
||||
become: true
|
||||
ansible.posix.mount:
|
||||
src: "{{ item.src }}"
|
||||
path: "{{ item.path }}"
|
||||
fstype: nfs
|
||||
opts: "{{ item.opts }}"
|
||||
dump: "0"
|
||||
passno: "0"
|
||||
state: "{{ 'present' if item.state == 'present' else 'absent_from_fstab' }}"
|
||||
loop: "{{ __nfs_client_entries }}"
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
notify: Reload systemd for the nfs_client fstab entries
|
||||
tags: [nfs_client, configure]
|
||||
|
||||
- name: Flush handlers
|
||||
ansible.builtin.meta: flush_handlers
|
||||
@@ -0,0 +1,73 @@
|
||||
---
|
||||
# Input checks. Imported first in main.yml with tags: always, so a bad input fails before any
|
||||
# change. The argument spec (types, choices, required keys) runs before this file; the rules
|
||||
# below are the ones between values. Each assert covers the whole list, not one item per loop
|
||||
# pass, so the failure message is the assert's own. fstab fields are split on whitespace, so
|
||||
# "one word" is tested with split rather than a pattern.
|
||||
|
||||
# The package and the fstab format are Debian's, and the role reads gathered facts.
|
||||
- name: Require a Debian-family host
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ansible_facts['os_family'] | default('') == 'Debian'
|
||||
fail_msg: >-
|
||||
nfs_client supports Debian-family hosts only (found: {{ ansible_facts['os_family'] | default('no gathered facts') }}).
|
||||
The role reads gathered facts, so run it in a play that gathers them.
|
||||
quiet: true
|
||||
|
||||
# Fact-computing tasks that the checks below read. A statement block in one template would leave
|
||||
# whitespace around the result and make it a string instead of a list, so the list is built by
|
||||
# appending one entry per pass.
|
||||
- name: Start the resolved entries
|
||||
ansible.builtin.set_fact:
|
||||
__nfs_client_entries: []
|
||||
|
||||
# Defaults of the suboptions are applied here: the spec's suboption defaults are documentation.
|
||||
- name: Resolve the entries
|
||||
ansible.builtin.set_fact:
|
||||
__nfs_client_entries: >-
|
||||
{{ __nfs_client_entries + [{
|
||||
'src': item.src | trim,
|
||||
'path': item.path,
|
||||
'opts': (item.opts | default('', true) | trim) or (nfs_client_default_opts | trim),
|
||||
'state': item.state | default('present', true)
|
||||
}] }}
|
||||
loop: "{{ nfs_client_mounts }}"
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
|
||||
- name: Require a server and an export in every src
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __nfs_client_entries | map(attribute='src') | map('split') | map('length') | reject('eq', 1) | list | length == 0
|
||||
- __nfs_client_entries | map(attribute='src') | reject('search', '^[^ ]+:/') | list | length == 0
|
||||
fail_msg: >-
|
||||
nfs_client_mounts src must be one word of the form server:/export, without spaces
|
||||
(offending: {{ __nfs_client_entries | map(attribute='src') | reject('search', '^[^ ]+:/') | list }}).
|
||||
quiet: true
|
||||
|
||||
- name: Require an absolute mount point that is not the root
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __nfs_client_entries | map(attribute='path') | map('split') | map('length') | reject('eq', 1) | list | length == 0
|
||||
- __nfs_client_entries | map(attribute='path') | reject('search', '^/[^ ]*[^/ ]$') | list | length == 0
|
||||
fail_msg: >-
|
||||
nfs_client_mounts path must be an absolute path without spaces, not the root and without a trailing slash
|
||||
(offending: {{ __nfs_client_entries | map(attribute='path') | reject('search', '^/[^ ]*[^/ ]$') | list }}).
|
||||
quiet: true
|
||||
|
||||
- name: Require options that fit one fstab field
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __nfs_client_entries | map(attribute='opts') | map('split') | map('length') | reject('eq', 1) | list | length == 0
|
||||
fail_msg: >-
|
||||
nfs_client_mounts options must be a non-empty comma-separated word without spaces, from the entry's opts or, when
|
||||
that is empty, from nfs_client_default_opts.
|
||||
quiet: true
|
||||
|
||||
- name: Require one entry per mount point
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __nfs_client_entries | map(attribute='path') | unique | list | length == __nfs_client_entries | length
|
||||
fail_msg: nfs_client_mounts lists the same path twice; each mount point may appear once.
|
||||
quiet: true
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
# Constant, not an input: the package that carries mount.nfs on Debian and Ubuntu.
|
||||
__nfs_client_package: nfs-common
|
||||
@@ -134,8 +134,8 @@ The scenario `molecule/default/` runs in CI only, on two platforms: `${MOLECULE_
|
||||
- Verify checks the installed and removed packages, the journal size cap, the apt settings in `20auto-upgrades` and `50unattended-upgrades`, the locale, and that systemd loaded the `apt-daily.service` timeout.
|
||||
- Verify checks the tmux snippet: root-owned, valid shell, the session and quoted window command, no effect without a terminal, a session name or window command ending in a newline refused, and the file removed when autostart is off.
|
||||
- Verify refuses bad items in `system_baseline_extra_packages` and `system_baseline_extra_remove_packages` (whitespace, a null, an empty string, a trailing minus, upper case, a bare string) and a package that one input installs and another purges; converge applies the `ubuntu_lxc` profile with `jq` as an extra package and `ed` as an extra removal; verify checks that `jq` is installed, `ed` is gone and the profile's packages are still there, and that an extra `tmux` installs the snippet where a flat list without it installs none.
|
||||
- Verify also checks that a bad `system_baseline_apt_tmpdir` (under `/tmp` or `/var/tmp`, relative, with `..`, empty) is refused in the main flow and in the `update` entry point. It reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, and that the connection is reset afterwards: the scenario skips the `update` tag, so the upgrade itself never runs there.
|
||||
- Verify runs the `update` entry point in check mode on the Ubuntu container with `system_baseline_system_type: pve` and a `pvesh` stub, in seven cases (a running, a finished or no vzdump task, the input off, `ubuntu_lxc`), and asserts the fact that decides the upgrade and that `pvesh` was run, with `--source active`, only when it should be. It does not assert that the apt task itself was skipped. The stub stands for the real answer, which no CI image has.
|
||||
- Verify also checks that a bad `system_baseline_apt_tmpdir` (under `/tmp` or `/var/tmp`, relative, with `..`, empty) is refused in the main flow and in the `update` entry point. It reads `tasks/update.yml` and checks that the scratch directory is created with mode `0700`, that both apt tasks set `TMPDIR` to it, that the connection is reset afterwards, and that the vzdump guard is imported before the upgrade, whose `when` reads the guard's fact: the scenario skips the `update` tag, so the upgrade itself never runs there.
|
||||
- Verify runs the vzdump guard in check mode on the Ubuntu container with `system_baseline_system_type: pve` and a `pvesh` stub, in seven cases (a running, a finished or no vzdump task, the input off, `ubuntu_lxc`); six run the guard's task file alone and the `ubuntu_lxc` case runs the whole `update` entry point. Each case asserts the fact that decides the upgrade and that `pvesh` was run, with `--source active`, only when it should be. It does not assert that the apt task itself was skipped. The stub stands for the real answer, which no CI image has.
|
||||
- Verify ends by running the role once with `system_baseline_journal_max_use: ""` after removing the drop-in, and asserts that no drop-in is written and that `systemd-journald` was not restarted.
|
||||
- Verify runs the `reboot` entry point with `system_baseline_reboot_if_required: false`, without and with `/var/run/reboot-required`, and checks the fact and that the host did not reboot.
|
||||
- The `pve` origins pin is applied to the Ubuntu container and read back with `apt-config dump`, then removed again. The package blacklist is written, read back as a list, left alone by a second run and removed by an empty list.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
- name: Converge the LXC profile
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
gather_subset: [min]
|
||||
vars:
|
||||
system_baseline_system_type: ubuntu_lxc
|
||||
system_baseline_extra_packages: [jq]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
# One case of the vzdump guard: a pvesh stub answers with system_baseline_case_answer, the update entry point runs in check mode, and the
|
||||
# fact that decides the upgrade, and whether pvesh was asked at all, are compared with what the case expects. Kept outside the role's own tasks:
|
||||
# no CI image is a Proxmox node, so the stub stands for the real `pvesh get /nodes/<node>/tasks` answer.
|
||||
# One case of the vzdump guard: a pvesh stub answers with system_baseline_case.answer, the role's tasks_from file (the guard alone unless the
|
||||
# case names update) runs in check mode, and the fact that decides the upgrade, and whether pvesh was asked at all, are compared with what the
|
||||
# case expects. Kept outside the role's own tasks: no CI image is a Proxmox node, so the stub stands for the real `pvesh get` answer.
|
||||
- name: Write the pvesh stub
|
||||
check_mode: false
|
||||
ansible.builtin.copy:
|
||||
@@ -14,8 +14,9 @@
|
||||
{{ system_baseline_case.answer | to_json }}
|
||||
JSON
|
||||
|
||||
- name: Create the apt scratch directory, which a check mode run does not
|
||||
- name: Create the apt scratch directory, which a check mode run of the update entry point does not
|
||||
check_mode: false
|
||||
when: system_baseline_case.tasks_from | default('vzdump_guard') == 'update'
|
||||
ansible.builtin.file:
|
||||
path: /var/cache/system-baseline-apt-tmp
|
||||
state: directory
|
||||
@@ -26,13 +27,13 @@
|
||||
path: /var/tmp/pvesh-calls
|
||||
state: absent
|
||||
|
||||
- name: Run the update entry point in check mode
|
||||
- name: Run the case's tasks in check mode
|
||||
check_mode: true
|
||||
block:
|
||||
- name: Include system_baseline, tasks_from update
|
||||
- name: Include system_baseline, tasks_from {{ system_baseline_case.tasks_from | default('vzdump_guard') }}
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.system_baseline
|
||||
tasks_from: update
|
||||
tasks_from: "{{ system_baseline_case.tasks_from | default('vzdump_guard') }}"
|
||||
vars:
|
||||
system_baseline_system_type: "{{ system_baseline_case.type }}"
|
||||
system_baseline_skip_upgrade_during_vzdump: "{{ system_baseline_case.input }}"
|
||||
|
||||
@@ -464,6 +464,19 @@
|
||||
- system_baseline_verify_update_tasks is search('(?m)^ ansible.builtin.meta:\sreset_connection$')
|
||||
quiet: true
|
||||
|
||||
# The guard cases below run vzdump_guard.yml alone, so this holds the wiring: the guard is imported before the upgrade, and the upgrade
|
||||
# task's when reads the guard's fact.
|
||||
- name: The vzdump guard is imported before the upgrade, and the upgrade waits on its fact
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- >-
|
||||
system_baseline_verify_update_tasks is search('(?ms)^ ansible\.builtin\.import_tasks:\svzdump_guard\.yml$'
|
||||
~ '.*^- name:\sUpdate & upgrade apt packages$')
|
||||
- >-
|
||||
system_baseline_verify_update_tasks is search('(?m)^- name:\sUpdate & upgrade apt packages\n(?: .*\n)*?'
|
||||
~ ' - not \(__system_baseline_vzdump_running \| default\(false\)\)$')
|
||||
quiet: true
|
||||
|
||||
# The reboot entry point is a supported interface: with system_baseline_reboot_if_required
|
||||
# false it only sets system_baseline_reboot_required. Here and not in converge, because it
|
||||
# creates and removes the marker file, which the idempotence run would report as a change.
|
||||
@@ -471,6 +484,7 @@
|
||||
- name: The reboot entry point only computes the fact when told not to reboot
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
gather_subset: [min]
|
||||
tasks:
|
||||
- name: Remove the reboot marker
|
||||
ansible.builtin.file:
|
||||
@@ -785,7 +799,8 @@
|
||||
tags: always
|
||||
|
||||
# The vzdump guard (system_baseline_skip_upgrade_during_vzdump): a running backup is a vzdump task without an endtime. With the input off, or on
|
||||
# a system type other than pve, pvesh is never run. Only the decision is asserted: the upgrade itself is not run in CI.
|
||||
# a system type other than pve, pvesh is never run. Only the decision is asserted: the upgrade itself is not run in CI. The cases run the guard
|
||||
# alone; the last one runs the update entry point, so it still runs end to end in check mode.
|
||||
- name: The vzdump guard skips the upgrade only for a running backup on a pve node
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
@@ -801,7 +816,7 @@
|
||||
- {type: pve, input: true, running: false, asked: true, answer: [{type: qmstart, upid: b, starttime: 1}]}
|
||||
- {type: pve, input: true, running: false, asked: true, answer: []}
|
||||
- {type: pve, input: false, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}]}
|
||||
- {type: ubuntu_lxc, input: true, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}]}
|
||||
- {type: ubuntu_lxc, input: true, running: false, asked: false, answer: [{type: vzdump, upid: a, starttime: 1}], tasks_from: update}
|
||||
|
||||
# An empty system_baseline_journal_max_use leaves journald alone: with the drop-in gone, the role neither writes it again nor restarts
|
||||
# systemd-journald. It runs last, because it applies the role with its defaults (the converge's tmux autostart and apt-daily timeout are
|
||||
@@ -810,6 +825,7 @@
|
||||
- name: An empty journal size cap leaves journald alone
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
gather_subset: [min]
|
||||
tasks:
|
||||
- name: Remove the drop-in and its directory
|
||||
ansible.builtin.file:
|
||||
|
||||
@@ -12,11 +12,13 @@
|
||||
manager: auto
|
||||
become: true
|
||||
|
||||
# One apt call for every unwanted package that is installed, skipped when none is.
|
||||
- name: Remove unnecessary packages if installed
|
||||
ansible.builtin.package:
|
||||
name: "{{ item }}"
|
||||
name: "{{ __system_baseline_purge_present }}"
|
||||
state: absent
|
||||
purge: true
|
||||
loop: "{{ __system_baseline_purge_packages }}"
|
||||
when: item in ansible_facts.packages
|
||||
vars:
|
||||
__system_baseline_purge_present: "{{ __system_baseline_purge_packages | select('in', ansible_facts.packages) | list }}"
|
||||
when: __system_baseline_purge_present | length > 0
|
||||
become: true
|
||||
@@ -9,11 +9,11 @@
|
||||
- name: Check if reboot is required (Debian)
|
||||
ansible.builtin.stat:
|
||||
path: /var/run/reboot-required
|
||||
register: system_baseline_reboot_required_file
|
||||
register: __system_baseline_reboot_required_file
|
||||
|
||||
- name: Set system_baseline_reboot_required fact
|
||||
ansible.builtin.set_fact:
|
||||
system_baseline_reboot_required: "{{ system_baseline_reboot_required_file.stat.exists }}"
|
||||
system_baseline_reboot_required: "{{ __system_baseline_reboot_required_file.stat.exists }}"
|
||||
|
||||
- name: Reboot the server if required
|
||||
ansible.builtin.reboot:
|
||||
|
||||
@@ -60,6 +60,6 @@
|
||||
- name: Validate unattended-upgrades config
|
||||
become: true
|
||||
ansible.builtin.command: unattended-upgrades --dry-run --debug
|
||||
register: system_baseline_unattended_check
|
||||
register: __system_baseline_unattended_check
|
||||
changed_when: false
|
||||
failed_when: system_baseline_unattended_check.rc != 0
|
||||
failed_when: __system_baseline_unattended_check.rc != 0
|
||||
@@ -21,57 +21,9 @@
|
||||
mode: "0700"
|
||||
become: true
|
||||
|
||||
# Opt-in guard (system_baseline_skip_upgrade_during_vzdump, pve only): an upgrade can restart Proxmox services while a backup holds a snapshot
|
||||
# of a guest, so the upgrade waits for the next run when this node has a vzdump task without an end time. Both tasks read state only, so
|
||||
# they run in check mode too; they are skipped where the upgrade is (a dry run of the main flow). `localhost` is the node's own alias, so no
|
||||
# node name and no gathered facts are needed. --source active lists the running tasks: the default, archive, holds only finished ones. The
|
||||
# fact is set on every run, so a guard that is off or skipped never inherits the answer of an earlier run in the same play.
|
||||
- name: List the recent Proxmox tasks of this node
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- pvesh
|
||||
- get
|
||||
- /nodes/localhost/tasks
|
||||
- --source
|
||||
- active
|
||||
- --limit
|
||||
- "0"
|
||||
- --output-format
|
||||
- json
|
||||
register: __system_baseline_pve_tasks
|
||||
changed_when: false
|
||||
check_mode: false
|
||||
become: true
|
||||
when:
|
||||
- system_baseline_skip_upgrade_during_vzdump | bool
|
||||
- system_baseline_system_type | default('') == 'pve'
|
||||
- not (ansible_check_mode and __system_baseline_main_flow | default(false))
|
||||
|
||||
- name: Check that pvesh answered with a list of tasks
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __system_baseline_pve_tasks.stdout | from_json is sequence
|
||||
- __system_baseline_pve_tasks.stdout | from_json is not string
|
||||
- __system_baseline_pve_tasks.stdout | from_json is not mapping
|
||||
fail_msg: pvesh did not answer with a JSON list of tasks, so the role cannot tell whether a backup is running.
|
||||
quiet: true
|
||||
when: __system_baseline_pve_tasks is not skipped
|
||||
|
||||
- name: Note whether a vzdump backup is running on this node
|
||||
ansible.builtin.set_fact:
|
||||
__system_baseline_vzdump_running: >-
|
||||
{{ __system_baseline_pve_tasks is not skipped
|
||||
and (__system_baseline_pve_tasks.stdout | from_json
|
||||
| selectattr('type', 'equalto', 'vzdump')
|
||||
| rejectattr('endtime', 'defined')
|
||||
| list | length) > 0 }}
|
||||
|
||||
- name: Skip the upgrade while a vzdump backup is running
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
Skipping the apt upgrade on {{ inventory_hostname }}: a vzdump task is running on this node. Run the update again after the backup
|
||||
has finished.
|
||||
when: __system_baseline_vzdump_running | default(false)
|
||||
# import_tasks, not include_tasks: the update tag, the caller's when and __system_baseline_main_flow must reach the guard's tasks.
|
||||
- name: Decide whether a vzdump backup holds back the upgrade
|
||||
ansible.builtin.import_tasks: vzdump_guard.yml
|
||||
|
||||
# safe is the apt module's name for the plain upgrade (apt-get upgrade --with-new-pkgs), what `true` meant here before; dist runs
|
||||
# apt-get dist-upgrade (profile key apt_upgrade, `pve` by default).
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
# Opt-in guard (system_baseline_skip_upgrade_during_vzdump, pve only): an upgrade can restart Proxmox services while a backup holds a snapshot
|
||||
# of a guest, so the upgrade waits for the next run when this node has a vzdump task without an end time. Both tasks read state only, so
|
||||
# they run in check mode too; they are skipped where the upgrade is (a dry run of the main flow). `localhost` is the node's own alias, so no
|
||||
# node name and no gathered facts are needed. --source active lists the running tasks: the default, archive, holds only finished ones. The
|
||||
# fact is set on every run, so a guard that is off or skipped never inherits the answer of an earlier run in the same play.
|
||||
- name: List the recent Proxmox tasks of this node
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- pvesh
|
||||
- get
|
||||
- /nodes/localhost/tasks
|
||||
- --source
|
||||
- active
|
||||
- --limit
|
||||
- "0"
|
||||
- --output-format
|
||||
- json
|
||||
register: __system_baseline_pve_tasks
|
||||
changed_when: false
|
||||
check_mode: false
|
||||
become: true
|
||||
when:
|
||||
- system_baseline_skip_upgrade_during_vzdump | bool
|
||||
- system_baseline_system_type | default('') == 'pve'
|
||||
- not (ansible_check_mode and __system_baseline_main_flow | default(false))
|
||||
|
||||
- name: Check that pvesh answered with a list of tasks
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- __system_baseline_pve_tasks.stdout | from_json is sequence
|
||||
- __system_baseline_pve_tasks.stdout | from_json is not string
|
||||
- __system_baseline_pve_tasks.stdout | from_json is not mapping
|
||||
fail_msg: pvesh did not answer with a JSON list of tasks, so the role cannot tell whether a backup is running.
|
||||
quiet: true
|
||||
when: __system_baseline_pve_tasks is not skipped
|
||||
|
||||
- name: Note whether a vzdump backup is running on this node
|
||||
ansible.builtin.set_fact:
|
||||
__system_baseline_vzdump_running: >-
|
||||
{{ __system_baseline_pve_tasks is not skipped
|
||||
and (__system_baseline_pve_tasks.stdout | from_json
|
||||
| selectattr('type', 'equalto', 'vzdump')
|
||||
| rejectattr('endtime', 'defined')
|
||||
| list | length) > 0 }}
|
||||
|
||||
- name: Skip the upgrade while a vzdump backup is running
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
Skipping the apt upgrade on {{ inventory_hostname }}: a vzdump task is running on this node. Run the update again after the backup
|
||||
has finished.
|
||||
when: __system_baseline_vzdump_running | default(false)
|
||||
@@ -80,14 +80,14 @@ Update or remove: pass `-e traefik_update=true`, or `-e "traefik_remove=true tra
|
||||
|
||||
## 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 needs outbound network: the role installs packages with apt and the converge downloads the real Traefik release 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 `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 the converge downloads the real Traefik release from GitHub. Prepare runs `mortis.kamino.ufw`, so converge runs only 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 install: the pinned version runs, and only the binary is left from the archive.
|
||||
- Files: `traefik.env` mode 0600 owned by root, `dynamic.yml` mode 0600 owned by `traefik`, `traefik.yml` mode 0600, the binary mode 0755; the logrotate configuration, which `logrotate --debug` parses.
|
||||
- Rendering: the ACME resolvers render when set and are absent when empty; the dashboard is off by default with the extra app routed, and renders behind basicAuth when enabled (a template render, not a running dashboard).
|
||||
- The service: running and enabled with `NoNewPrivileges`, `MemoryDenyWriteExecute` and `CAP_NET_BIND_SERVICE`, listening on 80 and 443 and redirecting http to https; ufw allows 80 and 443 next to SSH, with the traefik owner tag, in order.
|
||||
- The update path: it updates to another release and back with `traefik_update` (download from local `file://` stand-in releases, checksum check and swap) and asserts the version, an active unit and no leftovers. It leaves the stand-in stub installed, so nothing after it asserts real Traefik behaviour.
|
||||
- The update path: it updates to another release with `traefik_update` (download from local `file://` stand-in releases, checksum check and swap) and asserts the version, an active unit and no leftovers. It leaves the stand-in stub installed, so nothing after it asserts real Traefik behaviour.
|
||||
- The remove path, last: unit and binary are deleted, the service is no longer active, and only the traefik ufw rules are removed.
|
||||
|
||||
The scenario disables the namespace-based sandboxing and the `User=` switch with a drop-in because its container is unprivileged, so that sandboxing is not covered by CI. Certificate issuance is not covered: the Cloudflare credentials are dummies.
|
||||
@@ -96,6 +96,7 @@ The scenario disables the namespace-based sandboxing and the `User=` switch with
|
||||
|
||||
- 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 does not refresh an APT cache younger than an hour, so a package from a source you add just before the role (`ansible.builtin.deb822_repository` does not refresh) needs your own cache refresh first.
|
||||
- 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.
|
||||
- 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.
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
---
|
||||
# Role variables come from the inventory group_vars in molecule.yml, so the idempotence step
|
||||
# reruns converge with identical configuration; verify's plays override only what they test.
|
||||
# The base ufw play comes first: traefik passes its rules through the mortis.kamino.ufw
|
||||
# service_rules entry point, which needs ufw installed and active. ufw_rules comes from the
|
||||
# same group_vars (the SSH allow rule the lock-out guard requires).
|
||||
# mortis.kamino.ufw runs in prepare.yml, so only traefik counts toward idempotence. Facts are
|
||||
# off: neither the role nor the roles it includes reads any.
|
||||
- name: Converge
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
gather_facts: false
|
||||
roles:
|
||||
- role: mortis.kamino.ufw
|
||||
- role: mortis.kamino.traefik
|
||||
@@ -3,7 +3,7 @@
|
||||
# (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
|
||||
# .gitea/workflows/molecule.yml. Needs outbound network, unlike most scenarios: the role installs
|
||||
# packages with apt and the converge downloads the Traefik release from GitHub (verify's update
|
||||
# path uses file:// stand-ins built by prepare.yml). No privileged mode: systemd needs a writable
|
||||
# path uses a file:// stand-in built by prepare.yml). No privileged mode: systemd needs a writable
|
||||
# cgroup and the firewall tools need NET_ADMIN.
|
||||
driver:
|
||||
name: docker
|
||||
@@ -44,9 +44,10 @@ platforms:
|
||||
- apparmor=unconfined
|
||||
provisioner:
|
||||
name: ansible
|
||||
# One source for every play in converge.yml and verify.yml. The role renders traefik.yml before
|
||||
# its dashboard-auth collision check, so that guard play with other values would change it (and
|
||||
# restart Traefik) before verify's assertions; converge's values must also stay fixed for idempotence.
|
||||
# One source for the prepare plays that read them, converge.yml and verify.yml. The role renders
|
||||
# traefik.yml before its dashboard-auth collision check, so that guard play with other values
|
||||
# would change it (and restart Traefik) before verify's assertions; converge's values must also
|
||||
# stay fixed for idempotence.
|
||||
inventory:
|
||||
group_vars:
|
||||
all:
|
||||
@@ -55,8 +56,8 @@ provisioner:
|
||||
traefik_cloudflare_email: [email protected]
|
||||
traefik_cloudflare_api_token: molecule-not-a-token
|
||||
traefik_domain: example.test
|
||||
# Any release other than the role default: verify's update path goes there and back,
|
||||
# from the stand-ins prepare.yml builds.
|
||||
# Any release other than the role default: verify's update path goes there, from the
|
||||
# stand-in prepare.yml builds.
|
||||
traefik_verify_other_version: v3.7.18
|
||||
ufw_rules:
|
||||
- {rule: allow, port: 22, proto: tcp, comment: ssh}
|
||||
|
||||
@@ -41,26 +41,34 @@
|
||||
ReadWritePaths=
|
||||
User=
|
||||
|
||||
# Stand-in releases for verify's update path, behind file:// URLs: the role's download, checksum
|
||||
# check and swap run unchanged, without fetching two more real releases per host. The converge
|
||||
# traefik passes its rules through the mortis.kamino.ufw service_rules entry point, which needs ufw
|
||||
# installed and active. ufw_rules comes from the inventory group_vars (the SSH allow rule the
|
||||
# lock-out guard requires); the ufw scenario tests that role, so it runs once here, not in converge.
|
||||
- name: Install and enable ufw
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
roles:
|
||||
- role: mortis.kamino.ufw
|
||||
|
||||
# A stand-in release for verify's update path, behind a file:// URL: the role's download, checksum
|
||||
# check and swap run unchanged, without fetching another real release per host. The converge
|
||||
# still downloads the real role default from GitHub.
|
||||
- name: Prepare the stand-in releases
|
||||
- name: Prepare the stand-in release
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- ../../defaults/main.yml
|
||||
vars:
|
||||
traefik_test_release: "{{ traefik_verify_other_version }}"
|
||||
tasks:
|
||||
- name: Create a directory per stand-in release
|
||||
- name: Create the stand-in release directory
|
||||
ansible.builtin.file:
|
||||
path: "/opt/molecule-download/{{ traefik_test_release }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
|
||||
loop_control:
|
||||
loop_var: traefik_test_release
|
||||
|
||||
# Answers `version` like Traefik and otherwise stays up like the service.
|
||||
- name: Write the stand-in binaries
|
||||
- name: Write the stand-in binary
|
||||
ansible.builtin.copy:
|
||||
dest: "/opt/molecule-download/{{ traefik_test_release }}/traefik"
|
||||
mode: "0755"
|
||||
@@ -70,25 +78,16 @@
|
||||
version) echo "Version: {{ traefik_test_release | regex_replace('^v', '') }}" ;;
|
||||
*) exec sleep infinity ;;
|
||||
esac
|
||||
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
|
||||
loop_control:
|
||||
loop_var: traefik_test_release
|
||||
|
||||
- name: Pack the stand-in archives
|
||||
- name: Pack the stand-in archive
|
||||
ansible.builtin.command:
|
||||
argv: [tar, -czf, "{{ traefik_test_archive }}", -C, "/opt/molecule-download/{{ traefik_test_release }}", traefik]
|
||||
creates: "{{ traefik_test_archive }}"
|
||||
vars:
|
||||
traefik_test_archive: "/opt/molecule-download/{{ traefik_test_release }}/traefik_{{ traefik_test_release }}_{{ traefik_os }}_{{ traefik_arch }}.tar.gz"
|
||||
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
|
||||
loop_control:
|
||||
loop_var: traefik_test_release
|
||||
|
||||
- name: Write the checksums files in the release format
|
||||
- name: Write the checksums file in the release format
|
||||
ansible.builtin.shell:
|
||||
cmd: sha256sum traefik_*.tar.gz > traefik_{{ traefik_test_release }}_checksums.txt
|
||||
chdir: "/opt/molecule-download/{{ traefik_test_release }}"
|
||||
creates: "traefik_{{ traefik_test_release }}_checksums.txt"
|
||||
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
|
||||
loop_control:
|
||||
loop_var: traefik_test_release
|
||||
@@ -293,11 +293,11 @@
|
||||
traefik_ufw_key_443: "{{ ('allow|443|||||in' | hash('sha1'))[:10] }}"
|
||||
traefik_ufw_tagged: "{{ traefik_ufw_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list }}"
|
||||
|
||||
# A version bump through the update path and mortis.kamino._binary_update: down to another
|
||||
# release and back to the role default, both with traefik_update, from prepare.yml's stand-ins.
|
||||
# After the idempotence step, because each run changes the binary, and before the remove path.
|
||||
# A version bump through the update path and mortis.kamino._binary_update: to another release
|
||||
# with traefik_update, from prepare.yml's stand-in. One bump covers the download, checksum check
|
||||
# and swap. After the idempotence step, because it changes the binary, and before the remove path.
|
||||
# It leaves the stand-in stub installed, so nothing after it may assert real Traefik behaviour.
|
||||
- name: Verify the update path with stand-in releases
|
||||
- name: Verify the update path with a stand-in release
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
@@ -309,13 +309,10 @@
|
||||
fail_msg: Move traefik_verify_other_version off the role default ({{ traefik_version }}).
|
||||
quiet: true
|
||||
|
||||
- name: Update to the other release, then back to the role default
|
||||
- name: Update to the other release
|
||||
ansible.builtin.include_tasks: tasks/update_and_check.yml
|
||||
loop:
|
||||
- "{{ traefik_verify_other_version }}"
|
||||
- "{{ traefik_version }}"
|
||||
loop_control:
|
||||
loop_var: traefik_verify_target
|
||||
vars:
|
||||
traefik_verify_target: "{{ traefik_verify_other_version }}"
|
||||
|
||||
# The remove path. Last on purpose: it destroys what the plays above verify, and it runs
|
||||
# once, outside the idempotence step (a converge play that changed state would fail that step).
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
- logrotate
|
||||
state: present
|
||||
update_cache: true
|
||||
cache_valid_time: 3600
|
||||
tags: [traefik, prereqs, always]
|
||||
|
||||
- name: Create Traefik group
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
# Only runs that apply the role; the refusal cases are in verify.yml.
|
||||
- name: Converge with an SSH rule and service rules
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
# The role reads no facts; ufw_ssh_port defaults from ansible_port.
|
||||
gather_facts: false
|
||||
roles:
|
||||
- role: mortis.kamino.ufw
|
||||
vars:
|
||||
@@ -17,14 +18,15 @@
|
||||
# no proto: both protocols, and the guard must cope with the key missing
|
||||
- {rule: allow, port: 9090, comment: metrics}
|
||||
|
||||
# The service_rules entry point. prepare.yml stored a stale rule for svc_c,
|
||||
# a rule of the removed service svc_d and a stale rule for svc_e, so every pass here
|
||||
# is a no-op after the first one, purge included.
|
||||
# The service_rules entry point. prepare.yml stored a stale rule for svc_a, stale rules for
|
||||
# svc_c and a rule of the removed service svc_d, so every pass here is a no-op after the
|
||||
# first one, purge included. svc_c purges after svc_a ran, so svc_a's stale rule surviving
|
||||
# proves a purge touches only its own owner.
|
||||
- name: Converge the rules of several services through the entry point
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Two rules for svc_a
|
||||
- name: Keep the stale rule of svc_a because purging is off
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
tasks_from: service_rules
|
||||
@@ -33,18 +35,16 @@
|
||||
ufw_service_rules:
|
||||
- {rule: allow, port: 8001, proto: tcp, comment: alpha web}
|
||||
- {rule: allow, port: 8002, proto: udp, from: 10.1.0.0/16, comment: alpha dns}
|
||||
|
||||
- name: Two rules for svc_b, one without a comment
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
tasks_from: service_rules
|
||||
vars:
|
||||
ufw_service_name: svc_b
|
||||
ufw_service_rules:
|
||||
- {rule: allow, port: 8003, proto: tcp, comment: beta}
|
||||
# No comment and no proto: the tag alone, and both protocols.
|
||||
- {rule: deny, port: 8004}
|
||||
# A comment that mentions the SSH port on another port.
|
||||
- {rule: allow, port: 8022, proto: tcp, comment: forward to 22 here}
|
||||
- {rule: allow, port: 7201, proto: tcp, comment: epsilon}
|
||||
|
||||
- name: Keep one rule for svc_c and purge its stale rule
|
||||
# Of the stale rules, only 7001 and 7601 are single numeric ports; the SSH lookalike, the
|
||||
# rule with no port, the source-only rule and the range are kept as possible SSH paths.
|
||||
- name: Purge the stale rules of svc_c except those that may carry SSH
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
tasks_from: service_rules
|
||||
@@ -53,6 +53,8 @@
|
||||
ufw_purge_stale: true
|
||||
ufw_service_rules:
|
||||
- {rule: allow, port: 7101, proto: tcp, comment: gamma}
|
||||
- {rule: allow, port: 7301, proto: tcp, comment: eta}
|
||||
- {rule: allow, port: 7602, proto: tcp, comment: desired}
|
||||
|
||||
- name: Remove svc_d, which deletes without ufw_purge_stale
|
||||
ansible.builtin.include_role:
|
||||
@@ -62,50 +64,6 @@
|
||||
ufw_service_name: svc_d
|
||||
ufw_service_state: absent
|
||||
|
||||
- name: Keep the stale rule of svc_e because purging is off
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
tasks_from: service_rules
|
||||
vars:
|
||||
ufw_service_name: svc_e
|
||||
ufw_service_rules:
|
||||
- {rule: allow, port: 7201, proto: tcp, comment: epsilon}
|
||||
|
||||
- name: A comment that mentions the SSH port on another port
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
tasks_from: service_rules
|
||||
vars:
|
||||
ufw_service_name: svc_g
|
||||
ufw_service_rules:
|
||||
- {rule: allow, port: 8022, proto: tcp, comment: forward to 22 here}
|
||||
|
||||
- name: Purge svc_h without touching its stale rule that looks like the SSH rule
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
tasks_from: service_rules
|
||||
vars:
|
||||
ufw_service_name: svc_h
|
||||
ufw_purge_stale: true
|
||||
ufw_service_rules:
|
||||
- {rule: allow, port: 7301, proto: tcp, comment: eta}
|
||||
|
||||
- name: Purge svc_p but keep its stale rules that may carry SSH
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
# prepare.yml stored four stale rules for svc_p: a numeric port (deleted), and a rule
|
||||
# with no port, a source-only rule and a range, which are kept as possible SSH paths.
|
||||
- name: Keep one rule for svc_p and purge its stale rules
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
tasks_from: service_rules
|
||||
vars:
|
||||
ufw_service_name: svc_p
|
||||
ufw_purge_stale: true
|
||||
ufw_service_rules:
|
||||
- {rule: allow, port: 7602, proto: tcp, comment: desired}
|
||||
|
||||
# The orphan_rules entry point. prepare.yml stored two rules of svc_o1, a rule of
|
||||
# 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
|
||||
@@ -118,14 +76,9 @@
|
||||
vars:
|
||||
ufw_converge_managed:
|
||||
- svc_a
|
||||
- svc_b
|
||||
- svc_c
|
||||
- svc_d
|
||||
- svc_e
|
||||
- svc_g
|
||||
- svc_h
|
||||
- svc_m
|
||||
- svc_p
|
||||
tasks:
|
||||
# The marker is written after the purge, so the expected counts are absolute on both
|
||||
# passes: svc_o1 holds 2 rules before the purge and 0 once the marker exists.
|
||||
@@ -138,9 +91,6 @@
|
||||
ansible.builtin.set_fact:
|
||||
ufw_conv_o1_initial: "{{ 0 if ufw_conv_marker.stat.exists else 2 }}"
|
||||
|
||||
- name: Assert it before the first case
|
||||
ansible.builtin.include_tasks: tasks/orphan_check.yml
|
||||
|
||||
- name: No managed owners given, purge requested
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
@@ -148,9 +98,6 @@
|
||||
vars:
|
||||
ufw_purge_orphans: true
|
||||
|
||||
- name: Nothing was deleted without a list
|
||||
ansible.builtin.include_tasks: tasks/orphan_check.yml
|
||||
|
||||
- name: An empty list of managed owners, purge requested
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
@@ -159,9 +106,6 @@
|
||||
ufw_managed_owners: []
|
||||
ufw_purge_orphans: true
|
||||
|
||||
- name: Nothing was deleted with an empty list
|
||||
ansible.builtin.include_tasks: tasks/orphan_check.yml
|
||||
|
||||
- name: Report the orphans only
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
@@ -170,7 +114,8 @@
|
||||
ufw_managed_owners: "{{ ufw_converge_managed }}"
|
||||
ufw_purge_orphans: false
|
||||
|
||||
- name: Reporting deleted nothing
|
||||
# The counts are absolute, so one check proves none of the three cases above deleted.
|
||||
- name: The cases without a purge deleted nothing
|
||||
ansible.builtin.include_tasks: tasks/orphan_check.yml
|
||||
|
||||
- name: Purge the orphans
|
||||
|
||||
@@ -39,9 +39,9 @@
|
||||
proto: tcp
|
||||
comment: replaced
|
||||
|
||||
# Owners svc_c, svc_d and svc_e keep rules in converge.yml that these entries are
|
||||
# not part of: a stale rule to purge, a rule of a removed service, a stale rule
|
||||
# that is only reported.
|
||||
# Owners svc_a, svc_c and svc_d keep rules in converge.yml that these entries are
|
||||
# not part of: a stale rule that is only reported, stale rules to purge, a rule of
|
||||
# a removed service.
|
||||
- name: Store tagged rules that are no longer wanted
|
||||
community.general.ufw:
|
||||
rule: allow
|
||||
@@ -56,9 +56,10 @@
|
||||
# svc_c: the old spec of a rule whose port changed (key of allow|7001|tcp||||in)
|
||||
- {port: 7001, comment: "ansible-ufw[svc_c:128c086248]: old"}
|
||||
- {port: 7002, comment: "ansible-ufw[svc_d:abcdef0123]: gone"}
|
||||
- {port: 7003, comment: "ansible-ufw[svc_e:aaaaaaaaaa]: kept"}
|
||||
# svc_h: a stale rule that looks like an SSH rule, which a purge must skip
|
||||
- {port: 22, from: 10.9.0.0/16, comment: "ansible-ufw[svc_h:bbbbbbbbbb]: old"}
|
||||
# svc_a: a stale rule kept because svc_a does not purge, while svc_c's purge runs
|
||||
- {port: 7003, comment: "ansible-ufw[svc_a:aaaaaaaaaa]: kept"}
|
||||
# svc_c: a stale rule that looks like an SSH rule, which a purge must skip
|
||||
- {port: 22, from: 10.9.0.0/16, comment: "ansible-ufw[svc_c:bbbbbbbbbb]: old"}
|
||||
# orphan_rules: svc_o1 and svc_o2 are never listed as managed owners in converge.yml.
|
||||
# svc_o2's rule looks like the SSH rule and must survive a purge; svc_m is managed
|
||||
# but its role is never called, so its rule must survive too.
|
||||
@@ -73,11 +74,11 @@
|
||||
- {from: 10.20.0.0/24, comment: "ansible-ufw[svc_o3:5555555552]: source only"}
|
||||
- {port: "20:30", comment: "ansible-ufw[svc_o3:5555555553]: range over 22"}
|
||||
- {name: OrphanOpenSSH, comment: "ansible-ufw[svc_o3:5555555554]: openssh profile"}
|
||||
# service_rules purge of svc_p (converge.yml keeps only a rule for 7602): 7601 is stale
|
||||
# and deleted, the other three are stale and may carry SSH, so they stay.
|
||||
- {port: 7601, comment: "ansible-ufw[svc_p:6666666664]: stale numeric"}
|
||||
- {interface: wg0, direction: in, comment: "ansible-ufw[svc_p:6666666661]: no port"}
|
||||
- {from: 10.30.0.0/24, comment: "ansible-ufw[svc_p:6666666662]: source only"}
|
||||
- {port: "40:50", comment: "ansible-ufw[svc_p:6666666663]: range"}
|
||||
# svc_c again: 7601 is stale and deleted by its purge, the other three are stale and
|
||||
# may carry SSH, so they stay.
|
||||
- {port: 7601, comment: "ansible-ufw[svc_c:6666666664]: stale numeric"}
|
||||
- {interface: wg0, direction: in, comment: "ansible-ufw[svc_c:6666666661]: no port"}
|
||||
- {from: 10.30.0.0/24, comment: "ansible-ufw[svc_c:6666666662]: source only"}
|
||||
- {port: "40:50", comment: "ansible-ufw[svc_c:6666666663]: range"}
|
||||
loop_control:
|
||||
loop_var: ufw_prepare_rule
|
||||
@@ -1,9 +1,9 @@
|
||||
---
|
||||
# Included by converge.yml and verify.yml after each orphan_rules case. The counts are
|
||||
# absolute: svc_o1 holds ufw_conv_o1_want rules (default ufw_conv_o1_initial: 2 before the
|
||||
# purge, 0 after), and the tagged total is 20 plus those. The 20: svc_a 2, svc_b 2, svc_c 1,
|
||||
# svc_e 2, svc_g 1, svc_h 2, svc_m 1, svc_o2 1, svc_o3 4 (kept orphans that may carry SSH),
|
||||
# svc_p 4 (its desired rule and three kept stale rules).
|
||||
# Included by converge.yml around the orphan_rules cases. The counts are absolute: svc_o1
|
||||
# holds ufw_conv_o1_want rules (default ufw_conv_o1_initial: 2 before the purge, 0 after),
|
||||
# and the tagged total is 20 plus those. The 20: svc_a 7 (six desired, one stale), svc_c 7
|
||||
# (three desired, four stale kept as possible SSH paths), svc_m 1, svc_o2 1, svc_o3 4 (kept
|
||||
# orphans that may carry SSH).
|
||||
- name: Read the rules ufw would load
|
||||
ansible.builtin.command: ufw show added
|
||||
register: ufw_conv_added
|
||||
@@ -18,8 +18,8 @@
|
||||
- ufw_conv_added.stdout_lines | select('search', 'svc_o2:3333333333') | list | length == 1
|
||||
- ufw_conv_added.stdout_lines | select('search', 'svc_o3:555555555[1-4]') | list | length == 4
|
||||
- ufw_conv_added.stdout_lines | select('search', 'svc_m:4444444444') | list | length == 1
|
||||
- ufw_conv_added.stdout_lines | select('search', 'svc_p:666666666[123]') | list | length == 3
|
||||
- ufw_conv_added.stdout_lines | select('search', 'svc_p:6666666664') | list | length == 0
|
||||
- ufw_conv_added.stdout_lines | select('search', 'svc_c:666666666[123]') | list | length == 3
|
||||
- ufw_conv_added.stdout_lines | select('search', 'svc_c:6666666664') | list | length == 0
|
||||
- ufw_conv_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list | length == 20 + ufw_conv_o1_count | int
|
||||
- ufw_conv_added.stdout_lines | select('match', '^ufw ') | reject('search', 'ansible-ufw') | list | length == 5
|
||||
fail_msg: "Unexpected rules after the orphan_rules case: {{ ufw_conv_added.stdout_lines }}"
|
||||
|
||||
@@ -306,12 +306,6 @@
|
||||
that: "'ufw_managed_owners must be a list of strings matching' in ufw_verify_failure"
|
||||
quiet: true
|
||||
|
||||
# Converge's last play purged svc_o1 (want 0); svc_o2, svc_m and the tagged total carry the proof.
|
||||
- name: Nothing was deleted after the invalid owner
|
||||
ansible.builtin.include_tasks: tasks/orphan_check.yml
|
||||
vars:
|
||||
ufw_conv_o1_want: 0
|
||||
|
||||
- name: Verify
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
@@ -385,12 +379,12 @@
|
||||
that:
|
||||
- ufw_verify_tagged | select('search', ufw_verify_svc_a_web) | list | length == 1
|
||||
- 'ufw_verify_tagged | select("search", "8002.*ansible-ufw\[svc_a:[0-9a-f]{10}\]: alpha dns") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "8003.*ansible-ufw\[svc_b:[0-9a-f]{10}\]: beta") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "8004.*ansible-ufw\[svc_b:[0-9a-f]{10}\]:.$") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "8003.*ansible-ufw\[svc_a:[0-9a-f]{10}\]: beta") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "8004.*ansible-ufw\[svc_a:[0-9a-f]{10}\]:.$") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "7201.*ansible-ufw\[svc_a:[0-9a-f]{10}\]: epsilon") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "8022/tcp comment .ansible-ufw\[svc_a:[0-9a-f]{10}\]: forward to 22 here") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "7101.*ansible-ufw\[svc_c:[0-9a-f]{10}\]: gamma") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "7201.*ansible-ufw\[svc_e:[0-9a-f]{10}\]: epsilon") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "8022/tcp comment .ansible-ufw\[svc_g:[0-9a-f]{10}\]: forward to 22 here") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "7301.*ansible-ufw\[svc_h:[0-9a-f]{10}\]: eta") | list | length == 1'
|
||||
- 'ufw_verify_tagged | select("search", "7301.*ansible-ufw\[svc_c:[0-9a-f]{10}\]: eta") | list | length == 1'
|
||||
quiet: true
|
||||
vars:
|
||||
ufw_verify_tagged: "{{ ufw_verify_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list }}"
|
||||
@@ -402,15 +396,14 @@
|
||||
that:
|
||||
- ufw_verify_added.stdout_lines | select('search', 'svc_c:128c086248') | list | length == 0
|
||||
- ufw_verify_added.stdout_lines | select('search', 'svc_d:') | list | length == 0
|
||||
- ufw_verify_added.stdout_lines | select('search', '7003.*svc_e:aaaaaaaaaa') | list | length == 1
|
||||
- ufw_verify_added.stdout_lines | select('search', 'svc_h:bbbbbbbbbb') | list | length == 1
|
||||
- ufw_verify_added.stdout_lines | select('search', '7003.*svc_a:aaaaaaaaaa') | list | length == 1
|
||||
- ufw_verify_added.stdout_lines | select('search', 'svc_c:bbbbbbbbbb') | list | length == 1
|
||||
- ufw_verify_added.stdout_lines | select('search', 'ansible-ufw') | list | length == 20
|
||||
quiet: true
|
||||
|
||||
# Twenty tagged rules: svc_a 2, svc_b 2, svc_c 1, svc_e 2, svc_g 1, svc_h 2, svc_m 1, the
|
||||
# SSH lookalike of svc_o2, four orphans of svc_o3 and four rules of svc_p (its desired
|
||||
# rule and three stale ones). Both rules of svc_o1 and the numeric stale rule of svc_p were
|
||||
# deleted; the kept ones may carry SSH.
|
||||
# Twenty tagged rules: svc_a 7 (six desired, one stale), svc_c 7 (three desired, four stale),
|
||||
# svc_m 1, the SSH lookalike of svc_o2 and four orphans of svc_o3. Both rules of svc_o1 and
|
||||
# the numeric stale rules of svc_c were deleted; the kept ones may carry SSH.
|
||||
- name: Orphans were purged except those that may carry SSH, a managed owner kept its rule
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
@@ -426,12 +419,12 @@
|
||||
- name: The stale purge of service_rules kept the lines that may carry SSH
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ufw_verify_added.stdout_lines | select('search', 'svc_p:6666666664') | list | length == 0
|
||||
- ufw_verify_added.stdout_lines | select('search', 'svc_c:6666666664') | list | length == 0
|
||||
- ufw_verify_added.stdout_lines | select('search', '7601') | list | length == 0
|
||||
- ufw_verify_added.stdout_lines | select('search', 'wg0.*svc_p:6666666661') | list | length == 1
|
||||
- ufw_verify_added.stdout_lines | select('search', '10\.30\.0\.0/24.*svc_p:6666666662') | list | length == 1
|
||||
- ufw_verify_added.stdout_lines | select('search', '40:50.*svc_p:6666666663') | list | length == 1
|
||||
- 'ufw_verify_added.stdout_lines | select("search", "7602.*ansible-ufw\\[svc_p:[0-9a-f]{10}\\]: desired") | list | length == 1'
|
||||
- ufw_verify_added.stdout_lines | select('search', 'wg0.*svc_c:6666666661') | list | length == 1
|
||||
- ufw_verify_added.stdout_lines | select('search', '10\.30\.0\.0/24.*svc_c:6666666662') | list | length == 1
|
||||
- ufw_verify_added.stdout_lines | select('search', '40:50.*svc_c:6666666663') | list | length == 1
|
||||
- 'ufw_verify_added.stdout_lines | select("search", "7602.*ansible-ufw\\[svc_c:[0-9a-f]{10}\\]: desired") | list | length == 1'
|
||||
quiet: true
|
||||
|
||||
- name: No rejected input left a rule behind
|
||||
@@ -506,7 +499,7 @@
|
||||
ufw_service_rules:
|
||||
- {rule: allow, port: 7701, proto: tcp, comment: check mode}
|
||||
|
||||
- name: An absent call for svc_a, which holds two rules
|
||||
- name: An absent call for svc_a, which holds seven rules
|
||||
ansible.builtin.include_role:
|
||||
name: mortis.kamino.ufw
|
||||
tasks_from: service_rules
|
||||
@@ -524,7 +517,7 @@
|
||||
- name: Check mode added and deleted nothing
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- ufw_verify_chk_before.stdout_lines | select('search', 'svc_a:') | list | length == 2
|
||||
- ufw_verify_chk_before.stdout_lines | select('search', 'svc_a:') | list | length == 7
|
||||
- ufw_verify_chk_after.stdout_lines == ufw_verify_chk_before.stdout_lines
|
||||
- ufw_verify_chk_after.stdout_lines | select('search', 'svc_chk|7701') | list | length == 0
|
||||
quiet: true
|
||||
@@ -1,17 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
# The Molecule workflow's "Run the scenarios" step: `molecule test` for each scenario directory on
|
||||
# stdin, MOLECULE_LANES (default 4) at a time, each with its own log and ANSIBLE_HOME under
|
||||
# <work-dir>/<n>/ (no collection is installed there: .config/molecule/config.yml sets prerun false).
|
||||
# stdin, MOLECULE_LANES (default 2, also when empty) at a time, longest first, each with its own
|
||||
# log and ANSIBLE_HOME under <work-dir>/<n>/ (no collection is installed there:
|
||||
# .config/molecule/config.yml sets prerun false). A scenario still running after
|
||||
# MOLECULE_SCENARIO_TIMEOUT seconds (default 1800, also when empty) is stopped and fails; the
|
||||
# variable is for local runs and tests: the workflow does not pass it into the ci container.
|
||||
# Exit 1 on a failure.
|
||||
#
|
||||
# scripts/run_molecule_scenarios.sh <work-dir> < scenario-dirs
|
||||
set -euo pipefail
|
||||
|
||||
lanes="${MOLECULE_LANES:-4}"
|
||||
# 2: a full run took 34 min at 2 lanes and 35 at 4, so more lanes only slow each scenario.
|
||||
lanes="${MOLECULE_LANES:-2}"
|
||||
if ! [[ "$lanes" =~ ^[1-9][0-9]*$ ]]; then
|
||||
echo "MOLECULE_LANES must be a positive integer, not '$lanes'" >&2
|
||||
exit 2
|
||||
fi
|
||||
# 1800: the longest scenario takes about 8.5 min, and at the default 2 lanes two hung ones plus the
|
||||
# rest still end inside the job's 90 min, so a hang fails on its own with its log printed.
|
||||
limit="${MOLECULE_SCENARIO_TIMEOUT:-1800}"
|
||||
if ! [[ "$limit" =~ ^[1-9][0-9]*$ ]]; then
|
||||
echo "MOLECULE_SCENARIO_TIMEOUT must be a positive integer, not '$limit'" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "usage: $0 <work-dir> < scenario-dirs" >&2
|
||||
exit 2
|
||||
@@ -60,8 +71,16 @@ run_one() {
|
||||
export ANSIBLE_HOME="$out/ansible"
|
||||
# a role scenario runs from its role's directory, as molecule expects
|
||||
case "$dir" in roles/*) cd "${dir%/molecule/*}" || exit 1 ;; esac
|
||||
molecule test -s "${dir##*/}"
|
||||
# --foreground keeps timeout and molecule in this script's process group, so a cancel that
|
||||
# kills the group still reaches them. On expiry it signals molecule alone: its ansible-playbook
|
||||
# and workers run on until the run container ends, and the workflow's "Remove this run's
|
||||
# containers" step removes any container they recreate late.
|
||||
timeout --foreground --kill-after=30 "$limit" molecule test -s "${dir##*/}"
|
||||
) >"$out/log" 2>&1 </dev/null || rc=$?
|
||||
# 124 after TERM, 137 when the KILL of --kill-after was needed
|
||||
if { [ "$rc" -eq 124 ] || [ "$rc" -eq 137 ]; } && [ "$((SECONDS - start))" -ge "$limit" ]; then
|
||||
echo "timed out after $limit s" >>"$out/log"
|
||||
fi
|
||||
if ! remove_instances "$dir" >>"$out/log" 2>&1; then
|
||||
echo "could not remove the containers of $dir" >>"$out/log"
|
||||
if [ "$rc" -eq 0 ]; then rc=1; fi
|
||||
@@ -77,6 +96,38 @@ while IFS= read -r dir; do
|
||||
done
|
||||
mkdir -p "$work"
|
||||
|
||||
# Seconds each scenario took in the last full run at the default lane count, so the longest start
|
||||
# first and none started late sets the end of the run. Keyed by scenario directory, not label:
|
||||
# refresh from a full run's `finished <label>: exit 0 after S s` lines, each label mapped back to
|
||||
# its directory. A scenario missing here is assumed long and starts first.
|
||||
declare -A last_seconds=(
|
||||
[roles/system_baseline/molecule/default]=568
|
||||
[roles/ufw/molecule/default]=525
|
||||
[roles/traefik/molecule/default]=484
|
||||
[roles/gitea_runner/molecule/default]=398
|
||||
[roles/docker/molecule/default]=352
|
||||
[roles/cloudflared/molecule/default]=305
|
||||
[roles/tailscale/molecule/default]=220
|
||||
[roles/fail2ban/molecule/default]=161
|
||||
[roles/gitea/molecule/default]=137
|
||||
[roles/systemd_hardening/molecule/default]=134
|
||||
[roles/_binary_update/molecule/default]=132
|
||||
[roles/nfs_client/molecule/default]=126
|
||||
[roles/user_management/molecule/default]=115
|
||||
[roles/pihole/molecule/default]=112
|
||||
[roles/sshd/molecule/default]=65
|
||||
[roles/pve_lxc/molecule/default]=44
|
||||
[roles/_binary_update/molecule/check_mode]=42
|
||||
[roles/network_interfaces/molecule/default]=36
|
||||
[extensions/molecule/image-smoke]=25
|
||||
[extensions/molecule/image-smoke-2604]=21
|
||||
)
|
||||
# The indices of dirs in start order; ties keep the selection order (a stable sort).
|
||||
mapfile -t start_order < <(
|
||||
for n in "${!dirs[@]}"; do printf '%s %s\n' "${last_seconds[${dirs[$n]}]:-999999}" "$n"; done |
|
||||
sort -s -k1,1nr | cut -d' ' -f2
|
||||
)
|
||||
|
||||
# A cancelled job must not leave lanes behind that recreate containers after the next run's
|
||||
# cleanup. A signal to this script stops each lane's tree so it cannot fork, then terminates it,
|
||||
# with the whole group of any descendant that leads one: ansible's workers detach into their own.
|
||||
@@ -110,7 +161,7 @@ trap 'stop_lanes 143' TERM
|
||||
trap 'stop_lanes 130' INT
|
||||
trap 'stop_lanes 129' HUP
|
||||
|
||||
for n in "${!dirs[@]}"; do
|
||||
for n in "${start_order[@]}"; do
|
||||
while [ "$(jobs -rp | wc -l)" -ge "$lanes" ]; do wait -n || true; done
|
||||
run_one "$n" "${dirs[$n]}" </dev/null &
|
||||
done
|
||||
|
||||
@@ -42,7 +42,9 @@ exit 0
|
||||
|
||||
# The scenario runner: records its arguments, paths and stdin.
|
||||
RUNNER_STUB = """#!/usr/bin/env bash
|
||||
echo "runner args=$* path=$PATH acp=$ANSIBLE_COLLECTIONS_PATH inject=${ANSIBLE_INJECT_FACT_VARS-unset} stdin=[$(cat | tr '\\n' ' ')]" >> "$STUB_LOG"
|
||||
echo "runner args=$* path=$PATH acp=$ANSIBLE_COLLECTIONS_PATH" \\
|
||||
"inject=${ANSIBLE_INJECT_FACT_VARS-unset} lanes=${MOLECULE_LANES-unset}" \\
|
||||
"stdin=[$(cat | tr '\\n' ' ')]" >> "$STUB_LOG"
|
||||
"""
|
||||
|
||||
|
||||
@@ -161,6 +163,12 @@ class RunMoleculeInCiImageTest(unittest.TestCase):
|
||||
runner,
|
||||
)
|
||||
|
||||
def test_the_lane_count_reaches_the_scenario_runner(self):
|
||||
result = self.run_script(MOLECULE_LANES="3")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
(runner,) = self.calls("runner")
|
||||
self.assertIn(" lanes=3 ", runner)
|
||||
|
||||
def test_the_load_check_sees_the_selection_and_the_final_path(self):
|
||||
selection = "roles/alpha/molecule/default\nextensions/molecule/image-smoke\n"
|
||||
result = self.run_script(selection, STUB_FAIL_sha256sum="1")
|
||||
|
||||
@@ -28,9 +28,10 @@ RUN_LABEL = "net.rkdr.mortis.molecule-run"
|
||||
HAS_MOLECULE = importlib.util.find_spec("molecule") is not None
|
||||
NEEDS_MOLECULE = "the run script imports molecule to expand platform names"
|
||||
|
||||
# Records what each run saw, then behaves as STUB_<scenario label> asks: fail, sleep, hang (and
|
||||
# record its pids), detach (as an ansible worker does, into its own process group, whose orphaned
|
||||
# child no parent link reaches; record both), or read stdin (which must be empty).
|
||||
# Records what each run saw, then behaves as STUB_<scenario label> asks: fail, sleep, stall (past
|
||||
# a short time limit), hang (and record its pids), detach (as an ansible worker does, into its own
|
||||
# process group, whose orphaned child no parent link reaches; record both), or read stdin (which
|
||||
# must be empty).
|
||||
MOLECULE_STUB = """#!/usr/bin/env bash
|
||||
label="$(basename "$PWD")/$3"
|
||||
[ "$PWD" = "$STUB_ROOT" ] && label="$3"
|
||||
@@ -40,6 +41,7 @@ echo "output of $label"
|
||||
case "${!key:-}" in
|
||||
fail) echo "$label end $(date +%s.%N)" >> "$STUB_LOG"; exit 2 ;;
|
||||
sleep) sleep 1 ;;
|
||||
stall) exec sleep 30 ;;
|
||||
hang) sleep 60 & echo "$$ $!" >> "$STUB_PIDS"; wait ;;
|
||||
detach)
|
||||
setsid bash -c '(sleep 60 & echo $! >> "$STUB_PIDS"); echo $$ >> "$STUB_PIDS"; exec sleep 60' &
|
||||
@@ -283,6 +285,46 @@ class RunMoleculeScenariosTest(unittest.TestCase):
|
||||
self.assertEqual(proc.returncode, 1)
|
||||
self.assertIn("::error::ran 1 of 2 selected scenarios", proc.stdout)
|
||||
|
||||
@unittest.skipUnless(HAS_MOLECULE, NEEDS_MOLECULE)
|
||||
def test_the_longest_scenarios_start_first(self):
|
||||
# an unlisted scenario counts as longest; the groups keep the selection order
|
||||
seconds = listed_seconds()
|
||||
roles = [d for d in seconds if d.startswith("roles/")]
|
||||
shortest, longest = min(roles, key=seconds.get), max(roles, key=seconds.get)
|
||||
for scenario in (shortest, longest):
|
||||
d = self.root / scenario
|
||||
d.mkdir(parents=True)
|
||||
name = f"{RUN_ID}-{scenario.replace('/', '-')}"
|
||||
platforms = [{"name": name, "image": "${MOLECULE_IMAGE}"}]
|
||||
(d / "molecule.yml").write_text(yaml.safe_dump({"platforms": platforms}))
|
||||
smoke = "extensions/molecule/image-smoke"
|
||||
order = [smoke, shortest, "roles/alpha/molecule/default", longest]
|
||||
listed = sorted((smoke, shortest, longest), key=seconds.get, reverse=True)
|
||||
proc = self.run_script(order, MOLECULE_LANES="1")
|
||||
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
|
||||
spans = self.events()
|
||||
self.assertEqual(
|
||||
sorted(spans, key=lambda label: spans[label][0]),
|
||||
[label(d) for d in ["roles/alpha/molecule/default", *listed]],
|
||||
)
|
||||
groups = re.findall(
|
||||
r"^::group::molecule test: (\S+) ", proc.stdout, re.MULTILINE
|
||||
)
|
||||
self.assertEqual(groups, [label(d) for d in order])
|
||||
|
||||
def test_the_duration_list_names_existing_scenarios(self):
|
||||
# a renamed scenario would otherwise drop out of the list unnoticed
|
||||
listed = listed_seconds()
|
||||
self.assertTrue(listed)
|
||||
for scenario in listed:
|
||||
self.assertTrue((REPO / scenario / "molecule.yml").is_file(), scenario)
|
||||
|
||||
@unittest.skipUnless(HAS_MOLECULE, NEEDS_MOLECULE)
|
||||
def test_empty_lanes_are_accepted(self):
|
||||
# the workflow passes an empty value outside a manual dispatch
|
||||
proc = self.run_script(list(PLATFORMS), MOLECULE_LANES="")
|
||||
self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr)
|
||||
|
||||
def test_lanes_must_be_a_positive_integer(self):
|
||||
for lanes in ("0", "-1", "two", "04"):
|
||||
proc = self.run_script(list(PLATFORMS), MOLECULE_LANES=lanes)
|
||||
@@ -290,6 +332,45 @@ class RunMoleculeScenariosTest(unittest.TestCase):
|
||||
self.assertIn("MOLECULE_LANES must be a positive integer", proc.stderr)
|
||||
self.assertEqual(self.log.read_text(), "")
|
||||
|
||||
@unittest.skipUnless(HAS_MOLECULE, NEEDS_MOLECULE)
|
||||
def test_a_scenario_past_its_time_limit_fails_alone(self):
|
||||
# one lane, and alpha first (both unlisted, so the selection order holds): beta runs only
|
||||
# if the stalled lane is freed
|
||||
proc = self.run_script(
|
||||
["roles/alpha/molecule/default", "roles/beta/molecule/default"],
|
||||
MOLECULE_LANES="1", MOLECULE_SCENARIO_TIMEOUT="2", STUB_alpha_default="stall",
|
||||
) # fmt: skip
|
||||
self.assertEqual(proc.returncode, 1)
|
||||
self.assertIn("::error::Failed: alpha/default\n", proc.stdout)
|
||||
self.assertIn("Scenarios run: 2", proc.stdout)
|
||||
body = proc.stdout.split("::group::molecule test: alpha/default")[1].split(
|
||||
"::endgroup::"
|
||||
)[0]
|
||||
self.assertIn("output of alpha/default", body)
|
||||
self.assertIn("timed out after 2 s", body)
|
||||
self.assertIn("output of beta/default", proc.stdout)
|
||||
self.assertIn(
|
||||
"remove local-alpha-instance force=True", self.docker_log.read_text()
|
||||
)
|
||||
|
||||
def test_the_default_time_limit_is_inside_the_job_timeout(self):
|
||||
# a limit past the job's own would let a hang take the job and every log with it
|
||||
timeout = yaml.safe_load(WORKFLOW.read_text())["jobs"]["molecule"][
|
||||
"timeout-minutes"
|
||||
]
|
||||
limit = re.findall(r"MOLECULE_SCENARIO_TIMEOUT:-(\d+)\}", SCRIPT.read_text())
|
||||
self.assertEqual(len(limit), 1)
|
||||
self.assertLess(int(limit[0]), timeout * 60)
|
||||
|
||||
def test_the_time_limit_must_be_a_positive_integer(self):
|
||||
for limit in ("0", "-1", "ten", "04"):
|
||||
proc = self.run_script(list(PLATFORMS), MOLECULE_SCENARIO_TIMEOUT=limit)
|
||||
self.assertEqual(proc.returncode, 2, limit)
|
||||
self.assertIn(
|
||||
"MOLECULE_SCENARIO_TIMEOUT must be a positive integer", proc.stderr
|
||||
)
|
||||
self.assertEqual(self.log.read_text(), "")
|
||||
|
||||
def start_hung_run(self, count=4, **stubs):
|
||||
"""A run in its own process group whose molecule stubs hang, and the pids they record."""
|
||||
pids = self.tmp / "pids"
|
||||
@@ -349,6 +430,20 @@ class RunMoleculeScenariosTest(unittest.TestCase):
|
||||
self.assertEqual(self.log.read_text(), "")
|
||||
|
||||
|
||||
def listed_seconds():
|
||||
"""{scenario directory: seconds} from the run script's duration list."""
|
||||
pairs = re.findall(r"^ \[([^]]+)\]=(\d+)$", SCRIPT.read_text(), re.MULTILINE)
|
||||
return {d: int(s) for d, s in pairs}
|
||||
|
||||
|
||||
def label(scenario):
|
||||
"""The run script's label of a scenario directory, as its log groups print it."""
|
||||
if scenario.startswith("extensions/"):
|
||||
return scenario.rsplit("/", 1)[1]
|
||||
parts = scenario.split("/")
|
||||
return f"{parts[1]}/{parts[3]}"
|
||||
|
||||
|
||||
def alive(pid):
|
||||
"""Whether pid is a running process, not gone or a zombie."""
|
||||
try:
|
||||
@@ -416,6 +511,20 @@ class ScenarioPlatformsTest(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class LanesInputTest(unittest.TestCase):
|
||||
"""A manual dispatch can set the lane count of the run script inside the run container."""
|
||||
|
||||
def test_the_dispatch_input_reaches_the_run_container(self):
|
||||
workflow = yaml.safe_load(WORKFLOW.read_text())
|
||||
# yaml reads the `on:` key as True
|
||||
lanes = workflow[True]["workflow_dispatch"]["inputs"]["lanes"]
|
||||
self.assertEqual((lanes["type"], lanes["default"]), ("string", ""))
|
||||
steps = workflow["jobs"]["molecule"]["steps"]
|
||||
step = next(s for s in steps if s.get("name") == "Run the scenarios")
|
||||
self.assertEqual(step["env"]["MOLECULE_LANES"], "${{ inputs.lanes }}")
|
||||
self.assertRegex(step["run"], r"docker run [^<]*-e MOLECULE_LANES\b")
|
||||
|
||||
|
||||
class ScenarioSequenceTest(unittest.TestCase):
|
||||
"""A role scenario previews the fresh host and the configured host with molecule's check step."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user