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.
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 .
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 .
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.
The most basic way is to run ansible / ansible-playbook with an increased verbosity level by adding -vvv to the execution line.
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
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"
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With