I want to run 2 times the playbook1 that may fail using import_playbook.
- name: Run playbook twice with potential failure
ansible.builtin.import_playbook: playbook1.yml
retries: 2
delay: 10
register: result
until: result.rc == 0
However, there is no retries/dely/register/until attributes for import_playbook
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_playbook_module.html
ERROR! 'retries' is not a valid attribute for a PlaybookInclude
Any alternatives or workaround ?
Unfortunately, the
import_playbookmodule itself doesn't support theretries,delay,register, anduntilattributes as I know.However, you can achieve a similar effect you want by incorporating a
loopand error handling directly at yourplaybook1.ymllevel . Here's an example I do quickly of how you might structure it:Here, the
include_tasksmodule is used to includeplaybook1.yml, and aloopis added to run it twice(range(2)).The
registerattribute captures theresult, and theuntilattribute is used to retry if the result has a non-zero return code.The retries and delay attributes control the retry behavior.
I hope this helps you to achieve the desired behavior.