Blame SOURCES/scap-security-guide-0.1.61-fix-ansible-service-disabled-task-PR_8226.patch

574ebc
From 1c054ed40a4dbc2a48ffe7720d018c317cad8105 Mon Sep 17 00:00:00 2001
574ebc
From: Watson Sato <wsato@redhat.com>
574ebc
Date: Tue, 15 Feb 2022 14:12:55 +0100
574ebc
Subject: [PATCH] Simply mask services that should be disabled
574ebc
574ebc
At some point Ansible started to return much more services in
574ebc
ansible_facts.services, including services that are not installed.
574ebc
This caused the task to think that the service exists, attempt to stop
574ebc
and mask the service.
574ebc
But systemd module fatal errors on non existing services, although the
574ebc
module ends up masking the service in question.
574ebc
574ebc
The bash remediations simply mask the service, even if it is not
574ebc
installed.
574ebc
Let's do the same with Ansible, mask the service and ignore errors.
574ebc
574ebc
One down side is that every non-existing service is reported as an
574ebc
error, which is ignored. But still a fatal error.
574ebc
---
574ebc
 shared/templates/service_disabled/ansible.template | 5 +----
574ebc
 1 file changed, 1 insertion(+), 4 deletions(-)
574ebc
574ebc
diff --git a/shared/templates/service_disabled/ansible.template b/shared/templates/service_disabled/ansible.template
574ebc
index 550ed563056..254f41ac7fd 100644
574ebc
--- a/shared/templates/service_disabled/ansible.template
574ebc
+++ b/shared/templates/service_disabled/ansible.template
574ebc
@@ -6,16 +6,13 @@
574ebc
 {{%- if init_system == "systemd" %}}
574ebc
 - name: Disable service {{{ SERVICENAME }}}
574ebc
   block:
574ebc
-  - name: Gather the service facts
574ebc
-    service_facts:
574ebc
-
574ebc
   - name: Disable service {{{ SERVICENAME }}}
574ebc
     systemd:
574ebc
       name: "{{{ DAEMONNAME }}}.service"
574ebc
       enabled: "no"
574ebc
       state: "stopped"
574ebc
       masked: "yes"
574ebc
-    when: '"{{{ DAEMONNAME }}}.service" in ansible_facts.services'
574ebc
+    ignore_errors: 'yes'
574ebc
 
574ebc
 - name: "Unit Socket Exists - {{{ DAEMONNAME }}}.socket"
574ebc
   command: systemctl list-unit-files {{{ DAEMONNAME }}}.socket