summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <brian.coca+git@gmail.com>2016-11-23 14:00:01 -0500
committerBrian Coca <brian.coca+git@gmail.com>2016-11-23 14:20:37 -0500
commit6c129b77b0d2461cfee72f26f0314c5f051aa626 (patch)
tree357154f5ccbe5e9396efbaeba8118c5aca964087
parent373dcef535f41dcd6d493369f64920329f4666ad (diff)
downloadansible-modules-core-6c129b77b0d2461cfee72f26f0314c5f051aa626.tar.gz
systemctl show rc changes across versions
to avoid different errors across versions, ignore rc in favor of found/notfound fixes #5710 (cherry picked from commit aa0cad528adcdc5cd3f69cb257ae54644090eb91)
-rw-r--r--system/systemd.py63
1 files changed, 30 insertions, 33 deletions
diff --git a/system/systemd.py b/system/systemd.py
index 88e981e6..4f7e58dd 100644
--- a/system/systemd.py
+++ b/system/systemd.py
@@ -264,44 +264,41 @@ def main():
if rc != 0:
module.fail_json(msg='failure %d during daemon-reload: %s' % (rc, err))
- # check service data
- (rc, out, err) = module.run_command("%s show '%s'" % (systemctl, unit))
- if rc != 0:
- module.fail_json(msg='failure %d running systemctl show for %r: %s' % (rc, unit, err))
-
found = False
is_initd = sysv_exists(unit)
is_systemd = False
- # load return of systemctl show into dictionary for easy access and return
- multival = []
- if out:
- k = None
- for line in to_native(out).split('\n'): # systemd can have multiline values delimited with {}
- if line.strip():
- if k is None:
- if '=' in line:
- k,v = line.split('=', 1)
- if v.lstrip().startswith('{'):
- if not v.rstrip().endswith('}'):
- multival.append(line)
- continue
- result['status'][k] = v.strip()
- k = None
- else:
- if line.rstrip().endswith('}'):
- result['status'][k] = '\n'.join(multival).strip()
- multival = []
- k = None
+ # check service data, cannot error out on rc as it changes across versions, assume not found
+ (rc, out, err) = module.run_command("%s show '%s'" % (systemctl, unit))
+ if rc == 0:
+ # load return of systemctl show into dictionary for easy access and return
+ multival = []
+ if out:
+ k = None
+ for line in to_native(out).split('\n'): # systemd can have multiline values delimited with {}
+ if line.strip():
+ if k is None:
+ if '=' in line:
+ k,v = line.split('=', 1)
+ if v.lstrip().startswith('{'):
+ if not v.rstrip().endswith('}'):
+ multival.append(line)
+ continue
+ result['status'][k] = v.strip()
+ k = None
else:
- multival.append(line)
-
- is_systemd = 'LoadState' in result['status'] and result['status']['LoadState'] != 'not-found'
-
- # Check for loading error
- if is_systemd and 'LoadError' in result['status']:
- module.fail_json(msg="Error loading unit file '%s': %s" % (unit, result['status']['LoadError']))
-
+ if line.rstrip().endswith('}'):
+ result['status'][k] = '\n'.join(multival).strip()
+ multival = []
+ k = None
+ else:
+ multival.append(line)
+
+ is_systemd = 'LoadState' in result['status'] and result['status']['LoadState'] != 'not-found'
+
+ # Check for loading error
+ if is_systemd and 'LoadError' in result['status']:
+ module.fail_json(msg="Error loading unit file '%s': %s" % (unit, result['status']['LoadError']))
# Does service exist?
found = is_systemd or is_initd