There is quite a simple setup I am sure many of us have come across:

  1. You have lean, slim and dedicate roles
  2. Every role has its own role vars
  3. Playbooks include the roles

Let's assume you have a base path for an application, most likely you will need this path in many roles. To keep the roles independent you would define this base path in every role vars where needed.

Now you include some roles in a Playbook and in case of a change on e.g. the base path you need to change that in every role.

One help would be to use extra vars to overrule the role vars, but what if there are many potential candidates for a change?

So I would like to be able to include_vars in a playbook to overrule the variables in the roles. But this is not possible as:

  1. include_vars is not allowed in Playbooks
  2. var_files (what would work in Playbooks) will be over written by role vars

Question: how do you do solve this situation? Maybe I want something odd and there is a much simpler way?

2 Answers 2


Variables have different priorities, see vars precedence.

As of Ansible 2.x:

role defaults
inventory file or script group vars
inventory group_vars/all
playbook group_vars/all
inventory group_vars/*
playbook group_vars/*
inventory file or script host vars
inventory host_vars/*
playbook host_vars/*
host facts
play vars
play vars_prompt
play vars_files
role vars (defined in role/vars/main.yml)
block vars (only for tasks in block)
task vars (only for the task)
role (and include_role) params
include params
set_facts / registered vars
extra vars (always win precedence)

For roles you would generally use myrole/defaults/main.yml for easily overridable vars (e.g. installation path or smth) and use myrole/vars/main.yml for vars that you don't want to be easily overridden (smth like required packages).


I missed one point which provides the answer: role defaults are the lowest in precedence. So just these vars and file_vars can overwrite in the playbook.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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