Wei_Wei
(Wei Wei)
October 21, 2015, 3:48pm
1
Hi,
I am writing an inventory that contains 3 groups of hosts, and each of them have their own host specific variables. It looks like this:
[abc]
10.10.0.101
10.10.0.102
[abc:vars]
dest_path=/home/wwwroot/abc
port=4100
appname=abc
[efg]
10.10.0.10
10.10.0.11
[efg:vars]
dest_path=/home/wwwroot/efg
port=4100
appname=efg
[xyz]
10.10.0.10
10.10.0.11
[xyz:vars]
dest_path=/home/wwwroot/xyz
port=3001
appname=xyz
I run a test playbook, and always get the wrong variables. the playbook looks:
CyberCyber
(CyberCyber)
October 22, 2015, 1:38am
2
I’m curious to know what is going wrong here. Setting target_hosts=efg returns the correct variables, but using abc or xyz still returns the vars of the efg group:
ansible-playbook main.yml -i inventory.txt -e “target_hosts=abc”
PLAY [abc] ********************************************************************
TASK: [test vars] *************************************************************
ok: [10.10.0.101] => {
“msg”: “Group=abc”
}
TASK: [test vars 2] ***********************************************************
ok: [10.10.0.101] => {
“msg”: “Appname=efg”
}
TASK: [test vars 3] ***********************************************************
ok: [10.10.0.101] => {
“msg”: “Port=4100”
}
TASK: [test vars 3] ***********************************************************
ok: [10.10.0.101] => {
“msg”: “Dest_Path=/home/wwwroot/efg”
}
PLAY RECAP ********************************************************************
10.10.0.101 : ok=4 changed=0 unreachable=0 failed=0
I’ve tried splitting the groups vars into their own files under group_vars, but ended up with same results.
Wei_Wei
(Wei Wei)
October 22, 2015, 9:03am
3
Thanks Cyber! Yes, that’s exactly what I am facing.
Anyone any clues?
esco_real
(esco real)
October 22, 2015, 9:22am
4
I get this for abc:
TASK: [test vars] *************************************************************
ok: [10.10.0.101] => {
“msg”: “abc has name abc and port 4100 and /home/wwwroot/abc”
}
But the group xyz has the same hosts. So this is a expected result…
Version: 1.9.4