[stable-2.7] Handle sets differently than lists in wrap_var. Fixes #47372 (#47510).

(cherry picked from commit f6ecdf0b87)

Co-authored-by: Matt Martz <matt@sivel.net>
This commit is contained in:
Matt Martz 2018-10-23 11:18:21 -05:00 committed by Toshio Kuratomi
parent 376b199c05
commit 8a40514d2b
3 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- unsafe - Add special casing to sets, to support wrapping elements of sets correctly in Python 3 (https://github.com/ansible/ansible/issues/47372)

View file

@ -96,11 +96,17 @@ def _wrap_list(v):
return v return v
def _wrap_set(v):
return set(item if item is None else wrap_var(item) for item in v)
def wrap_var(v): def wrap_var(v):
if isinstance(v, Mapping): if isinstance(v, Mapping):
v = _wrap_dict(v) v = _wrap_dict(v)
elif isinstance(v, (MutableSequence, Set)): elif isinstance(v, MutableSequence):
v = _wrap_list(v) v = _wrap_list(v)
elif isinstance(v, Set):
v = _wrap_set(v)
elif v is not None and not isinstance(v, AnsibleUnsafe): elif v is not None and not isinstance(v, AnsibleUnsafe):
v = UnsafeProxy(v) v = UnsafeProxy(v)
return v return v

View file

@ -252,3 +252,13 @@
loop: "{{ fake_var }}" loop: "{{ fake_var }}"
register: result register: result
failed_when: result is not skipped failed_when: result is not skipped
# https://github.com/ansible/ansible/issues/47372
- name: Loop unsafe list
debug:
var: item
with_items: "{{ things|list|unique }}"
vars:
things:
- !unsafe foo
- !unsafe bar