From 917b7071d6f4e2c341bf87b8e7ca82c44a4c95c7 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 2 Sep 2015 17:09:53 -0400 Subject: [PATCH] partially reverted previous change to deal with systemctl show status not returning errors on missing service Now it looks for not-found key instead of running status which does return error codes when service is present but in diff states. fixes #12216 --- lib/ansible/modules/system/service.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index 172ebb7a914..97a190f29cd 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -522,13 +522,12 @@ class LinuxService(Service): def get_systemd_status_dict(self): # 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)) + elif 'LoadState=not-found' in out: + self.module.fail_json(msg='systemd could not find the requested service "%r": %s' % (self.__systemd_unit, err)) + key = None value_buffer = [] status_dict = {}