I’ve been playing with Ansible recently, and enjoying automating my server installs, after years of relying on home-made scripts (or worse).
From time to time I need to find out why Ansible isn’t doing what I think it should be, and after using -vvvv verbose flag, my next step is running the generated ansible installation script manually on the server. I didn’t find this explained anywhere, so I’m documenting it here for future reference.
First, run your ansible-playbook command on your local machine, setting the ANSIBLE_KEEP_REMOTE_FILES variable :
$ ANSIBLE_KEEP_REMOTE_FILES=1 ansible-playbook playbook.yml --ask-sudo-pass -vvvv
Make a note of the name of the file ansible copied to your server (it should be in your home directory, in .ansible/tmp/ansible-tmp-XXXXXXXXXXXX/ ) , then on the target machine (you should be doing this in your test environment or in a vagrant virtual machine), run the command using the python debugger :
$ pdb ~/.ansible/tmp/ansible-tmp-XXXXXXXXXXXX/command
You can step through the command file to see what Ansible is really doing. First step is to break at main() :
(Pdb) b main
then step through the code until it breaks