fix(roles): refresh apt in the docker and traefik scenarios and apply review round 2
Build / build (pull_request) Successful in 22s
Lint / lint (pull_request) Successful in 2m1s
Molecule / molecule (pull_request) Successful in 44m6s

The molecule images ship without apt lists, and --check does not
refresh them, so the fresh-host check of docker and traefik could not
find curl and wget. Their prepare now refreshes the cache, as pihole's
and system_baseline's already do by installing fixtures.

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

Assisted-by: Claude Code
This commit is contained in:
Defame1297 committed 2026-11-26 12:18:48 +00:00
1 parent 3afff00b9b
commit 9ce0fbd433
5 files changed
+42 -30

No files matched your search

+10 -10
View File
@@ -95,16 +95,16 @@ names a check that does not exist yet and its backlog issue.
- **Negative tests.** Every validation has one in `verify.yml` (or a file it includes):
block/rescue/assert matching the expected error message, run last or failing before any
change. *Why:* a bare "it failed" passes for the wrong error. *Held:* review.
- **Check mode.** Every scenario runs `check` before and after converge. The only guards are
`check_mode: false` on read-only probes and `when: not ansible_check_mode`, alone or as
`not ansible_check_mode or <condition>` where the condition shows the task can run, such as a
registered result that is not changed; `--check` is the supported preview, and the README says
a play-level `check_mode: true` is not supported. A role whose `--check` needs its package
installed says so in README Notes and keeps the step; a role that cannot support check mode at
all says why there and drops the step, with an exception in the test below. *Why:* check-mode
breakage is a frequent fix, and one guard pattern is reviewable. *Held:* Molecule for the run
passing, `tests/scripts/test_run_molecule_scenarios.py` for the steps being there; review for
the guards.
- **Check mode.** Every scenario runs `check` before and after converge. Guards:
`check_mode: false` on read-only probes, and `when: not ansible_check_mode`, alone or as
`not ansible_check_mode or <condition>` where the condition shows the task can run (such as a
registered result that is not changed). README: `--check` is the supported preview and a
play-level `check_mode: true` is not supported; a role whose `--check` needs its package
installed says so in Notes and keeps the step; a role that cannot support check mode at all
says why in Notes and drops the step, which also needs an exception in the test named below.
*Why:* check-mode breakage is a frequent fix, and one guard pattern is reviewable. *Held:*
Molecule for the run passing, `tests/scripts/test_run_molecule_scenarios.py` for the steps
being there; review for the guards.
## Roles calling roles
@@ -12,6 +12,12 @@
docker_molecule_repo: /srv/docker-stub-repo
docker_molecule_work: /var/tmp/docker-stub-work
tasks:
# The image ships without apt lists, and --check does not refresh them, so the fresh-host
# check finds the packages the role installs.
- name: Refresh the apt cache
ansible.builtin.apt:
update_cache: true
- name: Copy the repository builder
ansible.builtin.copy:
src: build-stub-repo.sh
@@ -14,6 +14,12 @@
hosts: all
gather_facts: false
tasks:
# The image ships without apt lists, and --check does not refresh them, so the fresh-host
# check finds the packages the role installs.
- name: Refresh the apt cache
ansible.builtin.apt:
update_cache: true
- name: Create the unit drop-in directory
ansible.builtin.file:
path: /etc/systemd/system/traefik.service.d
+1 -1
View File
@@ -14,11 +14,11 @@
- item.state | default('present') == 'present'
- not item.system | default(false)
# Under --check a user the role would create does not exist yet, and authorized_key fails on a missing user.
- name: Read the existing users for the check-mode preview
ansible.builtin.getent:
database: passwd
# Under --check a user the role would create does not exist yet, and authorized_key fails on a missing user.
- name: Enforce authorized_keys authoritatively
become: true
ansible.posix.authorized_key:
+19 -19
View File
@@ -395,25 +395,6 @@ class ScenarioPlatformsTest(unittest.TestCase):
seen[name] = where
self.assertNotIn("destroy", data["scenario"]["test_sequence"], path)
class ScenarioSequenceTest(unittest.TestCase):
"""A role scenario previews the fresh host and the configured host with molecule's check step."""
def test_role_scenarios_run_check_before_and_after_converge(self):
# A check-only scenario has no converge to surround, so it is not held to this.
files = sorted(REPO.glob("roles/*/molecule/*/molecule.yml"))
self.assertTrue(files)
for path in files:
sequence = yaml.safe_load(path.read_text())["scenario"]["test_sequence"]
if "converge" not in sequence:
continue
at = sequence.index("converge")
self.assertEqual(
sequence[at - 1 : at + 3],
["check", "converge", "check", "idempotence"],
path.relative_to(REPO),
)
def test_the_workflow_finds_the_containers_by_the_run_label(self):
# the sweep of earlier runs filters by the key, the cleanup of this run by key and value
self.assertEqual(
@@ -435,5 +416,24 @@ class ScenarioSequenceTest(unittest.TestCase):
)
class ScenarioSequenceTest(unittest.TestCase):
"""A role scenario previews the fresh host and the configured host with molecule's check step."""
def test_role_scenarios_run_check_before_and_after_converge(self):
# A check-only scenario has no converge to surround, so it is not held to this.
files = sorted(REPO.glob("roles/*/molecule/*/molecule.yml"))
self.assertTrue(files)
for path in files:
sequence = yaml.safe_load(path.read_text())["scenario"]["test_sequence"]
if "converge" not in sequence:
continue
at = sequence.index("converge")
self.assertEqual(
sequence[at - 1 : at + 3],
["check", "converge", "check", "idempotence"],
path.relative_to(REPO),
)
if __name__ == "__main__":
unittest.main()