summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Delmanowski <drybjed@gmail.com>2016-09-09 15:23:39 +0200
committerBrian Coca <bcoca@users.noreply.github.com>2016-09-09 09:23:39 -0400
commitf5a4677680808d74f2b4a31bcc54377adb2a5cfb (patch)
tree54e68b2f429453f8e50705ee3e0c14467d05f40c
parent23f78efd7411261a363fad0ffb8f7ebfdd279435 (diff)
downloadansible-f5a4677680808d74f2b4a31bcc54377adb2a5cfb.tar.gz
Allow for no prefix in the comment filter (#17421)
In the 'comment' filter, if the 'prefix' parameter is set as empty, don't add an empty line before the comment. To get the previous behaviour (empty line before comment), set the prefix to '\n'.
-rw-r--r--lib/ansible/plugins/filter/core.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py
index 24c3901b80..8bf829afcb 100644
--- a/lib/ansible/plugins/filter/core.py
+++ b/lib/ansible/plugins/filter/core.py
@@ -336,8 +336,14 @@ def comment(text, style='plain', **kw):
str_beginning = ''
if p['beginning']:
str_beginning = "%s%s" % (p['beginning'], p['newline'])
- str_prefix = str(
- "%s%s" % (p['prefix'], p['newline'])) * int(p['prefix_count'])
+ str_prefix = ''
+ if p['prefix']:
+ if p['prefix'] != p['newline']:
+ str_prefix = str(
+ "%s%s" % (p['prefix'], p['newline'])) * int(p['prefix_count'])
+ else:
+ str_prefix = str(
+ "%s" % (p['newline'])) * int(p['prefix_count'])
str_text = ("%s%s" % (
p['decoration'],
# Prepend each line of the text with the decorator