Hi,

I'm confused with variable precedence of Ansible 2.0 documented 
in 
http://docs.ansible.com/ansible/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable
 
.  Suppose I have playbooks and roles as follows:

hosts (inventory):
[default]
localhost x=1

roles/a/tasks/main.yml (task in role a):
---
- set_fact:
    x: '{{ x + 1 }}'

roles/b/tasks/main.yml (task in role b):
---
- debug:
    var: x

tasks.yml (playbook):
---
- hosts: all
  gather_facts: no
  tasks:
    - include: roles/a/tasks/main.yml
      vars:
        x: 10
    - include: roles/b/tasks/main.yml
    - include: roles/b/tasks/main.yml
      vars:
        x: 20

roles.yml (playbook):
---
- hosts: all
  gather_facts: no
  roles:
    - role: a
      x: 10
    - role: b
    - role: b
      x: 20

With Ansible 2.0.1.0 those two playbooks show diffrent results in the last 
debug task:
$ ansible-playbook -i hosts tasks.yml 

PLAY 
***************************************************************************

TASK [include] 
*****************************************************************
included: /home/yaegashi/tmp/test/roles/a/tasks/main.yml for localhost

TASK [set_fact] 
****************************************************************
ok: [localhost]

TASK [include] 
*****************************************************************
included: /home/yaegashi/tmp/test/roles/b/tasks/main.yml for localhost

TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "x": "11"
}

TASK [include] 
*****************************************************************
included: /home/yaegashi/tmp/test/roles/b/tasks/main.yml for localhost

TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "x": 20
}

PLAY RECAP 
*********************************************************************
localhost                  : ok=6    changed=0    unreachable=0    failed=0 
  

$ ansible-playbook -i hosts roles.yml 

PLAY 
***************************************************************************

TASK [a : set_fact] 
************************************************************
ok: [localhost]

TASK [b : debug] 
***************************************************************
ok: [localhost] => {
    "x": "11"
}

TASK [b : debug] 
***************************************************************
ok: [localhost] => {
    "x": "11"
}

PLAY RECAP 
*********************************************************************
localhost                  : ok=3    changed=0    unreachable=0    failed=0 
  

While include vars can override vars by set_fact, role variable can't.  Is 
that an expected behavior?
What prcedences are actually given to vars passed by role/include calls 
respectively?
My first thought was both of them are "role and include vars" in the 
precedence list in the document.

Regards,
-- 
YAEGASHI Takeshi <[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a325f3a6-0037-4c00-8d2a-46f3ebccb85e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to