I have a playbook similar to the one below which uses the base_acl variable. Let's pretend base_acl: "default_acl.j2. I have a host that I want to use a different base_acl value for. I've looked over the ansible precedence docs and don't see a way to do this other than using --extra-vars on the command line which I don't want to do.
I've tried defining base_acl in a host_vars file (should have higher precedence according to link above?) for the host in question, however the play still prints "playbook" for the variable value when run.
Is there a way to tell ansible to give host_vars precedence over playbook variables?
---
- hosts: all
gather_facts: no
vars:
base_acl : "playbook"
tasks:
- debug: msg="variable is {{ base_acl }}"
From the link you have referenced in your question:
So, since the highest number wins and that all host related entries (8 through 11) have a lower number than 12, your statement is actually wrong. The only correct assesment is that an extra var would always override everything.
There are actually many ways to achieve what you are looking for. But in your situation this is what I would do.
group_vars/all.yml
(either at inventory or playbook level):host_vars/<your_host>.yml
(either at inventory or playbook level):Note that the above will work as well to override the default value for a specific group in
group_vars/<your_group>.yml
(either at inventory or playbook level).