diff --git a/roles/AGENTS.md b/roles/AGENTS.md index ebb3e65..9f63791 100644 --- a/roles/AGENTS.md +++ b/roles/AGENTS.md @@ -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 ` 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 ` 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 diff --git a/roles/docker/molecule/default/prepare.yml b/roles/docker/molecule/default/prepare.yml index c79cae1..32dbd94 100644 --- a/roles/docker/molecule/default/prepare.yml +++ b/roles/docker/molecule/default/prepare.yml @@ -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 diff --git a/roles/traefik/molecule/default/prepare.yml b/roles/traefik/molecule/default/prepare.yml index e81eda7..5c82815 100644 --- a/roles/traefik/molecule/default/prepare.yml +++ b/roles/traefik/molecule/default/prepare.yml @@ -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 diff --git a/roles/user_management/tasks/ssh_keys.yml b/roles/user_management/tasks/ssh_keys.yml index 8ba75be..fb2ce51 100644 --- a/roles/user_management/tasks/ssh_keys.yml +++ b/roles/user_management/tasks/ssh_keys.yml @@ -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: diff --git a/tests/scripts/test_run_molecule_scenarios.py b/tests/scripts/test_run_molecule_scenarios.py index 1804ed0..ddee564 100644 --- a/tests/scripts/test_run_molecule_scenarios.py +++ b/tests/scripts/test_run_molecule_scenarios.py @@ -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()