From 42ad1c879fa9b8eb62fe5cc6a5f2a5e3710d70ce Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Wed, 1 Aug 2012 14:44:26 -0700 Subject: [PATCH 1/2] Fix service module for issue 755 and another bug Allow use of service module with just enable parameter, per issue #755. Also fixed two other issues: - fixed parameter to be 'enabled' per docs, not 'enable'. - fixed if block that checks whether to run _do_enable() to check whether the parameter is set, not the value of the enable value which may be None or False. If enabled=no, the service would never be disabled. --- library/service | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/service b/library/service index 3909cfebd7d..c209c765807 100755 --- a/library/service +++ b/library/service @@ -132,14 +132,14 @@ def main(): module = AnsibleModule( argument_spec = dict( name = dict(required=True), - state = dict(required=True, choices=['running', 'started', 'stopped', 'restarted', 'reloaded']), - enable = dict(choices=BOOLEANS) + state = dict(choices=['running', 'started', 'stopped', 'restarted', 'reloaded']), + enabled = dict(choices=BOOLEANS) ) ) name = module.params['name'] state = module.params['state'] - enable = module.boolean(module.params.get('enable', None)) + enable = module.boolean(module.params.get('enabled', None)) # =========================================== # find binaries locations on minion @@ -156,7 +156,7 @@ def main(): err = '' out = '' - if enable: + if module.params['enabled']: rc_enable, out_enable, err_enable = _do_enable(name, enable) rc += rc_enable out += out_enable From abe8d8d4d64fc9f5dc919b3dee182cc6a711574e Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Wed, 1 Aug 2012 14:58:32 -0700 Subject: [PATCH 2/2] Return extra information from service module If _do_enable() is run and returns rc == 0, set changed=True Add enabled and state to result if they are supplied when the module is run. --- library/service | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/service b/library/service index c209c765807..188ef82709b 100755 --- a/library/service +++ b/library/service @@ -158,6 +158,8 @@ def main(): if module.params['enabled']: rc_enable, out_enable, err_enable = _do_enable(name, enable) + if rc == 0: + changed = True rc += rc_enable out += out_enable err += err_enable @@ -201,6 +203,10 @@ def main(): module.fail_json(msg=err) result = {"changed": changed} + if module.params['enabled']: + result['enabled'] = module.params['enabled'] + if state: + result['state'] = state rc, stdout, stderr = _run("%s %s status" % (SERVICE, name)) module.exit_json(**result);