Hi, I want to be able to go into interactive mode while creating a module. To do this I am adding the following line to my python code:
import pdb; pdb.set_trace()
when I run my ansible playbook with the following line:
ansible-playbook -i hosts helloworld.yml -vvv
I get this error:
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_fDi5pe/ansible_module_helloworld.py", line
5, in <module>
def main():
File "/tmp/ansible_fDi5pe/ansible_module_helloworld.py", line
5, in <module>
def main():
File "/usr/lib/python2.7/bdb.py", line 49, in trace_dispatch
return self.dispatch_line(frame)
File "/usr/lib/python2.7/bdb.py", line 68, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n Fil
e \"/tmp/ansible_fDi5pe/ansible_module_helloworld.py\", line 5,
in <module>\n def main():\n File \"/tmp/ansible_fDi5pe/ans
ible_module_helloworld.py\", line 5, in <module>\n def main(
):\n File \"/usr/lib/python2.7/bdb.py\", line 49, in trace_dis
patch\n return self.dispatch_line(frame)\n File \"/usr/lib/
python2.7/bdb.py\", line 68, in dispatch_line\n if self.quit
ting: raise BdbQuit\nbdb.BdbQuit\n",
"module_stdout": "> /tmp/ansible_fDi5pe/ansible_module_hell
oworld.py(5)<module>()\n-> def main():\n(Pdb) *** NameError: na
me 'false' is not defined\n(Pdb) \n",
"msg": "MODULE FAILURE",
"rc": 0
}
======================================================
Ansible playbook (helloworld.yml)
---
- hosts: localhost
tasks:
- name: Test that my module works
helloworld:
register: result
- debug: var=result
=====================================
Ansible module (helloworld.py)
#!/usr/bin/python
from ansible.module_utils.basic import *
def main():
import pdb; pdb.set_trace()
module = AnsibleModule(argument_spec={})
response = {"hello": "world"}
module.exit_json(changed=False, meta=response)
if __name__ == '__main__':
main()
=====================================
I would like to go into interactive mode so I can debug a module I am creating
Please note that this module works completely fine when I remove the pdb line
pdb is also working find when I don't user ansible
thanks for the help