# How to debug ansible action plugin

**URL:** <https://forum.ansible.com/t/how-to-debug-ansible-action-plugin/5288>\
**Category:** Get Help\
**Created:** [May 4, 2024, 7:16pm UTC](https://forum.ansible.com/t/how-to-debug-ansible-action-plugin/5288 "2024-05-04T19:16:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Ratliff](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/john_ratliff/32/3007_2.png) [@John\_Ratliff](https://forum.ansible.com/u/John_Ratliff)\
**Post date:** [May 4, 2024, 7:16pm UTC](https://forum.ansible.com/t/how-to-debug-ansible-action-plugin/5288/1 "2024-05-04T19:16:14Z")

</div>

I’d like to be able to debug a custom action plugin using VS Code. With a module, the module is created in the script and it calls exit\_json, so modules are pretty easy to get working in a debugger, but how would I do the same thing with a custom ActionPlugin?

How could I instantiate an ActionPlugin instance from main() in a python script?

Thanks

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [May 6, 2024, 8:29pm UTC](https://forum.ansible.com/t/how-to-debug-ansible-action-plugin/5288/2 "2024-05-06T20:29:46Z")

</div>

The simplest option is to create a breakpoint in your code and under the Python debugger run `ansible ... -m action_plugin`. You can also run it through ansible-playbook if you need some setup tasks first before you call your action plugin.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [May 6, 2024, 8:37pm UTC](https://forum.ansible.com/t/how-to-debug-ansible-action-plugin/5288/3 "2024-05-06T20:37:41Z")

</div>

With some more information you want something like the following launch configuration:

```json
{
    "name": "Python Debugger: Module",
    "type": "debugpy",
    "request": "launch",
    "module": "ansible",
    "args": [
        "adhoc",
        "localhost",
        "-m",
        "my_action",
        "--playbook-dir",
        "${workspaceFolder}"
    ]
}

```

In this case I’m running the `ansible` (adhoc) command through the Python module option. I’ve also set `--playbook-dir` so it loaded my custom action plugin based on the normal playbook loading rules. You can ignore that if you are loading your action plugin in another way.

When running Ansible will run as normal but will top at your breakpoint when the action plugin is run

 ![image](https://us1.discourse-cdn.com/ansible/original/2X/c/cfbe99ab632cbb4a6cc8308333fda03c8303cdd0.png)

---

<div class="post-metadata">

**Author:** ![John\_Ratliff](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/john_ratliff/32/3007_2.png) [@John\_Ratliff](https://forum.ansible.com/u/John_Ratliff)\
**Post date:** [May 6, 2024, 9:43pm UTC](https://forum.ansible.com/t/how-to-debug-ansible-action-plugin/5288/4 "2024-05-06T21:43:38Z")

</div>

Thanks, this seems to work great.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [June 5, 2024, 9:44pm UTC](https://forum.ansible.com/t/how-to-debug-ansible-action-plugin/5288/5 "2024-06-05T21:44:29Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
