--- # Required input with no default: the role does not read a global such as system_type; # the inventory maps it onto systemd_hardening_system_type. - name: Require systemd_hardening_system_type ansible.builtin.assert: that: - systemd_hardening_system_type is defined fail_msg: >- systemd_hardening_system_type is required and has no default. Set it in the play or the inventory. tags: always - name: Validate systemd_hardening_system_type variable ansible.builtin.assert: that: - systemd_hardening_system_type in systemd_hardening_profiles fail_msg: >- systemd_hardening_system_type '{{ systemd_hardening_system_type }}' is invalid. Must be one of: {{ systemd_hardening_profiles.keys() | list | join(', ') }}. success_msg: "systemd_hardening_system_type '{{ systemd_hardening_system_type }}' is valid." tags: always # Not service_facts: it returns a fact named `services`, which (with # inject_facts_as_vars) overrides the host_vars `services` list used by # playbooks/install_services.yml. Only installed unit files are listed, so # units that are merely referenced (LoadState not-found) are excluded. - name: List installed service unit files # noqa: command-instead-of-module become: true ansible.builtin.command: systemctl list-unit-files --type=service --no-legend --plain register: systemd_hardening_unit_files changed_when: false check_mode: false tags: [disable, mask] - name: Set installed service units ansible.builtin.set_fact: systemd_hardening_installed_units: "{{ systemd_hardening_unit_files.stdout_lines | map('split') | map('first') | list }}" tags: [disable, mask] - name: Disable unwanted services ansible.builtin.include_tasks: disable_services.yml tags: disable - name: Mask high-risk services ansible.builtin.include_tasks: mask_services.yml tags: mask - name: Harden systemd manager globally ansible.builtin.include_tasks: harden_manager.yml tags: harden-manager - name: Apply per-service drop-ins ansible.builtin.include_tasks: dropins.yml tags: dropins - name: Flush handlers early ansible.builtin.meta: flush_handlers