From 842b6b96c811807f6397e6b89804465bc7dc2eb9 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Thu, 11 Jul 2019 17:51:58 +0200 Subject: [PATCH] include only jinja2 strings if candidate is a template --- ansiblelater/rules/ansiblefiles.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ansiblelater/rules/ansiblefiles.py b/ansiblelater/rules/ansiblefiles.py index 4d9aa5e..bb779c1 100644 --- a/ansiblelater/rules/ansiblefiles.py +++ b/ansiblelater/rules/ansiblefiles.py @@ -6,6 +6,7 @@ from collections import defaultdict from ansiblelater.command.candidates import Error from ansiblelater.command.candidates import Result +from ansiblelater.command.candidates import Template from ansiblelater.utils import count_spaces from ansiblelater.utils.rulehelper import get_normalized_tasks from ansiblelater.utils.rulehelper import get_normalized_yaml @@ -193,6 +194,18 @@ def check_compare_to_literal_bool(candidate, settings): description = "use `when: var` rather than `when: var == True` " \ "(or conversely `when: not var`)" + if isinstance(candidate, Template): + matches = [] + braces = re.compile("({{|{%)(.*?)(}}|%})") + + for i, line in yamllines: + match = braces.findall(line) + if match: + for item in match: + matches.append((i, item[1])) + + yamllines = matches + literal_bool_compare = re.compile("[=!]= ?(True|true|False|false)") if not errors: