Shashi
Shashi

Reputation: 2714

Ansible in not picking up varibles from group_vars

I have created two folders in environments/staging/group_vars i.e.

  1. all/main.yml

  2. services/main.yml

When i execute my playbook as below

ansible-playbook -i environments/staging myplaybook.yml

Variable defined under group_vars/all/main.yml are being picked up by myplaybook but its not picking up services vars.

Any pointers here ?

Upvotes: 1

Views: 6423

Answers (3)

Ngstigator
Ngstigator

Reputation: 109

I was able to have environment-specific variables using children as follows:

playbook.yml

hosts: webservers

hosts/development

[webservers]
IP_ADDRESS1
...

[development:children]
webservers

group_vars/development

var1: value1
var2: value2
...

Usage

ansible-playbook playbook.yml -i hosts/development ...etc

Upvotes: 0

Andrew
Andrew

Reputation: 4622

If you want to separate globally accessible variables to different files (for readability, perhaps), you can store them inside group_vars/all directory under different names, for example: group_vars/ all/ services.yml something_else.yml

Please refer to official doc: http://docs.ansible.com/ansible/latest/intro_inventory.html#splitting-out-host-and-group-specific-data

Upvotes: 1

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68229

As you said in the comments, you don't have group services defined in your inventory.

Every subfolder in group_vars folder corresponds to group name and one for special group all.

So for inventory file:

[group1]
host1

[group2]
host2

group_vars may look like:

./group_vars/all/common.yml
./group_vars/group1/gr1_specific.yml
./group_vars/group2/gr2_specific.yml

So host1 will have vars from common.yml and gr1_specific.yml, host2common.yml and gr2_specific.yml.

Upvotes: 1

Related Questions