Template not updated with correct values from group_vars file

41 views
Skip to first unread message

Subramanian Olagappan

unread,
Oct 16, 2014, 6:31:56 AM10/16/14
to ansible...@googlegroups.com

Hi All,

I have a playbook which copy application.proprties with db.username and db.password.

I have qa env and qa1 is a cluster with app and ui server. The hosts file (hosts.qa) is as per the best practises mentioned in docs.ansible.com site. I have similar hosts file for dev ( hosts.dev )

I have group_vars file for qa and qa1 with db.usernamd and db.password values. Same for dev and dev1 groups

>ansible-playbook  -i inventory/hosts.qa  --limit qa1 site.yml

When I run the playbook, with --limit qa1, the application properties template is not updated with qa1 group_vars file values, instead it has "qa" as db_username and db_password. The same works fine for --limit dev1

Has anyone faced this problem ?

Thanks,
Olga

ansible 1.7.2
Centos 6.5

site.yml

---
- hosts: appservers
  remote_user: '{{ remote_user }}'
  sudo: True
  tasks:
  - name: configure application properties
    template: src=templates/application.properties.j2 dest=/tmp/application.properties
              owner=root group=root mode=744


templates/application.properties

# {{ ansible_managed }}
#Database Configuration
db.username={{ db_username }}
db.password={{ db_password }}


inventory/hosts.dev

[dev1-appserver]
xyz.com

[dev1-uiserver]
abc.com

[appservers:children]
dev1-appserver

[dev1:children]
dev1-appserver
dev1-uiserver

[dev:children]
dev1-appserver
dev1-uiserver

[uiservers:children]
dev1-uiserver


inventory/hosts.qa

[qa1-uiserver]
123.com

[qa1-appserver]
567.com

[qa:children]
qa1-appserver
qa1-uiserver

[appservers:children]
qa1-appserver

[qa1:children]
qa1-appserver
qa1-uiserver

[uiservers:children]
qa1-uiserver


group_vars/qa

# variables related to the qa environment
db_username: qa
db_password: qa

group_vars/qa1

# variables related to the qa environment
db_username: qa1
db_password: qa1

group_vars/dev

# variables related to the dev environment
db_username: dev
db_password: dev

group_vars/dev1

# variables related to the dev1 environment
db_username: dev1
db_password: dev1

olga

unread,
Oct 19, 2014, 10:20:02 AM10/19/14
to ansible...@googlegroups.com
Hi,

I went thru the docos on variable scope and was able to identify the issue:

[qa:children]
qa1

Solved my problem !

Thanks,
Olga
Reply all
Reply to author
Forward
0 new messages