[ansible-project] Re: Variable undefined after set_fact

2016-12-01 Thread thokari81

>
>
> - set_fact: var2 = "something"
>   when: var2 is not defined
>
> - set_fact: var3 = "something"
>   when: var3 is not defined
>

Try this without spaces around the '=' . 

-- 
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 ansible-project+unsubscr...@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/5b4b1de6-1a47-4c10-bd4d-609f37f130fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Variable undefined after set_fact

2014-06-06 Thread Nathan Robertson
So I found part of the problem.

First the set_fact only seemed to work when using the second format in the 
documentation

- set_fact: 
 var2: something
  when: var2 is not defined

second I found that if the set_fact runs in a role once and you run that 
role multiple times with different variable the set_fact will hold over 
until it is run at that level again.

For example:


roles:
- { role: test_role, var1: 'some string', var2: {{ some_var }} }
- { role: test_role, var1: 'some string', var2: {{ some_var }}, var3: 
{{ some_var2 }} }
 

In the first run var3 gets set to 'something'
on the second run even thought I tell it to set var3 to {{some_var2}} it 
seems to remember that at that level it was previously set to 'something' 
and that local setting takes president as if it was set that time around as 
well (even though it isn't)  


On Friday, June 6, 2014 9:43:25 AM UTC-7, Nathan Robertson wrote:

 I am either missing something simple or ran into a bug.

 I have a playbook that passes variable to a role as follows:


   roles:
 - { role: test_role, var1: 'some string', var2: {{ some_var }}, 
 var3: {{ some_var2 }} }


 Now both some_var and some_var2 are set (verified with a debug before 
 this)  

 in the role I have the following:

 - set_fact: var2 = something
   when: var2 is not defined

 - set_fact: var3 = something
   when: var3 is not defined

 - debug: msg=' {{ var3 is not defined }} '

 - debug: msg='{{ var2 }}  {{ var3 }}'


 Now the output is as follows

 TASK: [test_role | set_fact var2 = something] ***
 skipping: [10.0.0.1]

 TASK: [test_role | set_fact var3 = something] ***
 ok: [10.0.0.1]

 TASK: [test_role | debug msg=' True '] 
 ***
 ok: [10.0.0.1] = {
 item: ,
 msg:  True 
 }

 TASK: [test_role | debug msg='{{var2}} {{var3}}'] 
 fatal: [10.0.0.1] = One or more undefined variables: 'var3' is undefined

 So as you can see the var2 is passed through and is defined and so the 
 set_fact is skipped. 
 But var3 is not passed so the set_fact runs but it is still undefined 
 afterwards.

 I have tried changing the order of the variables in the playbook, renaming 
 the variable and I always get the same problem.  Anyone know what I'm 
 missing?  

 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 ansible-project+unsubscr...@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/21313b03-58b7-4151-a714-e93ba6c8ef30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.