How to continue execution on failed task after fixing error in playbook?

前端 未结 3 758
-上瘾入骨i
-上瘾入骨i 2021-01-31 01:23

When writing and debugging Ansible playbooks, typical workflow is as follows:

  1. ansible-playbook ./main.yaml
  2. Playbook fails on some task
  3. <
3条回答
  •  终归单人心
    2021-01-31 02:16

    Future Future readers:

    As of Ansible 2.4.2.0 --start-at-task works for tasks defined in roles I created.

    The ansible team is not willing to address this issue they suggest you keep your roles idempotent and replay the entire play, I don't have time for this. In my roles I am not using a massive amount of facts like @JeremyWhiting, so for me I can use this --start-at-task feature.

    Still however, this is a manual task so instead I wrote some ansible rpm and added a "Resume" feature that follows these basic steps:

    • Enable the ansible log via /etc/ansible/ansible.cfg (uncomment log_path)
    • Clear the log before each run
    • After a failure, the "Resume" feature greps this log for the last "TASK" line, and uses sed to get what is inside the "[]"
    • Then it simply calls the last run play, with --start-at-task="$start_at_task"
    • Ensure that you have "any_errors_fatal: true" in your roles to stop the play at the failing task you wish to resume from

    The ansible team is unwilling to create this basic (and very useful) feature so the only choice is to hack it together via some bash scripts.

提交回复
热议问题