Variable in role not overriden by inventory

39 views
Skip to first unread message

TibZ

unread,
Dec 7, 2017, 1:15:52 PM12/7/17
to Ansible Project
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

Kai Stian Olstad

unread,
Dec 7, 2017, 1:37:16 PM12/7/17
to ansible...@googlegroups.com
On 07.12.2017 19:15, TibZ wrote:
> As far I understand variable precedence , role variable should be
> overriden by inventory . But in my case , it stay with role variable.

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


--
Kai Stian Olstad

Thibaud LEBRET

unread,
Dec 7, 2017, 3:29:06 PM12/7/17
to ansible...@googlegroups.com


I will try again tomorow but I understant my mistake.



--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/dinO7NvRL34/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e294d5c68a9fe24ebc4b5cc02e996e63%40olstad.com.

For more options, visit https://groups.google.com/d/optout.

Thibaud LEBRET

unread,
Dec 7, 2017, 3:31:11 PM12/7/17
to ansible...@googlegroups.com
I understand ,

I read too quickly the first time.

Thanks for the reply.
On 7 December 2017 at 19:36, Kai Stian Olstad <ansible-pr...@olstad.com> wrote:
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/dinO7NvRL34/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages