20

Say I'm debugging an Ansible playbook and want to quit after a given task (and not run through all of the following tasks). Is there any one-line magic command available, or do I have to manually create an exit/assert task?

From the ansible-playbook manual, I see that there is a --start-at-task=START_AT flag, but I don't see anything like an 'end-at' counterpart.

3 Answers 3

21

Using - pause: might suit.

Pauses playbook execution for a set amount of time, or until a prompt is acknowledged. All parameters are optional. The default behavior is to pause with a prompt. You can use ctrl+c if you wish to advance a pause earlier than it is set to expire or if you need to abort a playbook run entirely. To continue early: press ctrl+c and then c. To abort a playbook: press ctrl+c and then a.

http://docs.ansible.com/pause_module.html

Or just a straight - fail: if you will certainly not want to continue.

If you want a block of tasks to execute, you can use tags and --with-tags:. Ansible v2 will have proper code blocks so you can use a single when: for multiple tasks.

27

- meta: end_play

end_play (added in 2.2) causes the play to end without failing the host.

2
  • 5
    This ends a play not a playbook. Nov 12, 2020 at 22:24
  • @BradSolomon what is the difference? Because for some reason, end_play has no effect in my playbook. Dec 10, 2022 at 21:53
7

ansible-playbook --step will let you confirm each task you want to run and stop execution whenever you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.