diff options
author | Matt Martz <matt@sivel.net> | 2019-03-08 14:36:53 -0600 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2019-03-11 13:14:01 -0700 |
commit | 07e4ae0806f96cc37d1f223205ffcbedde0a7967 (patch) | |
tree | e47960c03e32557e8ea456c46b76f5310159a5cf | |
parent | c93bfe9931c90c6825907ba5e15d4906fc60c1d3 (diff) | |
download | ansible-07e4ae0806f96cc37d1f223205ffcbedde0a7967.tar.gz |
[stable-2.7] Allow dict2items to work with hostvars (#53538).
(cherry picked from commit 414440e3237186bf6eb2f3cb1d1fbb1ebb4186e5)
Co-authored-by: Matt Martz <matt@sivel.net>
-rw-r--r-- | changelogs/fragments/dict2items-mapping.yaml | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/filter/core.py | 4 | ||||
-rw-r--r-- | test/integration/targets/filters/tasks/main.yml | 7 |
3 files changed, 11 insertions, 2 deletions
diff --git a/changelogs/fragments/dict2items-mapping.yaml b/changelogs/fragments/dict2items-mapping.yaml new file mode 100644 index 0000000000..814576f013 --- /dev/null +++ b/changelogs/fragments/dict2items-mapping.yaml @@ -0,0 +1,2 @@ +bugfixes: +- dict2items - Allow dict2items to work with hostvars diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py index 759e6ce7c9..78e62b735d 100644 --- a/lib/ansible/plugins/filter/core.py +++ b/lib/ansible/plugins/filter/core.py @@ -34,7 +34,7 @@ import time import uuid import yaml -from collections import MutableMapping +from collections import Mapping, MutableMapping import datetime from functools import partial from random import Random, SystemRandom, shuffle, random @@ -498,7 +498,7 @@ def dict_to_list_of_dict_key_value_elements(mydict): ''' takes a dictionary and transforms it into a list of dictionaries, with each having a 'key' and 'value' keys that correspond to the keys and values of the original ''' - if not isinstance(mydict, MutableMapping): + if not isinstance(mydict, Mapping): raise AnsibleFilterError("dict2items requires a dictionary, got %s instead." % type(mydict)) ret = [] diff --git a/test/integration/targets/filters/tasks/main.yml b/test/integration/targets/filters/tasks/main.yml index 69162c5132..a80c6814aa 100644 --- a/test/integration/targets/filters/tasks/main.yml +++ b/test/integration/targets/filters/tasks/main.yml @@ -237,3 +237,10 @@ that: - "'00:00:00' | random_mac is match('^00:00:00:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]:[a-f0-9][a-f0-9]$')" - "'00:00:00' | random_mac != '00:00:00' | random_mac" + +- name: Ensure dict2items works with hostvars + debug: + msg: "{{ item.key }}" + loop: "{{ hostvars|dict2items }}" + loop_control: + label: "{{ item.key }}"
\ No newline at end of file |