# How to debug a community ansible module ?

**URL:** <https://forum.ansible.com/t/how-to-debug-a-community-ansible-module/33462>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [July 22, 2020, 12:40pm UTC](https://forum.ansible.com/t/how-to-debug-a-community-ansible-module/33462 "2020-07-22T12:40:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmoullia](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cmoullia](https://forum.ansible.com/u/cmoullia)\
**Post date:** [July 22, 2020, 12:40pm UTC](https://forum.ansible.com/t/how-to-debug-a-community-ansible-module/33462/1 "2020-07-22T12:40:22Z")

</div>

Hi,

As the packages to be imported by a python file are prefixed as “ansible\_collections.”, how can we then locally debug an Ansible Module

Example: [https://github.com/ansible-collections/community.kubernetes/blob/main/plugins/modules/k8s\_log.py](https://github.com/ansible-collections/community.kubernetes/blob/main/plugins/modules/k8s_log.py)

from ansible\_collections.community.kubernetes.plugins.module\_utils.common import KubernetesAnsibleModule  
…

class KubernetesLogModule(KubernetesAnsibleModule):

def **init** (self, \*args, \*\*kwargs):  
KubernetesAnsibleModule. **init** (self, \*args,  
supports\_check\_mode=True,  
\*\*kwargs)

Result

/usr/local/bin/python3.7 “/Users/cmoullia/Library/Application Support/JetBrains/IntelliJIdea2020.1/plugins/python/helpers/pydev/pydevd.py” --multiproc --qt-support=auto --client 127.0.0.1 --port 57135 --file /Users/cmoullia/code/ansible/community.kubernetes/plugins/modules/k8s\_log.py  
pydev debugger: process 68087 is connecting

Connected to pydev debugger (build 201.8538.31)  
Traceback (most recent call last):  
File “”, line 983, in \_find\_and\_load  
File “”, line 953, in \_find\_and\_load\_unlocked  
File “”, line 219, in \_call\_with\_frames\_removed  
ModuleNotFoundError: No module named ‘ansible\_collections’

Best

Charles

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [July 22, 2020, 12:47pm UTC](https://forum.ansible.com/t/how-to-debug-a-community-ansible-module/33462/2 "2020-07-22T12:47:19Z")

</div>

Try adding PYTHONPATH

For me it is like PYTHONPATH=/Volumes/data/src/ansible/lib:/Volumes/data/src/ansible:/Volumes/data/src/collections /Volumes/data/venv3/bin/python

---

<div class="post-metadata">

**Author:** ![cmoullia](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cmoullia](https://forum.ansible.com/u/cmoullia)\
**Post date:** [July 22, 2020, 1:44pm UTC](https://forum.ansible.com/t/how-to-debug-a-community-ansible-module/33462/3 "2020-07-22T13:44:22Z")

</div>

That fails if I try what you suggest as the project (I suppose) is no installed as a collection but git cloned

(.venv) ~/code/ansible/ansible\_collections $ PYTHONPATH=/Users/cmoullia/code/ansible/ansible\_collections python3 community/kubernetes/plugins/modules/k8s\_log.py  
Traceback (most recent call last):  
File “community/kubernetes/plugins/modules/k8s\_log.py”, line 131, in   
from ansible\_collections.community.kubernetes.plugins.module\_utils.common import KubernetesAnsibleModule  
ModuleNotFoundError: No module named ‘ansible\_collections’

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [July 22, 2020, 1:50pm UTC](https://forum.ansible.com/t/how-to-debug-a-community-ansible-module/33462/4 "2020-07-22T13:50:02Z")

</div>

`ansible_collections` is the python module that the code will try to load, so you cannot contain that in your PYTHONPATH, you need to set your PYTHONPATH to the directory that contains the ansible\_collections directory.

fwiw, I wouldn’t recommend using this as the primary means to test or debug a module.

Follow the docs outlined at [https://docs.ansible.com/ansible/devel/dev\_guide/debugging.html#debugging-ansiblemodule-based-modules](https://docs.ansible.com/ansible/devel/dev_guide/debugging.html#debugging-ansiblemodule-based-modules)

If you bypass the normal execution flow, you aren’t properly testing the module.

---

<div class="post-metadata">

**Author:** ![cmoullia](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cmoullia](https://forum.ansible.com/u/cmoullia)\
**Post date:** [July 22, 2020, 1:57pm UTC](https://forum.ansible.com/t/how-to-debug-a-community-ansible-module/33462/5 "2020-07-22T13:57:23Z")

</div>

Sorry but I don’t see how I could debug the code with a breakpoint declared within my IDEA tool using this command “ansible localhost -m ping -a ‘data=debugging\_session’ -vvv” …
