James.Y
James.Y

Reputation: 1457

Ansible to separate variables in playbook/group_vars/*?

In inventory file, I define two groups, A and B. Also have two separate playbooks to apply host of them.

Meanwhile, define group_vars/A and group_vars/B to hold the variables, but some of them with same name.

By the following document, it says only the last one wins for same name variable.

http://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable

So how to let Ansible to only use the variables defined in groups/A when play play_book_A?

The other question is, what's the difference between playbook group_vars/* and inventory group_vars/* ?

Upvotes: 1

Views: 1131

Answers (1)

mcorbin
mcorbin

Reputation: 9

The difference between playbook group_vars and inventory group_vars is only the precedence. group_vars files in playbook and inventory are merged (i just tested it).

Regarding your problem, if your hosts are not in group A AND group B, everything should work as expected (no overriding between group_vars).

Upvotes: 0

Related Questions