Last active
October 24, 2017 10:35
-
-
Save halberom/c78b8bb51714cdce8deff128b9af5bc9 to your computer and use it in GitHub Desktop.
ansible - bug with lookup dict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# edit lib/ansible/plugins/lookup/dict.py to look like | |
class LookupModule(LookupBase): | |
def run(self, terms, variables=None, **kwargs): | |
# Expect any type of Mapping, notably hostvars | |
if not isinstance(terms, collections.Mapping): | |
raise AnsibleError("with_dict expects a dict, got type {0}, terms contains {1}".format(type(terms), terms)) | |
return self._flatten_hash_to_list(terms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TASK [debug] ************************************************************************************************************************** | |
task path: /private/tmp/ansible/play.yml:9 | |
fatal: [localhost]: FAILED! => { | |
"msg": "An unhandled exception occurred while running the lookup plugin 'dict'. Error was a <class 'ansible.errors.AnsibleError'>, original message: with_dict expects a dict, got type <type 'list'>, terms contains [{u'foo': u'bar'}]" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
gather_facts: False | |
connection: local | |
vars: | |
mydict: | |
foo: bar | |
tasks: | |
- debug: | |
msg: "{{ lookup('dict', mydict) }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment