added innitial daemon-reloaded support to service module

This commit is contained in:
Brian Coca 2015-06-06 13:41:22 -04:00
parent ce391c7265
commit 438d87d269

View file

@ -34,12 +34,13 @@ options:
- Name of the service.
state:
required: false
choices: [ started, stopped, restarted, reloaded ]
choices: [ started, stopped, restarted, reloaded, daemon_reloaded ]
description:
- C(started)/C(stopped) are idempotent actions that will not run
commands unless necessary. C(restarted) will always bounce the
service. C(reloaded) will always reload. B(At least one of state
and enabled are required.)
- The C(daemon_reloaded) state was added in 2.0, it is exclusive for systemd.
sleep:
required: false
version_added: "1.3"
@ -279,7 +280,7 @@ class Service(object):
# Find ps binary
psbin = self.module.get_bin_path('ps', True)
(rc, psout, pserr) = self.execute_command('%s %s' % (psbin, psflags))
(rc, psout, pserr) = execute_command('%s %s' % (psbin, psflags))
# If rc is 0, set running as appropriate
if rc == 0:
self.running = False
@ -1413,7 +1414,7 @@ def main():
module = AnsibleModule(
argument_spec = dict(
name = dict(required=True),
state = dict(choices=['running', 'started', 'stopped', 'restarted', 'reloaded']),
state = dict(choices=['running', 'started', 'stopped', 'restarted', 'reloaded', 'daemon_reloaded']),
sleep = dict(required=False, type='int', default=None),
pattern = dict(required=False, default=None),
enabled = dict(type='bool'),
@ -1440,6 +1441,21 @@ def main():
result = {}
result['name'] = service.name
# shortcut for systemd only daemon-reloaded
if module.params['state'] == 'daemon_reloaded':
cmd = module.get_bin_path('systemctl', True)
svc_cmd = "%s %s %s" % (cmd, service.name, 'daemon-reloaded')
rc, stdout, stderr = module.run_command(svc_cmd)
result['msg']=stdout
if rc != 0:
result['rc'] = rc
if stderr:
result['msg']=stderr
module.fail_json(**result)
result['changed']=True
else:
# Find service management tools
service.get_service_tools()