Hey all-
I’m having more problems w/ the dig lookup. If I statically define a list of hosts to lookup as a variable, it works. But if I return the list of hosts from another script, it fails. Here’s a simple example:
`
$ cat test.py
#!/usr/bin/env python
import json
hostList =
hostList.append((‘www.google.com’))
j = {}
j[‘hosts’] = hostList
print json.dumps(j)
$ cat test.yml
- name: debug
debug: msg="result is {{ (item.stdout | from_json).hosts }}"
with_items: "{{ oidLookup_output.results }}"
Your hosts is a list with one element www.google.com
- name: lookup
debug: msg="IP is {{ lookup('dig', (item.stdout | from_json).hosts,
wantlist=True) }}"
with_items: "{{ oidLookup_output.results }}"
So here you are feeding dig a list, it doesn't take a list, only a string.
TASK [debug]
*******************************************************************
ok: [10.239.211.85] => (item={'_ansible_parsed': True,
'_ansible_item_result': True, u'end': u'2018-12-10 12:34:26.177251',
</snip>
"stdout": "{\"hosts\": [\"www.google.com\"]}",
"stdout_lines": [
"{\"hosts\": [\"www.google.com\"]}"
],
"warnings":
},
"msg": "result is [u'www.google.com']"
Here you clearly see that it's a list and not a string.
Thanks Kai. That’s it. I thought I had read somewhere that dig will accept a list, but clearly not.
Doesn't accept a list, but do return a list if wantlist=True.