0

I am using Ansible 2.0.0.2.

I have inventory file like this:

[webproxy]
testserver

[database]
testserver

[application]
testserver

[testing:children]
webproxy
database

I run roles from playbooks like this:

---
- hosts: application

  become: true

  roles:
    - application

I define variables for testing environment in group_vars/testing. I have roles webproxy, database and application.

Since application group is not included in the testing group I would expect running the application role to fail because I have defined required variables only for testing group. In reality running application.yaml works it is able to use variables defined in group_vars/testing. Is that correct behaviour?

The testing group seems have at least some effect, because if I remove it completely from inventory file, then running application roles fails because of undefined variables as expected.

Are group_vars supposed to work like this? Is this maybe caused by the fact that I install roles on the same host? (I don't have access to multiple machines right now so I cannot test with each role having their own machine.)

I have been reading through Ansible documentation such as Group vars doc but have not found answer to this.

Madoc Comadrin
  • 570
  • 4
  • 11
  • 29

1 Answers1

1

Are group_vars supposed to work like this?

Yes.

Is this maybe caused by the fact that I install roles on the same host?

Yes. Facts are bound to hosts, not groups.

This also means that the same variable values defined in multiple group_vars will get overwritten.

techraf
  • 4,243
  • 8
  • 29
  • 44