# Buggy code
def __init__(self):
    self.device = None
    self.config = None
    self._locked = False
    self._connected = False
    self.default_output = "xml"


# Traceback (NameError)
TASK [test_junos_config : setup] ***********************************************
task path: /home/johnb/git/ansible-inc/test-network-modules/roles/test_junos_config/tests/netconf/single.yaml:4
Using module file /home/johnb/git/ansible-inc/ansible/lib/ansible/modules/core/network/junos/junos_config.py
<vsrx01> ESTABLISH LOCAL CONNECTION FOR USER: johnb
<vsrx01> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1474035513.73-204788358334242 `" &amp;&amp; echo ansible-tmp-1474035513.73-204788358334242="` echo $HOME/.ansible/tmp/ansible-tmp-1474035513.73-204788358334242 `" ) &amp;&amp; sleep 0'
<vsrx01> PUT /tmp/tmp9vam25 TO /home/johnb/.ansible/tmp/ansible-tmp-1474035513.73-204788358334242/junos_config.py
<vsrx01> EXEC /bin/sh -c 'chmod u+x /home/johnb/.ansible/tmp/ansible-tmp-1474035513.73-204788358334242/ /home/johnb/.ansible/tmp/ansible-tmp-1474035513.73-204788358334242/junos_config.py &amp;&amp; sleep 0'
<vsrx01> EXEC /bin/sh -c 'python /home/johnb/.ansible/tmp/ansible-tmp-1474035513.73-204788358334242/junos_config.py; rm -rf "/home/johnb/.ansible/tmp/ansible-tmp-1474035513.73-204788358334242/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_vsAILG/ansible_module_junos_config.py", line 292, in <module>
main()
File "/tmp/ansible_vsAILG/ansible_module_junos_config.py", line 275, in main
supports_check_mode=True)
File "/tmp/ansible_vsAILG/ansible_modlib.zip/ansible/module_utils/network.py", line 111, in __init__
File "/tmp/ansible_vsAILG/ansible_modlib.zip/ansible/module_utils/network.py", line 147, in connect
File "/tmp/ansible_vsAILG/ansible_modlib.zip/ansible/module_utils/junos.py", line 96, in connect
NameError: global name 'Device' is not defined

fatal: [vsrx01]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"lines": [
"set system host-name vsrx01"
],
"provider": {
"host": "vsrx01",
"password": "Ansible",
"transport": "netconf",
"username": "ansible"
}
},
"module_name": "junos_config"
},
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_vsAILG/ansible_module_junos_config.py\", line 292, in <module>\n    main()\n  File \"/tmp/ansible_vsAILG/ansible_module_junos_config.py\", line 275, in main\n    supports_check_mode=True)\n  File \"/tmp/ansible_vsAILG/ansible_modlib.zip/ansible/module_utils/network.py\", line 111, in __init__\n  File \"/tmp/ansible_vsAILG/ansible_modlib.zip/ansible/module_utils/network.py\", line 147, in connect\n  File \"/tmp/ansible_vsAILG/ansible_modlib.zip/ansible/module_utils/junos.py\", line 96, in connect\nNameError: global name 'Device' is not defined\n",
"module_stdout": "",
"msg": "MODULE FAILURE"

# Fixed code
def __init__(self):
    if not HAS_PYEZ:
        raise NetworkError(
            msg="junos-eznc >= 1.2.2 is required but does not appear to be installed.  "
            "It can be installed using `pip install junos-eznc`"
        )
    if not HAS_JXMLEASE:
        raise NetworkError(
            msg="jxmlease is required but does not appear to be installed.  "
            "It can be installed using `pip install jxmlease`"
        )
    self.device = None
    self.config = None
    self._locked = False
    self._connected = False
    self.default_output = "xml"