0

I'm trying to set up a (hopefully) simple Ansible script to check out a git branch. There are three environments: dev, qa, and live. Each spans two hosts. But dev and qa use the same hosts, just using different directories.

I'd like to have an inventory file sorta like this:

[dev]
internal1.example.com
internal2.example.com

[dev:vars]
dir = /opt/dev

[qa]
internal1.example.com
internal2.example.com

[qa:vars]
dir = /opt/qa

[live]
live1.example.com
live2.example.com

[live:vars]
dir = /opt/live

But this doesn't work. Variable values are taken from all groups they belong to. So internal1.example.com picks up the dir value from both dev and qa, regardless of which one I'm trying to deploy.

How can I assign a variable that applies to a host depending on which group I am targeting?

I'm using Ansible version 1.5.4.

1 Answer 1

-1

https://ansible-tips-and-tricks.readthedocs.io/en/latest/ansible/inventory/

You can use Group Specific Variables with files located in [ansible_base_dir]/group_vars/[group-name]

So you would have the files:

[ansible_base_dir]/group_vars/dev

---
dir: /opt/dev

[ansible_base_dir]/group_vars/qa

---
dir: /opt/qa

[ansible_base_dir]/group_vars/live

---
dir: /opt/live

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .