Using ignore_errors : yes in loop

5 views
Skip to first unread message

Rahul Kumar

unread,
Dec 10, 2019, 2:57:23 AM12/10/19
to ansible...@googlegroups.com
Hi Dick and Ansible gurus,
I want to continue to other items of loop even if any of the item is failed in loop(probably we did not define that item and because of that - item failed, in that case it should continue to remaining items). How can we use ignore_errors:yes which applies to all items in loop.
Below is snippet :
 name: Application Configuration
  uri:
    url: http://{{ my_ip | default(ansible_fqdn) }}:{{8080 + (instance_id | int -1)*100}}/my-config/rest/{{item.resource}}
    body_format: json
    method: PUT
    body: "{{item.name}}"
    user: "{{ app_user }}"
    password: "{{ api_password }}"
    force_basic_auth: true
    follow_redirects: all
  with_items:
    - { name: '{{item1cfg}}', resource: 'item1' }
    - { name: '{{item2cfg}}', resource: 'item2' }
    - { name: '{{item3cfg}}', resource: 'item3' }
  when: item1cfg is defined or item2cfg is defined or item3cfg is defined
  ignore_errors: yes 

Rahul

Stefan Hornburg (Racke)

unread,
Dec 10, 2019, 3:08:40 AM12/10/19
to ansible...@googlegroups.com
On 12/10/19 8:56 AM, Rahul Kumar wrote:
> Hi Dick and Ansible gurus,
> I want to continue to other items of loop even if any of the item is failed in loop(probably we did not define that item
> and because of that - item failed, in that case it should continue to remaining items). How can we use ignore_errors:yes
> which applies to all items in loop.
> Below is snippet :
>  name: Application Configuration
>   uri:
>     url: http://{{ my_ip | default(ansible_fqdn) }}:{{8080 + (instance_id | int -1)*100}}/my-config/rest/{{item.resource}}
>     body_format: json
>     method: PUT
>     body: "{{item.name <http://item.name>}}"
>     user: "{{ app_user }}"
>     password: "{{ api_password }}"
>     force_basic_auth: true
>     follow_redirects: all
>   with_items:
>     - { name: '{{item1cfg}}', resource: 'item1' }
>     - { name: '{{item2cfg}}', resource: 'item2' }
>     - { name: '{{item3cfg}}', resource: 'item3' }
>   when: item1cfg is defined or item2cfg is defined or item3cfg is defined
>   ignore_errors: yes 
>
> Rahul
>

This doesn't make much sense to me ... you should know which items exists.

But try failed_when: ... this will be applied for every item in the loop.

Regards
Racke

> --
> 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-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAGH8rEwi%3DSAOTWHw1MnNHAbpqa0_8wUsaxQCEHU%3DKa%3DBM9gB5Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAGH8rEwi%3DSAOTWHw1MnNHAbpqa0_8wUsaxQCEHU%3DKa%3DBM9gB5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>.


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

signature.asc
Reply all
Reply to author
Forward
0 new messages