Capture the path from the list returned via find module

14 views
Skip to first unread message

Saranya N

unread,
Apr 25, 2018, 12:09:37 PM4/25/18
to Ansible Project
Hi all ,

I'm trying to find two XML files in all the locations only if it contains a severname and then pass the list of these files to the replace module to replace that severname by another string.

I'm able to get the file list via shell module but not via the find module.

I tried various options that I found online

---

- hosts: all



tasks:

- name: Find all Paascli Files

find:

paths: /opt/common

patterns: “test.xml|ordit.xml”

recurse: yes

contains: "servername "

register: matched_files



- debug:

msg: "{{ matched_files.files }}"



# - debug:

# msg: "{{ matched_files.files[0].path }}"





- name: Replace the word

replace:

path: "{{ item.path }}"

regexp: "servername"

replace: "new_servername"

backup: yes

# with_items: "{{ matched_files.files }}"

with_items: "{{ matched_files.results | sum(attribute='files', start=[]) | map(attribute='path')|list }}"

I get " dict object has no attribute results for the above with_item option.


Can someone suggest how to capture the path attribute from the returned file list via find module.










Karl Auer

unread,
Apr 25, 2018, 7:05:26 PM4/25/18
to ansible...@googlegroups.com
Not sure if it will make a difference, but you have a space after "servername" in your contains: line.

​Regards, K.​












--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6f2e442c-7057-4c2f-a43d-ce34f53379a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Karl Auer

Email  : ka...@2pisoftware.com
Website: 
http://2pisoftware.com

GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

Saranya N

unread,
Apr 25, 2018, 10:50:28 PM4/25/18
to Ansible Project
That space is a typo in my post
Reply all
Reply to author
Forward
0 new messages