From 186db40864209a19f1202f328169a4b34bd3e3c2 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 5 Jul 2016 08:54:08 -0400 Subject: [PATCH] make daemon reload first thing always run otherwise service detection can fail before we run it which might be required to actually detect the service. --- lib/ansible/modules/system/systemd.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py index c7ca2c6bde..53171a73a1 100644 --- a/lib/ansible/modules/system/systemd.py +++ b/lib/ansible/modules/system/systemd.py @@ -241,6 +241,12 @@ def main(): 'status': {}, } + # Run daemon-reload first, if requested + if module.params['daemon_reload']: + (rc, out, err) = module.run_command("%s daemon-reload" % (systemctl)) + if rc != 0: + module.fail_json(msg='failure %d during daemon-reload: %s' % (rc, err)) + #TODO: check if service exists (rc, out, err) = module.run_command("%s show '%s'" % (systemctl, unit)) if rc != 0: @@ -269,18 +275,11 @@ def main(): multival.append(line) - if 'LoadState' in result['status'] and result['status']['LoadState'] == 'not-found': module.fail_json(msg='Could not find the requested service "%r": %s' % (unit, err)) elif 'LoadError' in result['status']: module.fail_json(msg="Failed to get the service status '%s': %s" % (unit, result['status']['LoadError'])) - # Run daemon-reload first, if requested - if module.params['daemon_reload']: - (rc, out, err) = module.run_command("%s daemon-reload" % (systemctl)) - if rc != 0: - module.fail_json(msg='failure %d during daemon-reload: %s' % (rc, err)) - # mask/unmask the service, if requested if module.params['masked'] is not None: masked = (result['status']['LoadState'] == 'masked')