From ab3a87cc1ada40e32dab661cbb4286ae9118b886 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 11 Aug 2016 09:43:16 -0400 Subject: [PATCH] improved logic when dealing with init scripts --- lib/ansible/modules/system/systemd.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py index 9538fd78341..3c83e3f69b7 100644 --- a/lib/ansible/modules/system/systemd.py +++ b/lib/ansible/modules/system/systemd.py @@ -309,9 +309,15 @@ def main(): (rc, out, err) = module.run_command("%s is-enabled '%s'" % (systemctl, unit)) # check systemctl result or if it is a init script - initscript = '/etc/init.d/' + unit - if rc == 0 or (os.access(initscript, os.X_OK) and bool(glob.glob('/etc/rc?.d/S??' + unit))): + if rc == 0: enabled = True + elif rc == 1: + # Deals with init scripts + # if both init script and unit file exist stdout should have enabled/disabled, otherwise use rc entries + initscript = '/etc/init.d/' + unit + if os.path.exists(initscript) and os.access(initscript, os.X_OK) and \ + (not out.startswith('disabled') or bool(glob.glob('/etc/rc?.d/S??' + unit))): + enabled = True # default to current state result['enabled'] = enabled