# Remove missing files from a list

**URL:** <https://forum.ansible.com/t/remove-missing-files-from-a-list/27188>\
**Category:** Ansible Project\
**Created:** [April 4, 2018, 8:42pm UTC](https://forum.ansible.com/t/remove-missing-files-from-a-list/27188 "2018-04-04T20:42:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andy\_Smith](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Andy\_Smith](https://forum.ansible.com/u/Andy_Smith)\
**Post date:** [April 4, 2018, 8:42pm UTC](https://forum.ansible.com/t/remove-missing-files-from-a-list/27188/1 "2018-04-04T20:42:55Z")

</div>

Hi,

Imagine a service foo that has a config file  
/etc/foo/files\_of\_interest which is just a list of other file paths,  
one per line. If you put a path that doesn't exist into the file  
then the service foo complains about it regularly, so you'd better  
not do that.

I'd like to provide a default list of paths to all remote hosts, but  
sometimes some of those paths won't be present. At the time the  
/etc/foo/files\_of\_interest file is built I would like to exclude any  
paths that don't exist.

I would prefer not to use per-host variables to specify a different  
set of paths as that would be too much to manage and some of these  
paths may spring into existence later on, without me knowing.

I found one way to do it:

&nbsp;&nbsp;&nbsp;&nbsp;[https://gist.github.com/grifferz/a505e352baa18e06ba1ba1d02a123ee2](https://gist.github.com/grifferz/a505e352baa18e06ba1ba1d02a123ee2)

This works, but have I missed something which allows this to be done  
in a more elegant way?

Cheers,  
Andy

---

<div class="post-metadata">

**Author:** ![flowerysong1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@flowerysong1](https://forum.ansible.com/u/flowerysong1)\
**Post date:** [April 4, 2018, 9:56pm UTC](https://forum.ansible.com/t/remove-missing-files-from-a-list/27188/2 "2018-04-04T21:56:39Z")

</div>

Building the list of missing files doesn’t need to be a multi-step process or involve an Ansible loop. I would preserve the ordering in the generated file instead of splitting it into two lists, so that someone manually adding a file and uncommenting its line creates the same state as re-templating the file.

So, something like this: [https://gist.github.com/flowerysong/d6c5b16123473279c025fe8d34c20bd6](https://gist.github.com/flowerysong/d6c5b16123473279c025fe8d34c20bd6)

---

<div class="post-metadata">

**Author:** ![Andy\_Smith](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Andy\_Smith](https://forum.ansible.com/u/Andy_Smith)\
**Post date:** [April 6, 2018, 3:02am UTC](https://forum.ansible.com/t/remove-missing-files-from-a-list/27188/3 "2018-04-06T03:02:23Z")

</div>

Hi,
