From 2a0d18b0926e809687f1d12909b57adfaaf93ca2 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 9 Oct 2014 16:45:08 -0500 Subject: [PATCH] Insert newlines correctly when splitting literal blocks Fixes #9274 --- lib/ansible/module_utils/splitter.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/splitter.py b/lib/ansible/module_utils/splitter.py index 41b337773f..899fa8cd92 100644 --- a/lib/ansible/module_utils/splitter.py +++ b/lib/ansible/module_utils/splitter.py @@ -76,7 +76,7 @@ def split_args(args): do_decode = True except UnicodeDecodeError: do_decode = False - items = args.strip().split('\n') + items = args.split('\n') # iterate over the tokens, and reassemble any that may have been # split on a space inside a jinja2 block. @@ -138,7 +138,10 @@ def split_args(args): spacer = ' ' params[-1] = "%s%s%s" % (params[-1], spacer, token) else: - params[-1] = "%s\n%s" % (params[-1], token) + spacer = '' + if not params[-1].endswith('\n') and idx == 0: + spacer = '\n' + params[-1] = "%s%s%s" % (params[-1], spacer, token) appended = True # if the number of paired block tags is not the same, the depth has changed, so we calculate that here @@ -170,7 +173,7 @@ def split_args(args): # one item (meaning we split on newlines), add a newline back here # to preserve the original structure if len(items) > 1 and itemidx != len(items) - 1 and not line_continuation: - if not params[-1].endswith('\n'): + if not params[-1].endswith('\n') or item == '': params[-1] += '\n' # always clear the line continuation flag