# How to use different variables file between prod, dev1, dev2, etc?

**URL:** <https://forum.ansible.com/t/how-to-use-different-variables-file-between-prod-dev1-dev2-etc/23128>\
**Category:** Ansible Project\
**Created:** [November 29, 2016, 8:06pm UTC](https://forum.ansible.com/t/how-to-use-different-variables-file-between-prod-dev1-dev2-etc/23128 "2016-11-29T20:06:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Wen](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jeffrey\_Wen](https://forum.ansible.com/u/Jeffrey_Wen)\
**Post date:** [November 29, 2016, 8:06pm UTC](https://forum.ansible.com/t/how-to-use-different-variables-file-between-prod-dev1-dev2-etc/23128/1 "2016-11-29T20:06:24Z")

</div>

Here is what my current `ansible/` directory looks like:

`  
├── development  
│ └── hosts  
├── production  
│ └── hosts  
├── group\_vars  
│ └── [prod.example.com](http://prod.example.com)  
│ └── [dev1.example.com](http://dev1.example.com)  
│ └── [dev2.example.com](http://dev2.example.com)  
├── playbooks  
│ ├── [prod.example.com.com](http://prod.example.com.com)  
│ │ └── site.yml  
│ ├── [dev1.example.com.com](http://dev1.example.com.com)  
│ │ └── site.yml  
│ ├── [dev2.example.com.com](http://dev2.example.com.com)  
│ │ └── site.yml  
└── roles  
├── webservers  
├── templates  
│ └── main.yml  
├── tasks  
│ └── main.yml  
└── vars  
└── main.yml

`

In my `roles/webservers/templates/main.yml`, I would reference variables such as

1. `http_port`

2. `document_root`

3. `server_name`  
I can easily reference them in my `roles/webservers/templates/main.yml` by typing the following into my template:

4. `{{ http_port }}`

5. `{{ document_root }}`

6. `{{ server_name }}`  
I know when I type it like the above, it references my `roles/webservers/vars/main.yml` file; which contain variables for production.

**I would like to change the 3 variables if I am referencing my `dev1.example.com` and `dev2.example.com` environments, but I am unsure on how to do this with using** `group_vars/dev1.example.com` **and** `group_vars/dev2.example.com`

---

<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:** [November 29, 2016, 8:11pm UTC](https://forum.ansible.com/t/how-to-use-different-variables-file-between-prod-dev1-dev2-etc/23128/2 "2016-11-29T20:11:46Z")

</div>

Move from vars/main.yml to default/main.yml then the group\_vars will be able to override the role vars.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Wen](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jeffrey\_Wen](https://forum.ansible.com/u/Jeffrey_Wen)\
**Post date:** [November 29, 2016, 8:15pm UTC](https://forum.ansible.com/t/how-to-use-different-variables-file-between-prod-dev1-dev2-etc/23128/3 "2016-11-29T20:15:33Z")

</div>

Hi Brian,

If I change it to `defaults/main.yml`, how would I reference my `group_vars/dev1.example.com` variables file?

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Wen](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jeffrey\_Wen](https://forum.ansible.com/u/Jeffrey_Wen)\
**Post date:** [November 29, 2016, 8:37pm UTC](https://forum.ansible.com/t/how-to-use-different-variables-file-between-prod-dev1-dev2-etc/23128/4 "2016-11-29T20:37:44Z")

</div>

I actually added in the variables into my development/hosts file like so:

[dev1]  
[dev1.example.com](http://dev1.example.com)

[dev1:vars]  
http\_port=80  
server\_name=[dev1.example.com](http://dev1.example.com)  
document\_root=/var/www/dev1.example.com

[dev2]  
[dev2.example.com](http://dev2.example.com)

[dev2:vars]  
http\_port=80  
server\_name=[dev2.example.com](http://dev2.example.com)  
document\_root=/var/www/dev2.example.com

Do you believe this is an efficient/proper way of having specific variables per node/environment?

---

<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:** [November 29, 2016, 8:41pm UTC](https://forum.ansible.com/t/how-to-use-different-variables-file-between-prod-dev1-dev2-etc/23128/5 "2016-11-29T20:41:27Z")

</div>

either in inventory file or in host\_vars/, both work
