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

Here is what my current ansible/ directory looks like:

`
├── development
│ └── hosts
├── production
│ └── hosts
├── group_vars
│ └── prod.example.com
│ └── dev1.example.com
│ └── dev2.example.com
├── playbooks
│ ├── prod.example.com.com
│ │ └── site.yml
│ ├── dev1.example.com.com
│ │ └── site.yml
│ ├── 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

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

Hi Brian,

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

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

[dev1]
dev1.example.com

[dev1:vars]
http_port=80
server_name=dev1.example.com
document_root=/var/www/dev1.example.com

[dev2]
dev2.example.com

[dev2:vars]
http_port=80
server_name=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?

either in inventory file or in host_vars/, both work