Does any function have the ability to debug / pause?

I would like to run my downloadable book with a remote test machine, but as a way of testing, I would like to check between each step that what I expected to do was done.

I want to add more or less a “pause” task after each task command, but without actually entering it in my yaml script. Does ansible have some kind of "debugging" mode that would allow this?

I use ansible 1.5, but I am open to answers that use functions in newer versions.

+5
source share
3 answers

Yes, ansible has a "step" mode that will cause it to pause before each task and wait for user confirmation to complete the task.

Just call your game with the step flag:

ansible-playbook ... --step 
+3
source

start-up tasks

To get the time, you can use -start-at-task to execute only the latest commands, which are probably the ones that are listening. But for this you must name your task:

This shell task has no name

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

It does:

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

then do:

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

tags

Another good tip is to use tags. For example, 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:

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

And it will only launch tasks that received tag debugging.

Verbose

And if you need more information, you can ask Ansible to be more detailed using -v, -vv, -vvv or -vvvvv

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

This will tell you everything that can, for a given task.

+4
source

I do not think that ansible provides such a function. One way to do this is to pause between games and make it conditional. When you run a playbook, define a variable that decides whether to pause or not.

 - pause: when: PAUSE is defined 

When you run a playbook, do not define PAUSE unless you want to pause. But if you want to pause between games, define it.

 ansible-playbook -v .... --extra-vars "PAUSE=yes" ... myplay.yml 
+3
source

Source: https://habr.com/ru/post/1242025/


All Articles