retries/loop for a bunch of tasks

25 views
Skip to first unread message

Azadeh Amirhosseini

unread,
Apr 3, 2024, 8:36:54 AM4/3/24
to Ansible Project
Hi All,

how can I implement 'retries:' for a bunch of tasks. Unfortunately  it does not work with 'block:' and i get the error: 'ERROR! 'until' is not a valid attribute for a block'. Any idea or trick to get the result is highly welocomed.

tasks:
- name: "execute show commands before Update"
nxos_command:
commands: "{{ item }}"
ignore_errors: true
with_items: "{{ todo }}"
register: before_install

- set_fact:
out_before: "{{ out_before + [item.item] + item.stdout }}"
with_items: "{{ before_install.results }}"

# more tasks come here to do the Software Update...

- name: "Check Output after update"
block:
- name: "execute show commands after Update"
nxos_command:
commands: "{{ item }}"
ignore_errors: true
with_items: "{{ todo2 }}"
register: after_install

- set_fact:
error_data: "{{ 'false' if before_install == after_install else 'true'}}"

retries: 3
delay: 300
until: error_data == 'false'

Dick Visser

unread,
Apr 3, 2024, 9:21:17 AM4/3/24
to ansible...@googlegroups.com
You could put the tasks from the block in a separate file, and then
include that with include_tasks.
That does allow you to loop over it.
> --
> 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.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2ab45753-43fe-431e-8ed4-891dde801db8n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages