# Confused about variable precedence

**URL:** <https://forum.ansible.com/t/confused-about-variable-precedence/15427>\
**Category:** Ansible Project\
**Created:** [June 9, 2014, 3:22am UTC](https://forum.ansible.com/t/confused-about-variable-precedence/15427 "2014-06-09T03:22:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_Hurrell](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Greg\_Hurrell](https://forum.ansible.com/u/Greg_Hurrell)\
**Post date:** [June 9, 2014, 3:22am UTC](https://forum.ansible.com/t/confused-about-variable-precedence/15427/1 "2014-06-09T03:22:06Z")

</div>

Hi,

I had a playbook that I _think_ used to work, but I’m finding now that variables other than the ones I intended are being applied to a particular host. Does the following minimal test case look sane?

I have vars file at roles/mariadb/vars/credentials.yml with some default settings:

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [June 9, 2014, 2:29pm UTC](https://forum.ansible.com/t/confused-about-variable-precedence/15427/2 "2014-06-09T14:29:13Z")

</div>

You should not be using vars files from inside roles as vars\_files entries. If you want easily overridden variables put them in defaults/main.yml and then override them either via role parameters or inventory variables (like host\_vars and group\_vars).

---

<div class="post-metadata">

**Author:** ![Greg\_Hurrell](https://avatars.discourse-cdn.com/v4/letter/g/76d3ee/32.png) [@Greg\_Hurrell](https://forum.ansible.com/u/Greg_Hurrell)\
**Post date:** [June 9, 2014, 3:21pm UTC](https://forum.ansible.com/t/confused-about-variable-precedence/15427/3 "2014-06-09T15:21:16Z")

</div>

Thanks James. I’ve re-jigged it as you describe and things are working nicely.

-Greg
