Inventory group variables

49 views
Skip to first unread message

Wei Wei

unread,
Oct 21, 2015, 11:54:13 AM10/21/15
to Ansible Project
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:

---

- hosts: "{{ target_hosts }}"

  user: webapps


  tasks:

     - name: test vars

       debug: msg="{{ target_hosts }} has name {{ appname }} and port {{ port }} and {{ dest_path }}"


and I run it like this: ansible-playbook -i inventory test.yml -e "target_hosts=efg". I tried with all the 3 groups, but it always give me the same anwser: "prd has name efg and port 4100 and /home/wwwroot/efg".


Ansible: 1.9.2

OS: centos 6.2


Please help! 

Thanks!

CyberCyber

unread,
Oct 21, 2015, 9:38:15 PM10/21/15
to Ansible Project
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

unread,
Oct 22, 2015, 5:03:46 AM10/22/15
to Ansible Project
Thanks Cyber! Yes, that's exactly what I am facing.

Anyone any clues?

esco real

unread,
Oct 22, 2015, 5:22:18 AM10/22/15
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages