January 11, 2017 · ansible

debugging in an ansible environment

I was looking for a PDB sort of debugger for debugging custom ansible modules written in Python. This is when i bumped into this blog.

As recommended on the blog, I tried out epdb and it works great for debugging custom ansible modules written in python.

Installation:

pip install epdb

epdb: https://pypi.python.org/pypi/epdb

Usage:

Insert the below code works as a breakpoint. Insert this at the lines needing debug.

import epdb
epdb.serve()

Run ansible with --forks 1 option to avoid parallel threads

ansible-playbook -i inventory site.yml --forks 1

This run should hang when it hits the piece of code that has epdb.serve(). At this point run the below from another shell

python -c "import epdb; epdb.connect()"

This should get you to the epdb shell.
here on, things should look familiar to pdb.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket