# How do you ensure a string is present in a directory of files?

**URL:** <https://forum.ansible.com/t/how-do-you-ensure-a-string-is-present-in-a-directory-of-files/14972>\
**Category:** Ansible Project\
**Created:** [April 8, 2014, 7:28pm UTC](https://forum.ansible.com/t/how-do-you-ensure-a-string-is-present-in-a-directory-of-files/14972 "2014-04-08T19:28:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tracy\_Phillips](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Tracy\_Phillips](https://forum.ansible.com/u/Tracy_Phillips)\
**Post date:** [April 8, 2014, 7:28pm UTC](https://forum.ansible.com/t/how-do-you-ensure-a-string-is-present-in-a-directory-of-files/14972/1 "2014-04-08T19:28:12Z")

</div>

Hi,

What is the best way to ensure gpgcheck=1 in all places of all .repo files in /etc/yum.repos.d/?

Thanks,

Tracy

---

<div class="post-metadata">

**Author:** ![Tracy\_Phillips](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Tracy\_Phillips](https://forum.ansible.com/u/Tracy_Phillips)\
**Post date:** [April 9, 2014, 2:02pm UTC](https://forum.ansible.com/t/how-do-you-ensure-a-string-is-present-in-a-directory-of-files/14972/2 "2014-04-09T14:02:52Z")

</div>

Anyone have an idea on this?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 9, 2014, 2:03pm UTC](https://forum.ansible.com/t/how-do-you-ensure-a-string-is-present-in-a-directory-of-files/14972/3 "2014-04-09T14:03:08Z")

</div>

While not the direct answer to your question, ideally you should manage all files in yum.repos.d with the “template” directive, making sure each one is centrally placed 100% by the ansible server.

If you don’t want to do this, you could do something like:

- shell: ls -l /etc/yum.repos.d  
register: files

- shell: grep command here {{ item }}  
with\_items: files.stdout.split()

---

<div class="post-metadata">

**Author:** ![Tracy\_Phillips1](https://avatars.discourse-cdn.com/v4/letter/t/919ad9/32.png) [@Tracy\_Phillips1](https://forum.ansible.com/u/Tracy_Phillips1)\
**Post date:** [April 9, 2014, 2:04pm UTC](https://forum.ansible.com/t/how-do-you-ensure-a-string-is-present-in-a-directory-of-files/14972/4 "2014-04-09T14:04:24Z")

</div>

Good thinking Michael! I was trying to over complicate it 🙂

Thanks!
