Look up every listed name as a socket and as a service and act on each installed unit, the socket first. A service whose socket stays active is started again by the next connection to its port. Assisted-by: Claude Code
13 lines
564 B
YAML
13 lines
564 B
YAML
---
|
|
# Same shape as disable_services.yml: every installed socket and service of a listed name is masked, the socket first.
|
|
# A unit that is not installed can't be started, so masking it is unnecessary.
|
|
- name: Mask high-risk services
|
|
become: true
|
|
ansible.builtin.systemd:
|
|
name: "{{ item }}"
|
|
masked: true
|
|
state: stopped
|
|
loop: >-
|
|
{{ systemd_hardening_mask_services | map('regex_replace', '[.](service|socket)$', '') | unique
|
|
| product(['socket', 'service']) | map('join', '.') | select('in', systemd_hardening_installed_units) | list }}
|