Another case, which isn't related to extra_vars but to the root cause 
(according to my best guess) of evaluating the variables expressions too 
early:

inventory:
localhost ansible_connection=local
[all:vars]
var=value

Playbook:
---
- hosts: localhost
  gather_facts: no
  vars:
    var2: "{{ var  | default('none') }}"
  tasks:
    - debug: var=var
    - debug: var=var2

Output:
TASK: [debug var=var] 
********************************************************* 
ok: [localhost] => {
    "var": "value"
}

TASK: [debug var=var2] 
******************************************************** 
ok: [localhost] => {
    "var2": "none"
}


On Tuesday, October 7, 2014 10:50:13 AM UTC+3, Hagai Kariti wrote:
>
> Hi
>
> I hope this is the right place to post this. I reported 
> https://github.com/ansible/ansible/issues/9242 a few days ago and I still 
> have issues after it was closed. I'll give a similar example to the one I 
> gave in the issue, but using vars_files and adding one more usecase:
>
> inventory:
>
> localhost ansible_connection=local
> [all:vars]
> var=one
>
>
> vars_file:
>
> var2: "{{var}}"
>
> mapping:
>   one: 1
>   two: 2
>
> playbook:
>
> ---
> - hosts: localhost
>   gather_facts: no
>   vars_files:
>     - vars_file
>   vars:
>     value: "{{mapping[var]}}"
>   tasks:
>     - debug: var=var
>     - debug: var=var2
>     - debug: var=value
>
>
> command:
>
>     ansible-playbook -i inventory playbook.yml -e var=two
>
> output:
>
> TASK: [debug var=var] 
> ********************************************************* 
> ok: [localhost] => {
>     "var": "two"
> }
>
> TASK: [debug var=var2] 
> ******************************************************** 
> ok: [localhost] => {
>     "var2": "one"
> }
>
> TASK: [debug var=value] 
> ******************************************************* 
> ok: [localhost] => {
>     "value": "1"
> }
>
> In older versions (1.5.5 is the one I test with), the third (mapping) 
> usecase is working properly, but the second does not. In the latest dev, 
> both don't work 
>
> Thanks!
>

-- 
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/dac219aa-4eb0-4ccc-8843-eb8aeeb5ea9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to