$ 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
---
- hosts: all
vars:
ldap_names:
- { cn: 'bogus', default: yes }
tasks:
- name: lookup ldap_names in directory
shell: ". /etc/env_ansible ; /home/rowagn/data-platform/oracle/ansible/client12c/test.py -j {{ item.cn }}"
with_items: "{{ ldap_names }}"
register: oidLookup_output
delegate_to: localhost
become: no
- name: debug
debug: msg="result is {{ (item.stdout | from_json).hosts }}"
with_items: "{{ oidLookup_output.results }}"
- name: lookup
debug: msg="IP is {{ lookup('dig', (item.stdout | from_json).hosts, wantlist=True) }}"
with_items: "{{ oidLookup_output.results }}"
$ ansible-playbook -clocal test.yml
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [10.239.211.85]
TASK [lookup ldap_names in directory] ******************************************
changed: [10.239.211.85 -> localhost] => (item={u'default': True, u'cn': u'bogus'})
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', '_ansible_no_log': False, u'stdout': u'{"hosts": ["www.google.com"]}', u'cmd': u'. /etc/env_ansible ; /home/rowagn/data-platform/oracle/ansible/client12c/test.py -j bogus', u'changed': True, 'invocation': {'module_name': u'command', u'module_args': {u'creates': None, u'executable': None, u'_uses_shell': True, u'_raw_params': u'. /etc/env_ansible ; /home/rowagn/data-platform/oracle/ansible/client12c/test.py -j bogus', u'removes': None, u'warn': True, u'chdir': None}}, 'item': {u'default': True, u'cn': u'bogus'}, u'delta': u'0:00:00.013173', u'stderr': u'', u'rc': 0, '_ansible_delegated_vars': {'ansible_host': u'localhost'}, 'stdout_lines': [u'{"hosts": ["www.google.com"]}'], u'start': u'2018-12-10 12:34:26.164078', u'warnings': []}) => {
"item": {
"changed": true,
"cmd": ". /etc/env_ansible ; /home/rowagn/data-platform/oracle/ansible/client12c/test.py -j bogus",
"delta": "0:00:00.013173",
"end": "2018-12-10 12:34:26.177251",
"invocation": {
"module_args": {
"_raw_params": ". /etc/env_ansible ; /home/rowagn/data-platform/oracle/ansible/client12c/test.py -j bogus",
"_uses_shell": true,
"chdir": null,
"creates": null,
"executable": null,
"removes": null,
"warn": true
},
"module_name": "command"
},
"item": {
"cn": "bogus",
"default": true
},
"rc": 0,
"start": "2018-12-10 12:34:26.164078",
"stderr": "",
"stdout": "{\"hosts\": [\"www.google.com\"]}",
"stdout_lines": [
"{\"hosts\": [\"www.google.com\"]}"
],
"warnings": []
},
"msg": "result is [u'www.google.com']"
}
TASK [lookup] ******************************************************************
fatal: [10.239.211.85]: FAILED! => {"failed": true, "msg": "An unhandled exception occurred while running the lookup plugin 'dig'. Error was a <type 'exceptions.AttributeError'>, original message: 'list' object has no attribute 'startswith'"}
PLAY RECAP *********************************************************************
10.239.211.85 : ok=3 changed=1 unreachable=0 failed=1 --
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/j-Adyf2eeWw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2980419.Iyv8cOm4ia%40x1.
For more options, visit https://groups.google.com/d/optout.