# Replace contents of same named file located in multiple non-unique directories.

**URL:** <https://forum.ansible.com/t/replace-contents-of-same-named-file-located-in-multiple-non-unique-directories/19560>\
**Category:** Ansible Developer\
**Created:** [October 20, 2015, 1:15pm UTC](https://forum.ansible.com/t/replace-contents-of-same-named-file-located-in-multiple-non-unique-directories/19560 "2015-10-20T13:15:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chad\_Yantorno](https://avatars.discourse-cdn.com/v4/letter/c/e9c0ed/32.png) [@Chad\_Yantorno](https://forum.ansible.com/u/Chad_Yantorno)\
**Post date:** [October 20, 2015, 1:15pm UTC](https://forum.ansible.com/t/replace-contents-of-same-named-file-located-in-multiple-non-unique-directories/19560/1 "2015-10-20T13:15:25Z")

</div>

I’d like to replace some text in a file using the Replace: command. The file is located in many different sub-directories. I know how to replace text when I know the directory, but the file I want to replace could be in multiple locations unique to each server. I know each folder where the file exists ends with \_. How can I make this happen?

ex: file name = file.conf  
folder structure = /opt/\<different\_folder\_name\>\_[0-9]/file.conf

---

<div class="post-metadata">

**Author:** ![Corwin\_Brown](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@Corwin\_Brown](https://forum.ansible.com/u/Corwin_Brown)\
**Post date:** [October 21, 2015, 6:21pm UTC](https://forum.ansible.com/t/replace-contents-of-same-named-file-located-in-multiple-non-unique-directories/19560/2 "2015-10-21T18:21:19Z")

</div>

I think the cleanest way to do it would be to save the folder name as a host var. If you can’t do that, here’s a really gross way!

Use find. Something like:

> find /opt -name ‘file.conf’

If that file name is unique, you should only get one result.

> 

> - name: Find file.conf Path  
> command: find /opt -name ‘file./conf’  
> register: file\_conf\_path
> 
> - name: Do something to file.conf  
> file:  
> dest: “{{ file\_conf\_path.stdout }}”
> 
> >

This is not an ideal solution, and not technically idempotent, but it would solve your problem.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 21, 2015, 11:23pm UTC](https://forum.ansible.com/t/replace-contents-of-same-named-file-located-in-multiple-non-unique-directories/19560/3 "2015-10-21T23:23:40Z")

</div>

in 2.0 you have the find module
