--- # 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 }}