parent
77061f5521
commit
e70c0afc5e
1 changed files with 16 additions and 9 deletions
|
@ -7,14 +7,14 @@ __metaclass__ = type
|
||||||
DOCUMENTATION = """
|
DOCUMENTATION = """
|
||||||
lookup: dict
|
lookup: dict
|
||||||
version_added: "1.5"
|
version_added: "1.5"
|
||||||
short_description: returns key/value pair items from a dictionary
|
short_description: returns key/value pair items from dictionaries
|
||||||
description:
|
description:
|
||||||
- Takes a dictionary as input and returns a list with each item in the list being a dictionary with 'key' and 'value' as
|
- Takes dictionaries as input and returns a list with each item in the list being a dictionary with 'key' and 'value' as
|
||||||
keys to the previous dictionary's structure.
|
keys to the previous dictionary's structure.
|
||||||
options:
|
options:
|
||||||
_raw:
|
_terms:
|
||||||
description:
|
description:
|
||||||
- A dictionary
|
- A list of dictionaries
|
||||||
required: True
|
required: True
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ tasks:
|
||||||
- name: Print phone records
|
- name: Print phone records
|
||||||
debug:
|
debug:
|
||||||
msg: "User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
|
msg: "User {{ item.key }} is {{ item.value.name }} ({{ item.value.telephone }})"
|
||||||
with_dict: "{{ users }}"
|
loop: "{{ lookup('dict', users) }}"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN = """
|
RETURN = """
|
||||||
|
@ -56,8 +56,15 @@ class LookupModule(LookupBase):
|
||||||
|
|
||||||
def run(self, terms, variables=None, **kwargs):
|
def run(self, terms, variables=None, **kwargs):
|
||||||
|
|
||||||
|
# FIXME: can remove once with_ special case is removed
|
||||||
|
if not isinstance(terms, list):
|
||||||
|
terms = [terms]
|
||||||
|
|
||||||
|
results = []
|
||||||
|
for term in terms:
|
||||||
# Expect any type of Mapping, notably hostvars
|
# Expect any type of Mapping, notably hostvars
|
||||||
if not isinstance(terms, collections.Mapping):
|
if not isinstance(term, collections.Mapping):
|
||||||
raise AnsibleError("with_dict expects a dict")
|
raise AnsibleError("with_dict expects a dict")
|
||||||
|
|
||||||
return self._flatten_hash_to_list(terms)
|
results.extend(self._flatten_hash_to_list(term))
|
||||||
|
return results
|
||||||
|
|
Loading…
Reference in a new issue