Avoid the 'state=null' coming back from the service module.

pull/2109/head
Michael DeHaan 12 years ago
parent fa21b41357
commit 934f416387

@ -237,7 +237,7 @@ class Service(object):
def check_service_changed(self):
if self.state and self.running is None:
self.module.fail_json(msg="failed determining the current service state => state stays unchanged")
self.module.fail_json(msg="failed determining service state, possible typo of service name?")
# Find out if state has changed
if not self.running and self.state in ["started", "running"]:
self.changed = True
@ -420,6 +420,9 @@ class LinuxService(Service):
# TODO: lookup if we can use a return code for this instead?
self.running = True
return self.running
def service_enable(self):
# we change argument depending on real binary used
# update-rc.d wants enable/disable while
@ -666,8 +669,25 @@ def main():
result['changed'] = service.changed
if service.module.params['enabled']:
result['enabled'] = service.module.params['enabled']
if service.state:
result['state'] = service.state
#if service.state:
# result['state'] = service.state
print "getting state!"
if not service.module.params['state']:
status = service.get_service_status()
if status is None:
result['state'] = 'absent'
elif status is False:
result['state'] = 'started'
else:
result['state'] = 'stopped'
else:
# as we may have just bounced the service the service command may not
# report accurate state at this moment so just show what we ran
if service.module.params['state'] in ['started','restarted']:
result['state'] = 'started'
else:
result['state'] = 'stopped'
module.exit_json(**result)

Loading…
Cancel
Save