# Buggy code
def send_command(self, command, prompt=None, answer=None, sendonly=False):
    """Executes a cli command and returns the results
    This method will execute the CLI command on the connection and return
    the results to the caller.  The command output will be returned as a
    string
    """
    if not signal.getsignal(signal.SIGALRM):
        signal.signal(signal.SIGALRM, self._alarm_handler)
    signal.alarm(self._connection._play_context.timeout)
    resp = self._connection.send(command, prompt, answer, sendonly)
    signal.alarm(0)
    return resp


# Traceback (ansible.module_utils.connection.ConnectionError)
TASK [Gather facts (vyos)] ***********************************************************************************************************************************************************************************************************************
task path: /home/johnb/git/ansible-inc/gundalows-test-cases/net-usecase-1-facts-v4/net-usecase-1-facts.yml:16
skipping: [eos01.example.net] => {
"changed": false,
"skip_reason": "Conditional result was False"
}
<vyos01.example.net> attempting to start connection
<vyos01.example.net> using connection plugin network_cli
<vyos01.example.net> local domain socket does not exist, starting it
<vyos01.example.net> control socket path is /home/johnb/.ansible/pc/473589d267
<vyos01.example.net> connection to remote device started successfully
<vyos01.example.net> local domain socket listeners started successfully
<vyos01.example.net> local domain socket path is /home/johnb/.ansible/pc/473589d267
Using module file /home/johnb/git/ansible-inc/ansible-workspace-4/lib/ansible/modules/network/vyos/vyos_facts.py
<vyos01.example.net> ESTABLISH LOCAL CONNECTION FOR USER: johnb
<vyos01.example.net> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<vyos01.example.net> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/johnb/.ansible/tmp/ansible-tmp-1513071920.48-103347042615861 `" &amp;&amp; echo ansible-tmp-1513071920.48-103347042615861="` echo /home/johnb/.ansible/tmp/ansible-tmp-1513071920.48-103347042615861 `" ) &amp;&amp; sleep 0'
<vyos01.example.net> PUT /tmp/tmpcpJLro TO /home/johnb/.ansible/tmp/ansible-tmp-1513071920.48-103347042615861/vyos_facts.py
<vyos01.example.net> EXEC /bin/sh -c 'chmod u+x /home/johnb/.ansible/tmp/ansible-tmp-1513071920.48-103347042615861/ /home/johnb/.ansible/tmp/ansible-tmp-1513071920.48-103347042615861/vyos_facts.py &amp;&amp; sleep 0'
<vyos01.example.net> EXEC /bin/sh -c '/usr/bin/python /home/johnb/.ansible/tmp/ansible-tmp-1513071920.48-103347042615861/vyos_facts.py; rm -rf "/home/johnb/.ansible/tmp/ansible-tmp-1513071920.48-103347042615861/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_mEbZ4z/ansible_module_vyos_facts.py", line 320, in <module>
main()
File "/tmp/ansible_mEbZ4z/ansible_module_vyos_facts.py", line 308, in main
inst.populate()
File "/tmp/ansible_mEbZ4z/ansible_module_vyos_facts.py", line 194, in populate
super(Neighbors, self).populate()
File "/tmp/ansible_mEbZ4z/ansible_module_vyos_facts.py", line 117, in populate
self.responses = run_commands(self.module, list(self.COMMANDS))
File "/tmp/ansible_mEbZ4z/ansible_modlib.zip/ansible/module_utils/network/vyos/vyos.py", line 117, in run_commands
File "/tmp/ansible_mEbZ4z/ansible_modlib.zip/ansible/module_utils/connection.py", line 146, in __rpc__
ansible.module_utils.connection.ConnectionError:  VMware, Inc.
Model:        VMware Virtual Platform
Asset ID:     No Asset Tag
-------------------------------------------------------------------------------
ansible@an-vyos-01:~$ None

Invalid command: [None]

ansible@an-vyos-01:~$

fatal: [vyos01.example.net]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_mEbZ4z/ansible_module_vyos_facts.py\", line 320, in <module>\n    main()\n  File \"/tmp/ansible_mEbZ4z/ansible_module_vyos_facts.py\", line 308, in main\n    inst.populate()\n  File \"/tmp/ansible_mEbZ4z/ansible_module_vyos_facts.py\", line 194, in populate\n    super(Neighbors, self).populate()\n  File \"/tmp/ansible_mEbZ4z/ansible_module_vyos_facts.py\", line 117, in populate\n    self.responses = run_commands(self.module, list(self.COMMANDS))\n  File \"/tmp/ansible_mEbZ4z/ansible_modlib.zip/ansible/module_utils/network/vyos/vyos.py\", line 117, in run_commands\n  File \"/tmp/ansible_mEbZ4z/ansible_modlib.zip/ansible/module_utils/connection.py\", line 146, in __rpc__\nansible.module_utils.connection.ConnectionError:  VMware, Inc.\r\n      Model:        VMware Virtual Platform\r\n      Asset ID:     No Asset Tag\r\n-------------------------------------------------------------------------------\r\nansible@an-vyos-01:~$ None\r\n\r\n  Invalid command: [None]\r\n\r\nansible@an-vyos-01:~$ \n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def send_command(self, command, prompt=None, answer=None, sendonly=False):
    """Executes a cli command and returns the results
    This method will execute the CLI command on the connection and return
    the results to the caller.  The command output will be returned as a
    string
    """
    kwargs = {"command": to_bytes(command), "sendonly": sendonly}
    if prompt is not None:
        kwargs["prompt"] = to_bytes(prompt)
    if answer is not None:
        kwargs["answer"] = to_bytes(answer)

    if not signal.getsignal(signal.SIGALRM):
        signal.signal(signal.SIGALRM, self._alarm_handler)
    signal.alarm(self._connection._play_context.timeout)
    resp = self._connection.send(**kwargs)
    signal.alarm(0)
    return resp