diff options
author | Brian Coca <brian.coca+git@gmail.com> | 2015-09-01 10:57:37 -0400 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2015-09-01 10:58:15 -0400 |
commit | bbcfb1092ae22e8520f6241b9da7f99a4f7423cd (patch) | |
tree | ddfc11df21aa89a74d6800b0f271aee84bdf44ab | |
parent | 68ab025dac8ea0f9779f57fde2236bac6ce95084 (diff) | |
download | ansible-modules-core-bbcfb1092ae22e8520f6241b9da7f99a4f7423cd.tar.gz |
check systemctl status before show as show will not return antyhing other than rc=0 even when it fails.
-rw-r--r-- | system/service.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/system/service.py b/system/service.py index 8495bec9..70ff8351 100644 --- a/system/service.py +++ b/system/service.py @@ -520,7 +520,13 @@ class LinuxService(Service): return False def get_systemd_status_dict(self): - (rc, out, err) = self.execute_command("%s show %s" % (self.enable_cmd, self.__systemd_unit,)) + + # Check status first as show will not fail if service does not exist + (rc, out, err) = self.execute_command("%s status '%s'" % (self.enable_cmd, self.__systemd_unit,)) + if rc != 0: + self.module.fail_json(msg='failure %d running systemctl status for %r: %s' % (rc, self.__systemd_unit, err)) + + (rc, out, err) = self.execute_command("%s show '%s'" % (self.enable_cmd, self.__systemd_unit,)) if rc != 0: self.module.fail_json(msg='failure %d running systemctl show for %r: %s' % (rc, self.__systemd_unit, err)) key = None |