Skip to content

Instantly share code, notes, and snippets.

@halberom
Last active October 24, 2017 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halberom/c78b8bb51714cdce8deff128b9af5bc9 to your computer and use it in GitHub Desktop.
Save halberom/c78b8bb51714cdce8deff128b9af5bc9 to your computer and use it in GitHub Desktop.
ansible - bug with lookup dict
# 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)
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'}]"
}
---
- 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