I'm having the same issue. How can we make this task check if the variable 
exists before looping ? If we can't use when here, what can we do ?

On Monday, October 20, 2014 at 5:02:25 PM UTC-4, Michael DeHaan wrote:
>
> The when is evaluated for each step in the loop, not before looping, which 
> is the source of confusion here.
>
> On Fri, Oct 17, 2014 at 6:04 AM, bshbg <[email protected] 
> <javascript:>> wrote:
>
>> I have the following two statements which have the same when part. The 
>> first one is skipped correctly but the second creates an error. It should 
>> be skipped also.
>>
>> - debug: var="{{ sites[env].restricted_areas }}"
>>   when: sites[env].restricted_areas is defined
>>  
>> - template: src="apache/site_credentials" dest="{{ 
>> apache_vhost_base_path }}/{{ sites[env].server_name }}/conf/{{ 
>> item.area.internal_name }}"
>>   with_items: sites[env].restricted_areas | list
>>   when: sites[env].restricted_areas is defined 
>>   tags: create
>>
>>
>>
>> result:
>>
>> TASK: [website | debug var="{{sites[env].restricted_areas}}"] 
>> *****************
>> skipping: [TSSDMZPORTAL002]
>>
>>
>> TASK: [website | template src="apache/site_credentials" dest=
>> "{{apache_vhost_base_path}}/{{sites[env].server_name}}/conf/{{item.area.internal_name}}"
>> ] ***
>> fatal: [TSSDMZPORTAL002] => with_items expects a list or a set
>>
>>
>> can someone help me?
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/eb330a83-d434-4d8f-8022-0f9acafff636%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/eb330a83-d434-4d8f-8022-0f9acafff636%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/e7586ace-55d4-495c-85b4-704d9047d76c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to