--- - name: Disable unwanted services if present become: true ansible.builtin.systemd: name: "{{ item }}" enabled: false state: stopped loop: "{{ systemd_hardening_disable_services_effective }}" # Only act on installed units; items may be given with or without the # ".service" suffix. when: (item | regex_replace('\.service$', '') ~ '.service') in systemd_hardening_installed_units