# Variable in role not overriden by inventory

**URL:** <https://forum.ansible.com/t/variable-in-role-not-overriden-by-inventory/26222>\
**Category:** Ansible Project\
**Created:** [December 7, 2017, 6:15pm UTC](https://forum.ansible.com/t/variable-in-role-not-overriden-by-inventory/26222 "2017-12-07T18:15:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thibaud\_LEBRET](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@Thibaud\_LEBRET](https://forum.ansible.com/u/Thibaud_LEBRET)\
**Post date:** [December 7, 2017, 6:15pm UTC](https://forum.ansible.com/t/variable-in-role-not-overriden-by-inventory/26222/1 "2017-12-07T18:15:51Z")

</div>

Hello

I have the following directory and I run ansible 2.4.1.0 with python 2.7 , on Redhat 6/7 server

inventories/  
production/  
hosts.prod # inventory file  
group\_vars/  
all  
host\_vars/

dev/  
hosts.dev # inventory file  
group\_vars/  
all  
host\_vars/  
stagehost1  
stagehost2

roles/  
common\_configuration  
tasks/  
main.yml  
vars/  
main.yml

playbook/  
all.yml

for the role common\_configuration

my task is

- name: set timezone , default to Europe/verlin but can be override by inventory  
timezone:  
name: “{{ timezone }}”  
notify:
- restart crond

and my variable in the role is  
timezone: Europe/verlin

( I konw this value is not a legit timezone but it’s for testing purpose)

In my dev inventory, I set in all.yml the variable with a different string.

timezone: Europe/Paris

Here how I call my playbook

ansible-playbook -u lebrett-adm -k --become -i /etc/ansible/inventories/dev/hosts.dev playbook/all.yml --limit matching

As far I understand variable precedence , role variable should be overriden by inventory . But in my case , it stay with role variable.

TASK [common\_configuration : set timezone , default to Europe/Paris but can be override by inventory] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [srvamsdev-mat02]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “Error message:\ngiven timezone "Europe/verlin" is not available”}  
fatal: [srvamsdev-mat01]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “Error message:\ngiven timezone "Europe/verlin" is not available”}  
to retry, use: --limit @/etc/ansible/playbook/all.retry

For testing, I have deleted variable in role and ansible use variable in my dev inventory.

Am i doing something wrong ?

Regards

Thibaud LEBRET

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 7, 2017, 6:36pm UTC](https://forum.ansible.com/t/variable-in-role-not-overriden-by-inventory/26222/2 "2017-12-07T18:36:53Z")

</div>

Not if it's the variables is in vars directory, they have very high priority[1].

If you have them in default is it will have the lowest priority and you can overwrite them everywhere.

[1] [http://docs.ansible.com/ansible/latest/playbooks\_variables.html#variable-precedence-where-should-i-put-a-variable](http://docs.ansible.com/ansible/latest/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable)

---

<div class="post-metadata">

**Author:** ![Thibaud\_LEBRET](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@Thibaud\_LEBRET](https://forum.ansible.com/u/Thibaud_LEBRET)\
**Post date:** [December 7, 2017, 8:28pm UTC](https://forum.ansible.com/t/variable-in-role-not-overriden-by-inventory/26222/3 "2017-12-07T20:28:28Z")

</div>

I will try again tomorow but I understant my mistake.

---

<div class="post-metadata">

**Author:** ![Thibaud\_LEBRET](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@Thibaud\_LEBRET](https://forum.ansible.com/u/Thibaud_LEBRET)\
**Post date:** [December 7, 2017, 8:30pm UTC](https://forum.ansible.com/t/variable-in-role-not-overriden-by-inventory/26222/4 "2017-12-07T20:30:37Z")

</div>

I understand ,

I read too quickly the first time.

Thanks for the reply.
