Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ansible have any feature to allow for debugging/pausing?

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.

like image 303
Mitch Avatar asked Feb 01 '16 18:02

Mitch


People also ask

How do you pause in Ansible?

The default behavior is to pause with a prompt. To pause/wait/sleep per host, use the wait_for module. 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 .

How do I enable Ansible debugging?

Enabling the debugger as a strategy You can do this at the play level, in ansible. cfg, or with the environment variable ANSIBLE_STRATEGY=debug .

What is the use of debug in Ansible?

Ansible provides a debug module option that makes the tasks more manageable. It is a handy tool to figure out any problem areas. Ansible version 2.1 extended the debug module with a verbosity parameter that transforms it from a print line.

How do I run Ansible in verbose mode?

The most basic way is to run ansible / ansible-playbook with an increased verbosity level by adding -vvv to the execution line.


2 Answers

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
like image 117
udondan Avatar answered Dec 05 '22 04:12

udondan


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

like image 32
Nicolas Zozol Avatar answered Dec 05 '22 06:12

Nicolas Zozol