From 1429507489496acbf87eeb674d220f47431327de Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 22 Oct 2014 16:43:35 -0400 Subject: [PATCH] Fix for systemd service scripts with newlines Fixes #127 --- lib/ansible/modules/system/service.py | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index b235ee25c57..6093717bcee 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -501,7 +501,33 @@ class LinuxService(Service): (rc, out, err) = self.execute_command("%s show %s" % (self.enable_cmd, self.__systemd_unit,)) if rc != 0: self.module.fail_json(msg='failure %d running systemctl show for %r: %s' % (rc, self.__systemd_unit, err)) - return dict(line.split('=', 1) for line in out.splitlines()) + key = None + value_buffer = [] + status_dict = {} + for line in out.splitlines(): + if not key: + key, value = line.split('=', 1) + # systemd fields that are shell commands can be multi-line + # We take a value that begins with a "{" as the start of + # a shell command and a line that ends with "}" as the end of + # the command + if value.lstrip().startswith('{'): + if value.rstrip().endswith('}'): + status_dict[key] = value + key = None + else: + value_buffer.append(value) + else: + status_dict[key] = value + key = None + else: + if line.rstrip().endswith('}'): + status_dict[key] = '\n'.join(value_buffer) + key = None + else: + value_buffer.append(value) + + return status_dict def get_systemd_service_status(self): d = self.get_systemd_status_dict()