# Buggy code
def open(
    self,
    host,
    port=22,
    username=None,
    password=None,
    timeout=10,
    key_filename=None,
    pkey=None,
    look_for_keys=None,
    allow_agent=False,
):
    self.ssh = paramiko.SSHClient()
    self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    # unless explicitly set, disable look for keys if a password is
    # present. this changes the default search order paramiko implements
    if not look_for_keys:
        look_for_keys = password is None

    try:
        self.ssh.connect(
            host,
            port=port,
            username=username,
            password=password,
            timeout=timeout,
            look_for_keys=look_for_keys,
            pkey=pkey,
            key_filename=key_filename,
            allow_agent=allow_agent,
        )

        self.shell = self.ssh.invoke_shell()
        self.shell.settimeout(timeout)
    except socket.gaierror:
        raise ShellError("unable to resolve host name")

    if self.kickstart:
        self.shell.sendall("\n")

    self.receive()


# Traceback (paramiko.ssh_exception.SSHException)
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
2351276/" > /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_bEsrK8/ansible_module_ios_command.py", line 169, in <module>
main()
File "/tmp/ansible_bEsrK8/ansible_module_ios_command.py", line 144, in main
response = module.execute(commands)
File "/tmp/ansible_bEsrK8/ansible_modlib.zip/ansible/module_utils/ios.py", line 146, in execute
File "/tmp/ansible_bEsrK8/ansible_modlib.zip/ansible/module_utils/ios.py", line 129, in connect
File "/tmp/ansible_bEsrK8/ansible_modlib.zip/ansible/module_utils/ios.py", line 82, in connect
File "/tmp/ansible_bEsrK8/ansible_modlib.zip/ansible/module_utils/shell.py", line 107, in open
File "/usr/local/lib/python2.7/site-packages/paramiko/client.py", line 380, in connect
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
File "/usr/local/lib/python2.7/site-packages/paramiko/client.py", line 598, in _auth
raise SSHException('No authentication methods available')
paramiko.ssh_exception.SSHException: No authentication methods available

fatal: [freqm]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "ios_command"}, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_bEsrK8/ansible_module_ios_command.py\", line 169, in <module>\n    main()\n  File \"/tmp/ansible_bEsrK8/ansible_module_ios_command.py\", line 144, in main\n    response = module.execute(commands)\n  File \"/tmp/ansible_bEsrK8/ansible_modlib.zip/ansible/module_utils/ios.py\", line 146, in execute\n  File \"/tmp/ansible_bEsrK8/ansible_modlib.zip/ansible/module_utils/ios.py\", line 129, in connect\n  File \"/tmp/ansible_bEsrK8/ansible_modlib.zip/ansible/module_utils/ios.py\", line 82, in connect\n  File \"/tmp/ansible_bEsrK8/ansible_modlib.zip/ansible/module_utils/shell.py\", line 107, in open\n  File \"/usr/local/lib/python2.7/site-packages/paramiko/client.py\", line 380, in connect\n    look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)\n  File \"/usr/local/lib/python2.7/site-packages/paramiko/client.py\", line 598, in _auth\n    raise SSHException('No authentication methods available')\nparamiko.ssh_exception.SSHException: No authentication methods available\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}

# Fixed code
def open(
    self,
    host,
    port=22,
    username=None,
    password=None,
    timeout=10,
    key_filename=None,
    pkey=None,
    look_for_keys=None,
    allow_agent=False,
):
    self.ssh = paramiko.SSHClient()
    self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    # unless explicitly set, disable look for keys if a password is
    # present. this changes the default search order paramiko implements
    if not look_for_keys:
        look_for_keys = password is None

    try:
        self.ssh.connect(
            host,
            port=port,
            username=username,
            password=password,
            timeout=timeout,
            look_for_keys=look_for_keys,
            pkey=pkey,
            key_filename=key_filename,
            allow_agent=allow_agent,
        )

        self.shell = self.ssh.invoke_shell()
        self.shell.settimeout(timeout)
    except socket.gaierror:
        raise ShellError("unable to resolve host name")
    except AuthenticationException:
        raise ShellError("Unable to authenticate to remote device")

    if self.kickstart:
        self.shell.sendall("\n")

    self.receive()