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

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