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
584 B
YAML
13 lines
584 B
YAML
---
|
|
# Every installed socket and service of a listed name is stopped and disabled, the socket first: a
|
|
# stopped service whose socket is still listening is started again by the next connection.
|
|
- name: Disable unwanted services if present
|
|
become: true
|
|
ansible.builtin.systemd:
|
|
name: "{{ item }}"
|
|
enabled: false
|
|
state: stopped
|
|
loop: >-
|
|
{{ systemd_hardening_disable_services_effective | map('regex_replace', '[.](service|socket)$', '') | unique
|
|
| product(['socket', 'service']) | map('join', '.') | select('in', systemd_hardening_installed_units) | list }}
|