Reputation: 13
I have 2 with_item
tasks in ansible and I want to combine these two tasks and use nested with items.
I want to do something like this..
- debug: msg="{{ item }}"
with_items:
- "{{ IP.split(',') }}"
- debug: msg="{{ item.json.Password }}"
with_items:
- "{{ password.results }}"
- debug: msg="{{ item.0 }} {{ item.1 }}"
with_nested:
- [ "{{ IP.split(',') }}" ]
- [ "{{ password.results.json.Password }}" ]
The first 2 tasks are running successfully. but 3rd task giving error as
"fatal: [localhost]: FAILED! => {"msg": "'list object' has no attribute 'json'"}"
Upvotes: 1
Views: 218
Reputation: 67984
Try
with_nested:
- "{{ IP.split(',') }}"
- "{{ password.results|json_query('[].json.Password') }}"
Q: Error 'You need to install jmespath'
A: It's also possible to use filter map. For example
with_nested:
- "{{ IP.split(',') }}"
- "{{ password.results|map(attribute='json.Password')|list }}"
Upvotes: 1