On Ansible 2.2,
I have an Ansible hosts file:
[webserver]
aegir.dev
[hostmaster]
aegir.dev
I have two group_vars/
files:
# group_vars/webserver.yml
my_var:
- vagrant
and
# group_vars/hostmaster.yml
my_var:
- vagrant
- aegir
and the playbook:
- hosts: webserver
tasks:
- debug: var=my_var
- hosts: hostmaster
tasks:
- debug: var=my_var
Output:
PLAY [webserver] ***************************************************************
TASK [setup] *******************************************************************
ok: [aegir.dev]
TASK [debug] *******************************************************************
ok: [aegir.dev] => {
"my_var": [
"vagrant",
"aegir"
]
}
PLAY [hostmaster] **************************************************************
TASK [setup] *******************************************************************
ok: [aegir.dev]
TASK [debug] *******************************************************************
ok: [aegir.dev] => {
"my_var": [
"vagrant",
"aegir"
]
}
Why both webserver
and hostmaster
use the variables from hostmaster.yml
?
Probably I'm not using the group_vars
correctly but how I can fix that?
EDIT
The real case scenario is that I have the same role running on two groups, one is webserver
that actually contains 4 generic servers and the hostmaster
group that is a webserver + extra configuration on the same role (the user aegir exists only on aegir.dev and not on the other 3 web-servers)