--- # The production LXC profile with one opt-in drop-in. The stub units come from prepare.yml. - name: Converge the role with a valid profile hosts: all vars: systemd_hardening_system_type: ubuntu_lxc systemd_hardening_services: testsvc: ProtectSystem: strict NoNewPrivileges: true ReadWritePaths: [/var/tmp, /run] LimitNOFILE: 1024 roles: - role: mortis.kamino.systemd_hardening # The plays below are refusals. The missing and unknown system types stop before the role # changes anything. The malformed drop-in plays fail at dropins.yml, after the disable, mask # and manager drop-in tasks ran, but those are no-ops after the converge above, so the # idempotence run stays clean. A sentinel in the failure message tells "the role refused" # from "the fail task after the role ran", which a bare rescue cannot. - name: A run without systemd_hardening_system_type is refused hosts: all gather_facts: false tasks: - name: Apply the role without a system type block: - name: Include the role ansible.builtin.include_role: name: mortis.kamino.systemd_hardening - name: Fail when the missing type was accepted ansible.builtin.fail: msg: MOLECULE-ACCEPTED rescue: - name: The role refused the run ansible.builtin.assert: that: "'missing required arguments' in ansible_failed_result.msg | default('')" quiet: true - name: An unknown system type is refused hosts: all gather_facts: false vars: systemd_hardening_system_type: not_a_type tasks: - name: Apply the role with an unknown type block: - name: Include the role ansible.builtin.include_role: name: mortis.kamino.systemd_hardening - name: Fail when the unknown type was accepted ansible.builtin.fail: msg: MOLECULE-ACCEPTED rescue: - name: The profile check stopped the play ansible.builtin.assert: that: "'is invalid' in ansible_failed_result.msg | default('')" quiet: true - name: A drop-in entry that is not a mapping is refused hosts: all gather_facts: false vars: systemd_hardening_system_type: ubuntu_lxc systemd_hardening_services: testsvc: not-a-mapping tasks: - name: Apply the role with a malformed drop-in block: - name: Include the role ansible.builtin.include_role: name: mortis.kamino.systemd_hardening - name: Fail when the malformed drop-in was accepted ansible.builtin.fail: msg: MOLECULE-ACCEPTED rescue: - name: The drop-in validation stopped the play ansible.builtin.assert: that: "'must be a mapping' in ansible_failed_result.msg | default('')" quiet: true - name: A drop-in list that is not a mapping is refused hosts: all gather_facts: false vars: systemd_hardening_system_type: ubuntu_lxc systemd_hardening_services: [testsvc] tasks: - name: Apply the role with a list instead of a mapping block: - name: Include the role ansible.builtin.include_role: name: mortis.kamino.systemd_hardening - name: Fail when the list was accepted ansible.builtin.fail: msg: MOLECULE-ACCEPTED rescue: - name: The role refused the run ansible.builtin.assert: that: - "'MOLECULE-ACCEPTED' not in ansible_failed_result.msg | default('')" - "'systemd_hardening_services' in ansible_failed_result.msg | default('')" quiet: true