Skip to content

Instantly share code, notes, and snippets.

@Deepakkothandan
Last active September 2, 2020 22:33
Show Gist options
  • Save Deepakkothandan/daeb1ba8dc5b73d85ded03cb2a614e85 to your computer and use it in GitHub Desktop.
Save Deepakkothandan/daeb1ba8dc5b73d85ded03cb2a614e85 to your computer and use it in GitHub Desktop.
Debug ansible with vscode

Ansible VSCode Debugging

  1. VSCode version 1.23.1
  2. Create launch.json for python attach
  3. Make sure ptvsd version is 3.0.0 pip install ptvsd==3.0.0
{
    "name": "Python: Attach",
    "type": "python",
    "request": "attach",
    "localRoot": "${workspaceFolder}",
    "remoteRoot": "${workspaceFolder}",
    "port": 3000,
    "secret": "ansible",
    "host": "127.0.0.1"
}

Setting a breakpoint in ansible module

import ptvsd
ptvsd.enable_attach(secret="ansible", address = ('127.0.0.1', 3000))
ptvsd.wait_for_attach()
ptvsd.break_into_debugger()

Dot't forget to set ansible remote interpreter path (incase of localhost)

ansible all -i 'localhost,' -u username -c local -m homebrew -a "package=vim" -e "ansible_python_interpreter=/path/to/interpreter"

@rockaut
Copy link

rockaut commented Jul 11, 2020

For me this doesn't work as debugger is telling me it cant enter zip file. How you worked around this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment