4

I'm trying to understand variable precedence in Ansible - more exactly the part about host_vars and group_vars in inventory or playbook. My layout looks like this:

production/
├── inventory (alfa, beta and gamma hosts)
├── group_vars/
│   └── all (foo=1)
└── host_vars/
    └── alfa (foo=2)
playbooks/
├── site.yml (debuging variable foo)
├── group_vars/
│   └── all (foo=10)
└── host_vars/
    └── beta (foo=20)

So I have three nodes (alfa, beta and gamma) and foo variable. When I start a play I get this result:

alfa's foo=2
beta's foo=20
gamma's foo=10

According to documentation the precedence should be following:

  1. inventory group_vars
  2. inventory host_vars
  3. playbook group_vars
  4. playbook host_vars

But my result looks like the precedence is following:

  1. inventory group_vars
  2. playbook group_vars
  3. inventory host_vars
  4. playbook host_vars

Did I misunderstand something? Or is it a mistake in documentation? I'm using Ansible 2.0.1.

2
  • Ansible 2.0.1. But with 1.9.3 it's same result. – Tangente Apr 8 '16 at 7:14
  • 3
    Seems like that this is an mistake in the documentation. There is an open issue for this. – Henrik Pingel Jul 26 '16 at 13:11
1

quoting @Henrik Pingel from the comments - as his comment is the correct answer to this question:

Seems like that this is an mistake in the documentation. There is an open issue for this. – Henrik Pingel Jul 26 '16 at 13:11

and this is pretty much deprecated as there's new ansible version 2.9 that fixed this behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.