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

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