# different setting in template for different inventory

**URL:** <https://forum.ansible.com/t/different-setting-in-template-for-different-inventory/14160>\
**Category:** Ansible Project\
**Created:** [December 16, 2013, 7:37am UTC](https://forum.ansible.com/t/different-setting-in-template-for-different-inventory/14160 "2013-12-16T07:37:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marko\_Lisica](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Marko\_Lisica](https://forum.ansible.com/u/Marko_Lisica)\
**Post date:** [December 16, 2013, 7:37am UTC](https://forum.ansible.com/t/different-setting-in-template-for-different-inventory/14160/1 "2013-12-16T07:37:58Z")

</div>

Hello, I am trying to make simple NGINX template. I have development inventory (it is vagrant) and staging which is remote VPS. I want to make different default root folder and different log location for these two environments. Ofcorse couldnt manage that 🙂 .  
I have this in my template:

> {% if (inventory\_hostname in groups[‘webservers’]) %}  
> access\_log /var/log/nginx/nginx-access.log;  
> error\_log /var/log/nginx/nginx-error.log;  
> {% endif %}

And for dev environment:

> > {% if (inventory\_hostname in groups[‘vagrant’]) %}  
> > access\_log /vagrant/log/nginx/nginx-access.log;  
> > error\_log /vagrant/log/nginx/nginx-error.log;  
> > {% endif %}

Whatever inventory I choose when depoying ansible-playbook I get BOTH of cases created in nginx config file. I am obviously missing something here. Any advice?

---

<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:** [December 16, 2013, 1:28pm UTC](https://forum.ansible.com/t/different-setting-in-template-for-different-inventory/14160/2 "2013-12-16T13:28:10Z")

</div>

It seems most likely that your host has been inadvertently added to both groups.

It’s hard to say without seeing your inventory.

---

<div class="post-metadata">

**Author:** ![Marko\_Lisica](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Marko\_Lisica](https://forum.ansible.com/u/Marko_Lisica)\
**Post date:** [December 16, 2013, 1:34pm UTC](https://forum.ansible.com/t/different-setting-in-template-for-different-inventory/14160/3 "2013-12-16T13:34:09Z")

</div>

Hello here s contents of my hosts file. I have separate files for staging and vagrant.

---

<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:** [December 16, 2013, 2:08pm UTC](https://forum.ansible.com/t/different-setting-in-template-for-different-inventory/14160/4 "2013-12-16T14:08:30Z")

</div>

Unrelated:

What you have done above is redefined the host record. In the second case you are overriding the variables for the host. To fix this, instead do:

[webservers]  
webservers ansible\_ssh\_user=root

[dbservers]  
dbservers ansible\_ssh\_user=root

Since you are definining “ansible\_hostname” it won’t use the IP address to contact things anyway.

I’m unclear why your template is not working, though this may be something else not shown above, such as it using the wrong template file, etc?

---

<div class="post-metadata">

**Author:** ![Marko\_Lisica](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Marko\_Lisica](https://forum.ansible.com/u/Marko_Lisica)\
**Post date:** [December 17, 2013, 11:12am UTC](https://forum.ansible.com/t/different-setting-in-template-for-different-inventory/14160/5 "2013-12-17T11:12:29Z")

</div>

thanks for help, I still have some trouble.

I have defined inventory like this:

[webservers]  
webservers ansible\_ssh\_user=root

[dbservers]  
dbservers ansible\_ssh\_user=root

Problem is I dont have DNS names for these hosts, is it possibile to define IP addresses of these hosts inside ansible, so I dont have to edit /etc/hosts ?

---

<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:** [December 17, 2013, 1:10pm UTC](https://forum.ansible.com/t/different-setting-in-template-for-different-inventory/14160/6 "2013-12-17T13:10:11Z")

</div>

/etc/ansible/hosts:

[groupname]  
myhostname ansible\_ssh\_host=10.1.1.10
