WIP: Check that union Jinja filter can be chained (#46298)

* Check that union Jinja filter can be chained

* set filters: fix unexpected templating type error

this error occurs with Jinja 2.10 since 32ec69d827,
for example when union filters are chained:

$ ansible all -i localhost, -mdebug -a"msg={{ []|union([])|union([]) }}"
localhost | FAILED! => {
    "msg": "Unexpected templating type error occurred on ({{ []|union([])|union([]) }}):
            unsupported operand type(s) for +: 'set' and 'list'"
}
This commit is contained in:
Pilou 2018-10-01 22:30:24 +02:00 committed by ansibot
commit b76c4c840e
2 changed files with 22 additions and 1 deletions

View file

@ -54,7 +54,12 @@ def unique(environment, a, case_sensitive=False, attribute=None):
error = None
try:
if HAS_UNIQUE:
c = set(do_unique(environment, a, case_sensitive=case_sensitive, attribute=attribute))
c = do_unique(environment, a, case_sensitive=case_sensitive, attribute=attribute)
if isinstance(a, collections.Hashable):
c = set(c)
else:
c = list(c)
except Exception as e:
if case_sensitive or attribute:
raise AnsibleFilterError("Jinja2's unique filter failed and we cannot fall back to Ansible's version "