From 71ae86dc61a9c76896bd7ab807012b7e504fab92 Mon Sep 17 00:00:00 2001 From: Defame1297 Date: Wed, 25 Nov 2026 18:58:16 +0000 Subject: [PATCH] test(pihole): assert the config directory, group and clone version verify.yml now checks the group of pihole.toml, the owner, group and mode of /etc/pihole, and that the clone is checked out at the repo.version the converge used, read from the role defaults. The molecule.yml comment describes the test sequence accurately. Assisted-by: Claude Code:claude-opus-5-5 --- roles/pihole/molecule/default/molecule.yml | 2 +- roles/pihole/molecule/default/verify.yml | 37 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/roles/pihole/molecule/default/molecule.yml b/roles/pihole/molecule/default/molecule.yml index 2e7d148..3856b2f 100644 --- a/roles/pihole/molecule/default/molecule.yml +++ b/roles/pihole/molecule/default/molecule.yml @@ -63,7 +63,7 @@ verifier: 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), - # with a check run before the converge (first-run preview) and after the idempotence run. + # plus two check steps: one before the converge (first-run preview), one after the idempotence run. test_sequence: - dependency - cleanup diff --git a/roles/pihole/molecule/default/verify.yml b/roles/pihole/molecule/default/verify.yml index 0da56e7..be5b64f 100644 --- a/roles/pihole/molecule/default/verify.yml +++ b/roles/pihole/molecule/default/verify.yml @@ -16,6 +16,13 @@ - name: Verify hosts: all gather_facts: true + # The role defaults, for the clone path and version the converge used: the scenario overrides + # neither, so the override falls back to them. Only the leaves read below are templated. + vars_files: + - ../../defaults/main.yml + vars: + pihole_test_repo_path: "{{ pihole_test_overrides.repo.path | default(pihole_default.repo.path) }}" + pihole_test_repo_version: "{{ pihole_test_overrides.repo.version | default(pihole_default.repo.version) }}" tasks: - name: Read the rendered pihole.toml ansible.builtin.slurp: @@ -27,6 +34,18 @@ path: /etc/pihole/pihole.toml register: pihole_test_toml_stat + - name: Stat the configuration directory + ansible.builtin.stat: + path: /etc/pihole + register: pihole_test_config_dir + + # The git module only checks out; it cannot report which tag HEAD is at. + - name: Read the tag the clone is checked out at + ansible.builtin.command: # noqa: command-instead-of-module + cmd: git -C {{ pihole_test_repo_path | quote }} describe --tags --exact-match HEAD + register: pihole_test_clone_tag + changed_when: false + - name: Read the stub installer log ansible.builtin.slurp: src: /var/log/pihole-stub-installer.log @@ -55,9 +74,27 @@ ansible.builtin.assert: that: - pihole_test_toml_stat.stat.pw_name == 'pihole' + - pihole_test_toml_stat.stat.gr_name == 'pihole' - pihole_test_toml_stat.stat.mode == '0664' quiet: true + - name: The configuration directory belongs to the pihole user and group, mode 0755 + ansible.builtin.assert: + that: + - pihole_test_config_dir.stat.isdir + - pihole_test_config_dir.stat.pw_name == 'pihole' + - pihole_test_config_dir.stat.gr_name == 'pihole' + - pihole_test_config_dir.stat.mode == '0755' + quiet: true + + # The stub repository tags its only commit with the default repo.version (prepare.yml). + - name: The clone is checked out at the configured version + ansible.builtin.assert: + that: + - pihole_test_clone_tag.stdout == pihole_test_repo_version + fail_msg: "Clone at {{ pihole_test_clone_tag.stdout }}, expected {{ pihole_test_repo_version }}" + quiet: true + - name: The user is a system account without a login shell ansible.builtin.assert: that: