find module parse return value

38 views
Skip to first unread message

Eugene Polyanichko

unread,
Oct 30, 2015, 4:27:19 PM10/30/15
to Ansible Project
Official documentation http://docs.ansible.com/ansible/find_module.html states, that main return value name is files and it's "list of dictionaries". Does anyone know how to parse this value? I've tried all possible loops, but I can't figure out how to loop properly. I've read docs dozens of times, googled and nothing.

Basic code:

- name: Get files
 find: paths="/etc/" patterns="*"
 register: find_results

- name: Make sure line is present
  lineinfile: dest=/etc/cron.d/{{ item }} insertbefore=BOF line="123"
  with_items: find_results.files

This example doesn't work, obviously, because as far as i understand, to traverse "list of dictionaries" you need to have with_dict inside with_items, but I don't see a way to have nested loops of different types.

Brian Coca

unread,
Oct 30, 2015, 4:29:42 PM10/30/15
to Ansible Project
item would be a dictionary, I'm assuming what you want is a path:

lineinfile: dest={{ item.path }}

-------------
Brian Coca

Eugene Polyanichko

unread,
Oct 30, 2015, 4:48:33 PM10/30/15
to Ansible Project
Thanks a lot for reply. You saved my day. I've been pulling my hair off for like 4 hours and the problem was simply in wrong "dest" value, because I didn't see my mistake and treated error output not the way it should be :)
with_items and item.path works of course
Reply all
Reply to author
Forward
0 new messages