7

I would like to run my ansible playbook against a remote test machine, but as way of testing I'd like to verify between each step that what I expected to be done was done.

I'd like to add, more or less, a "pause" task after every task command, but without actually putting it into my yaml script. Does ansible have any sort of 'debug' mode that would allow for this?

I'm using ansible 1.5, but am open to answers that use features in newer versions.

Mitch
  • 1,514
  • 4
  • 15
  • 34

3 Answers3

5

Yes, ansible has a "step" mode, which will make it to pause before every task and wait for user confirmation to execute the task.

Simply call your playbook with the step flag:

ansible-playbook ... --step
udondan
  • 52,841
  • 19
  • 186
  • 168
  • While the other answers are good in their own right, this is the correct answer. Thanks! – Mitch Feb 02 '16 at 15:22
4

start-at-task

To gain time, you can use --start-at-task to execute only the last comands which are probably those who are bugging. But for that you have to name your task :

This shell task has no name

- shell: vagrant provision; vagrant up;
  args:
    chdir: /vm/vagrant

This one does :

- name: start vagrant
  shell: vagrant provision; vagrant up;
  args:
    chdir: /vm/vagrant

then run :

ansible-playbook playbook.yml --start-at-task="start vagrant" 

tags

Another helpful tip is to use tags. For exemple you want to try only one command

- shell: vagrant provision; vagrant up;
  args:
    chdir: /linux/{{item.name}}
  tags: [shell, debug]

Now you can debug this one doing :

ansible-playbook playbook.yml --tags="debug"

And it will start only tasks that received the tag debug.

Verbose

And if you want more informations, you can ask Ansible to be more verbose using -v, -vv, -vvv or -vvvvv

ansible-playbook -vvvv playbook.yml --tags="debug"

This will tell you all it can on the specified task

Nicolas Zozol
  • 6,855
  • 3
  • 48
  • 67
  • `start-at-task` is very useful. Tags is also useful but annoying to have to edit it in – Mitch Feb 02 '16 at 17:26
  • The point of the *debug* tag is to execute only one step, which is exactly not the goal of Ansible, so yes, it needs some attention. – Nicolas Zozol Feb 07 '16 at 21:36
3

I do not think ansible provides a feature like that. One way to do this is put a pause between plays and make it conditional. When you execute the playbook, define a variable which decides whether to pause or not.

- pause:
  when: PAUSE is defined

When you execute the playbook, don't define PAUSE if you don't want to pause. But if you want to pause between plays, then define it.

ansible-playbook -v .... --extra-vars "PAUSE=yes" ... myplay.yml
helloV
  • 46,329
  • 4
  • 117
  • 135