From e0818bdc8a91bef7a3dda0063c5752b5617f8d4d Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Jan 23 2023 14:33:51 +0000 Subject: import ansible-core-2.13.3-2.el9_1 --- diff --git a/SOURCES/0001-Use-python-re-to-parse-service-output-in.patch b/SOURCES/0001-Use-python-re-to-parse-service-output-in.patch new file mode 100644 index 0000000..5356be8 --- /dev/null +++ b/SOURCES/0001-Use-python-re-to-parse-service-output-in.patch @@ -0,0 +1,72 @@ +From 1a583e3c0d67a63cef1b1a433f176b7983d39812 Mon Sep 17 00:00:00 2001 +From: Matt Martz +Date: Wed, 26 Oct 2022 16:06:43 -0500 +Subject: [PATCH] [stable-2.13] Use python re to parse service output instead + of grep (#79015) (#79051) + +* Use python re to parse service output instead of grep. Fixes #78541 + +* Add clog frag + +* Add an extra guard to abort if rc is 4, and /etc/init.d is missing +(cherry picked from commit 4458128) + +Co-authored-by: Matt Martz +--- + .../fragments/78541-service-facts-re.yml | 3 +++ + lib/ansible/modules/service_facts.py | 20 +++++++++++-------- + 2 files changed, 15 insertions(+), 8 deletions(-) + create mode 100644 changelogs/fragments/78541-service-facts-re.yml + +diff --git a/changelogs/fragments/78541-service-facts-re.yml b/changelogs/fragments/78541-service-facts-re.yml +new file mode 100644 +index 0000000000..b96d584246 +--- /dev/null ++++ b/changelogs/fragments/78541-service-facts-re.yml +@@ -0,0 +1,3 @@ ++bugfixes: ++- service_facts - Use python re to parse service output instead of grep ++ (https://github.com/ansible/ansible/issues/78541) +diff --git a/lib/ansible/modules/service_facts.py b/lib/ansible/modules/service_facts.py +index 996b47fd59..60555fdc4a 100644 +--- a/lib/ansible/modules/service_facts.py ++++ b/lib/ansible/modules/service_facts.py +@@ -89,6 +89,7 @@ ansible_facts: + ''' + + ++import os + import platform + import re + from ansible.module_utils.basic import AnsibleModule +@@ -104,16 +105,19 @@ class BaseService(object): + class ServiceScanService(BaseService): + + def _list_sysvinit(self, services): +- +- rc, stdout, stderr = self.module.run_command("%s --status-all 2>&1 | grep -E \"\\[ (\\+|\\-) \\]\"" % self.service_path, use_unsafe_shell=True) ++ rc, stdout, stderr = self.module.run_command("%s --status-all" % self.service_path) ++ if rc == 4 and not os.path.exists('/etc/init.d'): ++ # This function is not intended to run on Red Hat but it could happen ++ # if `chkconfig` is not installed. `service` on RHEL9 returns rc 4 ++ # when /etc/init.d is missing, add the extra guard of checking /etc/init.d ++ # instead of solely relying on rc == 4 ++ return + if rc != 0: + self.module.warn("Unable to query 'service' tool (%s): %s" % (rc, stderr)) +- for line in stdout.split("\n"): +- line_data = line.split() +- if len(line_data) < 4: +- continue # Skipping because we expected more data +- service_name = " ".join(line_data[3:]) +- if line_data[1] == "+": ++ p = re.compile(r'^\s*\[ (?P\+|\-) \]\s+(?P.+)$', flags=re.M) ++ for match in p.finditer(stdout): ++ service_name = match.group('name') ++ if match.group('state') == "+": + service_state = "running" + else: + service_state = "stopped" +-- +2.30.2 + diff --git a/SPECS/ansible-core.spec b/SPECS/ansible-core.spec index 57cb89f..dd8d518 100644 --- a/SPECS/ansible-core.spec +++ b/SPECS/ansible-core.spec @@ -36,7 +36,7 @@ Name: ansible-core Summary: SSH-based configuration management, deployment, and task execution system Version: 2.13.3 -Release: 1%{?dist} +Release: 2%{?dist} Group: Development/Libraries License: GPLv3+ @@ -52,6 +52,8 @@ Source5: pyparsing-6a844ee35ca5125490a28dbd6dd2d15b6498e605.tar.gz # Deps to build man pages Source6: straightplugin-6634ea8e1e89d5bb23804f50e676f196c52c46ed.tar.gz +Patch0: 0001-Use-python-re-to-parse-service-output-in.patch + URL: http://ansible.com # We obsolete old ansible, and any version of ansible-base. @@ -121,6 +123,7 @@ developed for ansible. %setup -q -T -b 5 -n pyparsing-6a844ee35ca5125490a28dbd6dd2d15b6498e605 %setup -q -T -b 6 -n straightplugin-6634ea8e1e89d5bb23804f50e676f196c52c46ed %setup -q -n ansible-%{commitId} +%patch0 -p 1 %build /usr/bin/python3.9 setup.py build @@ -207,6 +210,9 @@ cp -p lib/ansible_core.egg-info/PKG-INFO . %{python39_sitelib}/ansible_test %changelog +* Thu Dec 08 2022 Dimitri Savineau - 2.13.3-2 +- Use python re to parse service output instead of grep (rhbz#2151901) + * Mon Aug 15 2022 James Marshall - 2.13.3-1 - ansible-core 2.13.3 release (rhbz#2118458)