# Any concept of host specific files rather than role based files?

**URL:** <https://forum.ansible.com/t/any-concept-of-host-specific-files-rather-than-role-based-files/13452>\
**Category:** Ansible Project\
**Created:** [September 10, 2013, 8:04pm UTC](https://forum.ansible.com/t/any-concept-of-host-specific-files-rather-than-role-based-files/13452 "2013-09-10T20:04:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Rishi](https://forum.ansible.com/u/Rishi)\
**Post date:** [September 10, 2013, 8:04pm UTC](https://forum.ansible.com/t/any-concept-of-host-specific-files-rather-than-role-based-files/13452/1 "2013-09-10T20:04:48Z")

</div>

A few of my hosts need to have specific unique files copied to the host during configuration. They all share the same role but the files contents are different per host, I could go route of templating it but it would be a waste of time as I already have the static files.

So is there anything similar to the host\_vars concept with respect to roles, e.g something like host\_files/\<host\_name\>/\* where I can use the copy module on it?

Thanks.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [September 10, 2013, 8:09pm UTC](https://forum.ansible.com/t/any-concept-of-host-specific-files-rather-than-role-based-files/13452/2 "2013-09-10T20:09:58Z")

</div>

copy: src=files/{{inventory\_hostname}}/{{item}}  
with\_items:

- file1
- file2

you can even use fetch module to put them in per hostname dir structure, but I advise you to eventually template them.

---

<div class="post-metadata">

**Author:** ![Rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Rishi](https://forum.ansible.com/u/Rishi)\
**Post date:** [September 10, 2013, 8:19pm UTC](https://forum.ansible.com/t/any-concept-of-host-specific-files-rather-than-role-based-files/13452/3 "2013-09-10T20:19:48Z")

</div>

Doh, so simple was expecting some fancy built-in feature overlooked the obvious.

Cheers.

---

<div class="post-metadata">

**Author:** ![Rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Rishi](https://forum.ansible.com/u/Rishi)\
**Post date:** [September 11, 2013, 1:13pm UTC](https://forum.ansible.com/t/any-concept-of-host-specific-files-rather-than-role-based-files/13452/4 "2013-09-11T13:13:30Z")

</div>

Follow up question, copy doesn’t have a param to silently fail if source file does not exist. Out of the 20 hosts I use, only 3 have this static file that needs to be copied to it. So trying to the suggestion above, results in failures for files that do not exist.

copy: src=host\_files/{{inventory\_hostname}}/theFile dest…

I am leaning towards making a new role that only these 3 hosts exist in and run this single task.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 11, 2013, 6:32pm UTC](https://forum.ansible.com/t/any-concept-of-host-specific-files-rather-than-role-based-files/13452/5 "2013-09-11T18:32:03Z")

</div>

No, it definitely doesn’t have such a file.

You can however use a “local\_action” combined with the “stat” task to register where the local file exists, and then use “when” to skip the task.

---

<div class="post-metadata">

**Author:** ![Rishi](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@Rishi](https://forum.ansible.com/u/Rishi)\
**Post date:** [September 12, 2013, 12:38am UTC](https://forum.ansible.com/t/any-concept-of-host-specific-files-rather-than-role-based-files/13452/6 "2013-09-12T00:38:38Z")

</div>

Good suggestion, I ended up using ignore\_errors on the task, your way is cleaner though.
