On Mon, 17 Feb 2020 20:11:07 +0000
Nuno Jordão <[email protected]> wrote:

>     - name: "test loop"
>       debug:
>         msg: "test"
>       loop: "{{nulo}}"
>       when: nulo is defined
> 
> where "nulo" is an undefined variable. Here the task skips instead of
> failing.

Instead of testing whether the variable is defined or not, use the "default"
filter. For example

     - name: "test loop"
       debug:
         msg: "test"
       loop: "{{ nulo|default([]) }}"

The loop will be skipped if "nulo" is undefined. Test "nulo" separately if
you want the playbook to fail. For example

     - name: Fail when nulo undefined
       fail:
         msg: "Variable nulo undefined"
       when: nulo if undefined

HTH,

        -vlado

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200217220957.7d57397e%40gmail.com.

Attachment: pgpRQyYbXP7hV.pgp
Description: OpenPGP digital signature

Reply via email to