Re: [ansible-project] Conditional with dict2item is falied

2020-06-15 Thread Stefan Hornburg (Racke)
On 6/15/20 9:39 PM, Rafael Tomelin wrote:
> 
> Hi guys,
> 
> I have a task with equal below, but when I validate it is defined it not 
> recognized.
> - name: include vars virtual_machine
> include_tasks: virtual_machine.yml
> when:
> - gms_az_vm_action == 'create_virtual_machine'
> - virtual_machine is defined
> loop: "{{ virtual_machine|dict2items }}"
> 
> 
> 
> How I do for doesn't read loop and not stop playbook when virtual_machine not 
> defined?

  loop: "{{ virtual_machine | default({}) | dict2items }}"

This produces an empty dict ({}) if virtual_machine is undefined and the loop 
goes over zero iterations.

Regards
Racke

> 
> -- 
> Atenciosamente,
> 
> Rafael Tomelin
> Tel.: 51-984104084
> Skype: rafael.tomelin
> 
> LPI ID: LPI000191271
> Red Hat Certified Engineer
> Puppet Professional 2017 Certification
> 
> -- 
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAGEUqbAv4tEJoSWWU7TR9YP3x%2B5BzVDO6NmS7rZCGYhEHN_ocg%40mail.gmail.com
> .


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e75a094d-15de-600d-dbc0-22b5dc8ab93f%40linuxia.de.


signature.asc
Description: OpenPGP digital signature


Re: [ansible-project] Conditional with dict2item is falied

2020-06-15 Thread Rafael Tomelin
OK, thanks!

On Mon, Jun 15, 2020 at 4:42 PM Matt Martz  wrote:

> In the case of using `when` and `loop`, the `when` statements is applied
> to each iteration of the `loop`, and not before it.
>
> As such, you cannot prevent a loop from happening using a when statement.
>
> Instead you want to do this in loop, like:
>
> loop: '{{ virtual_machine|default({})|dict2items }}'
>
> On Mon, Jun 15, 2020 at 2:39 PM Rafael Tomelin 
> wrote:
>
>>
>> Hi guys,
>>
>> I have a task with equal below, but when I validate it is defined it not
>> recognized.
>> - name: include vars virtual_machine
>> include_tasks: virtual_machine.yml
>> when:
>> - gms_az_vm_action == 'create_virtual_machine'
>> - virtual_machine is defined
>> loop: "{{ virtual_machine|dict2items }}"
>>
>>
>>
>> How I do for doesn't read loop and not stop playbook when virtual_machine
>> not defined?
>>
>> --
>> Atenciosamente,
>>
>> Rafael Tomelin
>> Tel.: 51-984104084
>> Skype: rafael.tomelin
>>
>> LPI ID: LPI000191271
>> Red Hat Certified Engineer
>> Puppet Professional 2017 Certification
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/CAGEUqbAv4tEJoSWWU7TR9YP3x%2B5BzVDO6NmS7rZCGYhEHN_ocg%40mail.gmail.com
>> 
>> .
>>
>
>
> --
> Matt Martz
> @sivel
> sivel.net
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAD8N0v_A15vdx3waWE%3DH5ztveN-W6MdNz%2BP_WGAFOpEbRsFprg%40mail.gmail.com
> 
> .
>


-- 
Atenciosamente,

Rafael Tomelin
Tel.: 51-984104084
Skype: rafael.tomelin

LPI ID: LPI000191271
Red Hat Certified Engineer
Puppet Professional 2017 Certification

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


Re: [ansible-project] Conditional with dict2item is falied

2020-06-15 Thread Matt Martz
In the case of using `when` and `loop`, the `when` statements is applied to
each iteration of the `loop`, and not before it.

As such, you cannot prevent a loop from happening using a when statement.

Instead you want to do this in loop, like:

loop: '{{ virtual_machine|default({})|dict2items }}'

On Mon, Jun 15, 2020 at 2:39 PM Rafael Tomelin 
wrote:

>
> Hi guys,
>
> I have a task with equal below, but when I validate it is defined it not
> recognized.
> - name: include vars virtual_machine
> include_tasks: virtual_machine.yml
> when:
> - gms_az_vm_action == 'create_virtual_machine'
> - virtual_machine is defined
> loop: "{{ virtual_machine|dict2items }}"
>
>
>
> How I do for doesn't read loop and not stop playbook when virtual_machine
> not defined?
>
> --
> Atenciosamente,
>
> Rafael Tomelin
> Tel.: 51-984104084
> Skype: rafael.tomelin
>
> LPI ID: LPI000191271
> Red Hat Certified Engineer
> Puppet Professional 2017 Certification
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAGEUqbAv4tEJoSWWU7TR9YP3x%2B5BzVDO6NmS7rZCGYhEHN_ocg%40mail.gmail.com
> 
> .
>


-- 
Matt Martz
@sivel
sivel.net

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v_A15vdx3waWE%3DH5ztveN-W6MdNz%2BP_WGAFOpEbRsFprg%40mail.gmail.com.


[ansible-project] Conditional with dict2item is falied

2020-06-15 Thread Rafael Tomelin
Hi guys,

I have a task with equal below, but when I validate it is defined it not
recognized.
- name: include vars virtual_machine
include_tasks: virtual_machine.yml
when:
- gms_az_vm_action == 'create_virtual_machine'
- virtual_machine is defined
loop: "{{ virtual_machine|dict2items }}"



How I do for doesn't read loop and not stop playbook when virtual_machine
not defined?

-- 
Atenciosamente,

Rafael Tomelin
Tel.: 51-984104084
Skype: rafael.tomelin

LPI ID: LPI000191271
Red Hat Certified Engineer
Puppet Professional 2017 Certification

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