The fail2ban README example played against a consumer's real inventory group; it now uses a generic group name. A systemd_hardening task comment named a consumer playbook; it now describes the clash with any inventory variable called `services` in general terms. No task or default changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
58 lines
2.1 KiB
YAML
58 lines
2.1 KiB
YAML
---
|
|
# 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 any inventory variable of that name, such as
|
|
# a list of services a playbook installs. 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
|