Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: rerun playbook from failed task

I am executing play-book on only one host.

My Current task execution flow is:
1) Executing task
2) If any of the task fails in between, clean up everything
3) Rerun from the beginning.

This does not sound very efficient. I want to create flow very much like this,

1) Executing task
2) Task failed ..
3) if we rerun the play-book, ansible should execute tasks from the failed task. It should not rerun from the beginning.

In attempt to do that I was trying to achieve that once task was failed, I was trying to execute play-book with "--limit", it throws following error.

root@centos:/etc/ansible# ansible-playbook stack.yml --limit -vvvv
ERROR: provided hosts list is empty

root@centos:/etc/ansible# cat /root/stack.retry
10.17.10.150

I am not sure is this the right way to rerun the play-book to achieve this work flow.

like image 834
tgcloud Avatar asked May 17 '16 11:05

tgcloud


1 Answers

Use the option --start-at-task=START_AT

This will start your playbook at the task matching the given name. In your case:

ansible-playbook stack.yml --start-at-task=START_AT

change "START_AT" with the name of the task you will start at.

The --limit option you have used is to limit the playbook to hosts matching the pattern and not limiting tasks

like image 69
Bent Blue Avatar answered Sep 27 '22 23:09

Bent Blue