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

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