From d41b4e38026818ca1885885aaea7adfbf55908fb Mon Sep 17 00:00:00 2001 From: jctanner Date: Mon, 28 Nov 2016 14:15:12 -0500 Subject: [PATCH] Use the the new features of fail_if_missing for checkmode (#5750) --- lib/ansible/modules/system/service.py | 3 ++- lib/ansible/modules/system/systemd.py | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index a71e6382804..af97e7df5a4 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -131,6 +131,7 @@ import select import time import string import glob +from ansible.module_utils.service import fail_if_missing # The distutils module is not shipped with SUNWPython on Solaris. # It's in the SUNWPython-devel package which also contains development files @@ -493,7 +494,7 @@ class LinuxService(Service): self.enable_cmd = location['chkconfig'] if self.enable_cmd is None: - self.module.fail_json(msg="no service or tool found for: %s" % self.name) + fail_if_missing(self.module, False, self.name, msg='host') # If no service control tool selected yet, try to see if 'service' is available if self.svc_cmd is None and location.get('service', False): diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py index d835b85ff13..19fedce4a78 100644 --- a/lib/ansible/modules/system/systemd.py +++ b/lib/ansible/modules/system/systemd.py @@ -329,8 +329,7 @@ def main(): (rc, out, err) = module.run_command("%s %s '%s'" % (systemctl, action, unit)) if rc != 0: # some versions of system CAN mask/unmask non existing services, we only fail on missing if they don't - fail_if_missing(module, found, unit, "cannot %s" % (action)) - module.fail_json(msg="Unable to %s service %s: %s" % (action, unit, err)) + fail_if_missing(module, found, unit, msg='host') # Enable/disable service startup at boot if requested @@ -341,7 +340,7 @@ def main(): else: action = 'disable' - fail_if_missing(module, found, unit, "cannot %s" % (action)) + fail_if_missing(module, found, unit, msg='host') # do we need to enable the service? enabled = False @@ -370,7 +369,7 @@ def main(): # set service state if requested if module.params['state'] is not None: - fail_if_missing(module, found, unit, "cannot check nor set state") + fail_if_missing(module, found, unit, msg="host") # default to desired state result['state'] = module.params['state']