# Buggy code
def execute(self, commands, output="json", **kwargs):
    """Send commands to the device."""
    if self.url is None:
        raise NetworkError("Not connected to endpoint.")

    if self.enable is not None:
        commands.insert(0, self.enable)

    body = self._get_body(commands, output)
    data = json.dumps(body)

    headers = {"Content-Type": "application/json-rpc"}
    timeout = self.url_args["timeout"]

    response, headers = fetch_url(
        self.url_args,
        self.url,
        data=data,
        headers=headers,
        method="POST",
        timeout=timeout,
    )

    if headers["status"] != 200:
        raise NetworkError(**headers)

    try:
        response = json.loads(response.read())
    except ValueError:
        raise NetworkError("unable to load response from device")

    if "error" in response:
        err = response["error"]
        raise NetworkError(
            msg=err["message"], code=err["code"], data=err["data"], commands=commands
        )

    if self.enable:
        response["result"].pop(0)

    return response["result"]


# Traceback (TypeError)
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/core/network/eos/eos_command.py
<lf2> ESTABLISH LOCAL CONNECTION FOR USER: root
<lf2> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<lf2> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1487950019.58-19960267572732 `" &amp;&amp; echo ansible-tmp-1487950019.58-19960267572732="` echo /root/.ansible/tmp/ansible-tmp-1487950019.58-19960267572732 `" ) &amp;&amp; sleep 0'
<lf2> PUT /tmp/tmpgEtOGi TO /root/.ansible/tmp/ansible-tmp-1487950019.58-19960267572732/eos_command.py
<lf2> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1487950019.58-19960267572732/ /root/.ansible/tmp/ansible-tmp-1487950019.58-19960267572732/eos_command.py &amp;&amp; sleep 0'
<lf2> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1487950019.58-19960267572732/eos_command.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1487950019.58-19960267572732/" > /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_TYO0ov/ansible_module_eos_command.py", line 255, in <module>
main()
File "/tmp/ansible_TYO0ov/ansible_module_eos_command.py", line 228, in main
runner.run()
File "/tmp/ansible_TYO0ov/ansible_modlib.zip/ansible/module_utils/netcli.py", line 170, in run
File "/tmp/ansible_TYO0ov/ansible_modlib.zip/ansible/module_utils/netcli.py", line 98, in run_commands
File "/tmp/ansible_TYO0ov/ansible_modlib.zip/ansible/module_utils/eos.py", line 250, in run_commands
File "/tmp/ansible_TYO0ov/ansible_modlib.zip/ansible/module_utils/eos.py", line 209, in execute
TypeError: 'ModuleStub' object has no attribute '__getitem__'

fatal: [XXX]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "eos_command"
},
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_TYO0ov/ansible_module_eos_command.py\", line 255, in <module>\n    main()\n  File \"/tmp/ansible_TYO0ov/ansible_module_eos_command.py\", line 228, in main\n    runner.run()\n  File \"/tmp/ansible_TYO0ov/ansible_modlib.zip/ansible/module_utils/netcli.py\", line 170, in run\n  File \"/tmp/ansible_TYO0ov/ansible_modlib.zip/ansible/module_utils/netcli.py\", line 98, in run_commands\n  File \"/tmp/ansible_TYO0ov/ansible_modlib.zip/ansible/module_utils/eos.py\", line 250, in run_commands\n  File \"/tmp/ansible_TYO0ov/ansible_modlib.zip/ansible/module_utils/eos.py\", line 209, in execute\nTypeError: 'ModuleStub' object has no attribute '__getitem__'\n",
"module_stdout": "",
"msg": "MODULE FAILURE"
}

# Fixed code
def execute(self, commands, output="json", **kwargs):
    """Send commands to the device."""
    if self.url is None:
        raise NetworkError("Not connected to endpoint.")

    if self.enable is not None:
        commands.insert(0, self.enable)

    body = self._get_body(commands, output)
    data = json.dumps(body)

    headers = {"Content-Type": "application/json-rpc"}
    timeout = self.url_args.params["timeout"]

    response, headers = fetch_url(
        self.url_args,
        self.url,
        data=data,
        headers=headers,
        method="POST",
        timeout=timeout,
    )

    if headers["status"] != 200:
        raise NetworkError(**headers)

    try:
        response = json.loads(response.read())
    except ValueError:
        raise NetworkError("unable to load response from device")

    if "error" in response:
        err = response["error"]
        raise NetworkError(
            msg=err["message"], code=err["code"], data=err["data"], commands=commands
        )

    if self.enable:
        response["result"].pop(0)

    return response["result"]