From 8290912eb10c38de100db8ec03d25fe44c83933d Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 28 Jan 2025 07:19:46 -0800 Subject: [PATCH] service_facts: skip unwanted lines in openrc output (#84622) * rc-status commands returns unwanted lines with service names and their status. Skip such lines while parsing service names Fixes: #84512 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/openrc-status.yml | 3 +++ lib/ansible/modules/service_facts.py | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/openrc-status.yml diff --git a/changelogs/fragments/openrc-status.yml b/changelogs/fragments/openrc-status.yml new file mode 100644 index 00000000000..48f667817ac --- /dev/null +++ b/changelogs/fragments/openrc-status.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - service_facts - skip lines which does not contain service names in openrc output (https://github.com/ansible/ansible/issues/84512). diff --git a/lib/ansible/modules/service_facts.py b/lib/ansible/modules/service_facts.py index fa0e5f22252..4b67b61e42c 100644 --- a/lib/ansible/modules/service_facts.py +++ b/lib/ansible/modules/service_facts.py @@ -211,8 +211,8 @@ class ServiceScanService(BaseService): def _list_openrc(self, services): all_services_runlevels = {} - rc, stdout, stderr = self.module.run_command("%s -a -s -m 2>&1 | grep '^ ' | tr -d '[]'" % self.rc_status_path, use_unsafe_shell=True) - rc_u, stdout_u, stderr_u = self.module.run_command("%s show -v 2>&1 | grep '|'" % self.rc_update_path, use_unsafe_shell=True) + dummy, stdout, dummy = self.module.run_command("%s -a -s -m 2>&1 | grep '^ ' | tr -d '[]'" % self.rc_status_path, use_unsafe_shell=True) + dummy, stdout_u, dummy = self.module.run_command("%s show -v 2>&1 | grep '|'" % self.rc_update_path, use_unsafe_shell=True) for line in stdout_u.split('\n'): line_data = line.split('|') if len(line_data) < 2: @@ -228,6 +228,9 @@ class ServiceScanService(BaseService): if len(line_data) < 2: continue service_name = line_data[0] + # Skip lines which are not service names + if service_name == "*": + continue service_state = line_data[1] service_runlevels = all_services_runlevels[service_name] service_data = {"name": service_name, "runlevels": service_runlevels, "state": service_state, "source": "openrc"}