From f5a4677680808d74f2b4a31bcc54377adb2a5cfb Mon Sep 17 00:00:00 2001 From: Maciej Delmanowski Date: Fri, 9 Sep 2016 15:23:39 +0200 Subject: [PATCH] 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'. --- lib/ansible/plugins/filter/core.py | 10 ++++++++-- 1 file 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