I don't like suggesting anyone should ever need set_fact, except in cases
where it's occasionally needed to multiply a variable or something, as in
most cases Ansible lazy-evaluates variables, and in most cases those
expressions can just be written in the "vars" section.

I'd do this:

  with_dict: defgensrc | default({})

In this case, the dict is empty when it has no value, which means the
statement is skipped.




On Wed, May 28, 2014 at 8:01 AM, James Cammarata <[email protected]>wrote:

> You migh want to use set_fact on the hosts, when the dict is not defined,
> to give it some default value instead. As you've noticed, the "when" clause
> is applied to each item in the loop, so it's evaluated after the with_dict
> is parsed.
>
>
> On Tue, May 27, 2014 at 2:25 PM, Heath Henjum <[email protected]> wrote:
>
>> Hi,
>>
>> I have a task defined as follows:
>>
>> - name: copy defgen paramfile
>>   template: src={{ item.key }}.prm.j2 dest={{ ogg_home }}/{{
>> item.value.pfileloc }}/{{ item.key }}.prm backup=yes
>>   when: defgensrc is defined and oggaction == 'defgensrc'
>>   with_dict: defgensrc
>>
>> It is operating on two hosts in a group,  but one of the hosts does not
>> have the dictionary defgensrc defined.
>>
>> So,  I get this error:
>>
>> fatal: [mn-ldvora01.rxhub.net] => with_dict expects a dict
>>
>>
>> Is there a way to conditionally skip this task when the dictionary is not
>> defined,
>>
>> or would it be better to further refine my groups so that the host that
>> is a "defgensrc" is in a specific child group and the one that is not a
>> "defgensrc"
>>
>> The two hosts are defined in a group called [mn-ogg]  because they are
>> both oracle golden gate servers,  but one is the source of "defgen" and the
>> other is the destination of the results of "defgen".
>> (not that you probably need to know the details of all that)
>>
>> Thanks in advance,
>> Heath Henjum
>>
>>  --
>> 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/38518aa4-a610-48c3-ae40-7f356e19e399%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/38518aa4-a610-48c3-ae40-7f356e19e399%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/CAMFyvFg5bBgh4uEVBU4Tq87g4qpJPQaTW0rjeqh1ajQ9TdAj%3Dg%40mail.gmail.com<https://groups.google.com/d/msgid/ansible-project/CAMFyvFg5bBgh4uEVBU4Tq87g4qpJPQaTW0rjeqh1ajQ9TdAj%3Dg%40mail.gmail.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/CA%2BnsWgwMHOnm1xOUgH6qLdB%3DcKBPKQ13vkTiZpaimdxLN9U2%3DQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to