# Host-based files and templates

**URL:** <https://forum.ansible.com/t/host-based-files-and-templates/17458>\
**Category:** Ansible Project\
**Created:** [February 6, 2015, 1:46pm UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458 "2015-02-06T13:46:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [February 6, 2015, 1:46pm UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458/1 "2015-02-06T13:46:35Z")

</div>

Is there a feature in Ansible for host-based files/templates directory?

In my actual setup i am keeping track of it manually (on playbook level there is a files/ directory with one directory for {{ inventory\_hostname }} .

Nicer would be the same mechanism as host\_vars / group\_vars . Sometimes vars are not sufficient (for example the monitoring configuration differs too much between the machines).

Would it be worth a feature request?

Regards Ilya

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [February 6, 2015, 2:43pm UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458/2 "2015-02-06T14:43:19Z")

</div>

If your monitoring configuration differs too much between machines, I  
think you might be doing it wrong. I can definitely understand how it  
would be different per group/role (db vs web, etc) but how would it  
differ between machines of the same role?

---

<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:** [February 6, 2015, 2:53pm UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458/3 "2015-02-06T14:53:06Z")

</div>

Most users use variables to handle the per host differences vs full templates.

---

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [February 9, 2015, 3:55pm UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458/4 "2015-02-09T15:55:41Z")

</div>

The most actual case with my configuration is: I have multiple machines with the same apache configuration (application) except for ssl certificates. Would one put the whole certificate into a variable (looks strange to me)?

@Michael Peters:  
I am using monit for monitoring. And depending on machine there are completely different services to monitor. I could also do multiple roles like ‘monit\_webservice’ , ‘monit\_db’, ‘monit\_application\_a’, ‘monit\_application\_b’ for just one configuration file. … this would mean a certain amount of duplication and it seems odd in terms of clarity. Also some applications do not support a ‘conf.d/’ style. In my actual setup i can see on a per-machine basis which services are monitored.

---

<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:** [February 9, 2015, 4:07pm UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458/5 "2015-02-09T16:07:01Z")

</div>

you can put the list of certificates per host/app in a variable and  
then just reference that variable to copy the certs and reference them  
from the configs.

I really don't understand the comment about needing a conf.d when you  
have multiple functions to apply to a file, that is easily handled  
within a template.

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [February 9, 2015, 4:25pm UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458/6 "2015-02-09T16:25:30Z")

</div>

You don't need a whole role for each config file. If you have a  
webservice role, have that role depend on the monit role. The monit  
role will make sure that monit is installed and configured globally.  
And then the webservice role would add the extra monit configuration  
file that is specific for webservices. And you can repeat this same  
pattern for other things like rsyslog, statsd, collectd, etc.

And you're right that some applications don't do the conf.d/ pattern  
so you need to do extra work to get around that. But still in those  
cases you get around that in role-specific ways, not host specific  
ways. I still think that if you need host specific files and  
templates, something is probably wrong.

---

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [February 9, 2015, 5:18pm UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458/7 "2015-02-09T17:18:15Z")

</div>

Thanks a lot, great idea for my poor design 🙂 (did not have the role dependencies in mind).

Do you have any idea what to do about the machine-specific ssl-certificates?

Thanks, Ilya

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [February 9, 2015, 5:31pm UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458/8 "2015-02-09T17:31:36Z")

</div>

Again, I can't think of a valid "machine-specific" ssl certificate  
case. It should be based on roles, right? But I liked Brian Coca's  
ealier comment about putting the names of the files in a variable and  
then using that variable to determine what to deploy.

---

<div class="post-metadata">

**Author:** ![profhase85](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@profhase85](https://forum.ansible.com/u/profhase85)\
**Post date:** [February 10, 2015, 9:47am UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458/9 "2015-02-10T09:47:37Z")

</div>

No, a certificate is always machine-specific. Multiple machines may have the same role, like “webapplicationA”. this application may run on different hosts like ([mytestapplication.com](http://mytestapplication.com), [myprodapplication.com](http://myprodapplication.com), etc). Everything stays equal except for the certificate, which is a machine parameter.

---

<div class="post-metadata">

**Author:** ![Mirko\_Friedenhagen](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Mirko\_Friedenhagen](https://forum.ansible.com/u/Mirko_Friedenhagen)\
**Post date:** [February 13, 2015, 8:15am UTC](https://forum.ansible.com/t/host-based-files-and-templates/17458/10 "2015-02-13T08:15:00Z")

</div>

Hello,

when you have an active/passive approach or use IP based load  
balancing (e.g. round robin) for a service you may want to use the  
same SSL certificate on all machines.

Regards  
Mirko  
Regards Mirko
