summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Miller <admiller@redhat.com>2018-06-13 14:01:48 -0500
committerMatt Clay <matt@mystile.com>2018-06-15 12:22:26 -0700
commitbf1cc2f1f4743929b7ef9f4f5c2ac169fbfbc108 (patch)
treeb1d93565383aec206933cdc022b4787498ad09d3
parentf9f368f123724ff47fe5b3e1014469e560c2c8f8 (diff)
downloadansible-bf1cc2f1f4743929b7ef9f4f5c2ac169fbfbc108.tar.gz
service_facts correct meaning of state for systemd service units (#40914)
* service_facts correct meaning of state for systemd service units Fixes #40809 Previously this module used the commend `systemctl list-unit-files --type=service` to query state of services but list-unit-files only shows enabled vs disabled which is not what we want for "state" Signed-off-by: Adam Miller <admiller@redhat.com> * make sure to define service_name before referencing it Signed-off-by: Adam Miller <admiller@redhat.com>
-rw-r--r--lib/ansible/modules/system/service_facts.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/ansible/modules/system/service_facts.py b/lib/ansible/modules/system/service_facts.py
index 1038569f68..b884daff7e 100644
--- a/lib/ansible/modules/system/service_facts.py
+++ b/lib/ansible/modules/system/service_facts.py
@@ -178,16 +178,16 @@ class SystemctlScanService(BaseService):
systemctl_path = self.module.get_bin_path("systemctl", opt_dirs=["/usr/bin", "/usr/local/bin"])
if systemctl_path is None:
return None
- rc, stdout, stderr = self.module.run_command("%s list-unit-files --type=service | tail -n +2 | head -n -2" % systemctl_path, use_unsafe_shell=True)
- for line in stdout.split("\n"):
- line_data = line.split()
- if len(line_data) != 2:
- continue
- if line_data[1] == "enabled":
+ rc, stdout, stderr = self.module.run_command("%s list-units --no-pager --type service --all" % systemctl_path, use_unsafe_shell=True)
+ for line in [svc_line for svc_line in stdout.split('\n') if '.service' in svc_line and 'not-found' not in svc_line]:
+ service_name = line.split()[0]
+ if "running" in line:
state_val = "running"
else:
+ if 'failed' in line:
+ service_name = line.split()[1]
state_val = "stopped"
- services[line_data[0]] = {"name": line_data[0], "state": state_val, "source": "systemd"}
+ services[service_name] = {"name": service_name, "state": state_val, "source": "systemd"}
return services