With a simple list, you can do stuff like:

- shell: echo {{ item }}
  with_items: alist_that_may_be_undefined | default([])

Which will iterate over a list of 0 if there is nothing in it.

What you might wish to do is set users by default to an empty array
(perhaps in roles/foo/defaults.yml) or something similar, to ensure it
always has a value.




On Wed, Aug 20, 2014 at 4:46 AM, Nakai Tooru <[email protected]> wrote:

> Hello,
>
> Is it possible to skip a task with_subelements if its dictionary is
> undefined?
>
> For example,
>
> - authorized_key: "user={{ item.0.name }} key='{{ lookup('file',
> item.1)}}'"
>   with_subelements:
>     - users
>     - authorized
>   when: users is defined
>
> This is failed with;
> fatal: [localhost] => subelements lookup expects a dictionary, got 'users'.
>
> It seems with_subelements evaluate the action before check condition.
>
> Thanks
>
> --
> nakai
>
> --
> 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/eaf43b5b-dc5a-4387-8bcd-6bf9b8d2be10%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/eaf43b5b-dc5a-4387-8bcd-6bf9b8d2be10%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/CA%2BnsWgyX-OX-cxXp1Amsz9SFA5d5giY2qKr0jddmzTM8VDS8gA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to