# Buggy code
def on_become(self, passwd=None):
    if self._get_prompt().endswith("#"):
        return

    cmd = {"command": "enable"}
    if passwd:
        cmd["prompt"] = to_text(r"[\r\n]?password:$", errors="surrogate_or_strict")
        cmd["answer"] = passwd
    try:
        self._exec_cli_command(to_bytes(json.dumps(cmd), errors="surrogate_or_strict"))
    except AnsibleConnectionFailure:
        raise AnsibleConnectionFailure("unable to elevate privilege to enable mode")
    # in dellos6 the terminal settings are accepted after the privilege mode
    try:
        self._exec_cli_command(b"terminal length 0")
    except AnsibleConnectionFailure:
        raise AnsibleConnectionFailure("unable to set terminal parameters")


# Traceback (TypeError)
ansible-playbook 2.7.1
config file = None
configured module search path = ['/Users/jed.giblin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/jed.giblin/.pyenv/versions/3.5.6/lib/python3.5/site-packages/ansible
executable location = /Users/jed.giblin/.pyenv/versions/3.5.6/bin/ansible-playbook
python version = 3.5.6 (default, Oct 11 2018, 08:11:38) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)]
No config file found; using defaults
/Users/jed.giblin/code/backup/ansible-playbooks/production did not meet host_list requirements, check plugin documentation if this is unexpected
/Users/jed.giblin/code/backup/ansible-playbooks/production did not meet script requirements, check plugin documentation if this is unexpected
Parsed /Users/jed.giblin/code/backup/ansible-playbooks/production inventory source with ini plugin

PLAYBOOK: showversion.yaml *****************************************************************************************************************************************************************************************************************************************************
1 plays in showversion.yaml

PLAY [de.du.07.router1] ********************************************************************************************************************************************************************************************************************************************************
META: ran handlers

TASK [debug] *******************************************************************************************************************************************************************************************************************************************************************
task path: /Users/jed.giblin/code/backup/ansible-playbooks/showversion.yaml:7
The full traceback is:
Traceback (most recent call last):
File "/Users/jed.giblin/.pyenv/versions/3.5.6/bin/ansible-connection", line 106, in start
self.connection._connect()
File "/Users/jed.giblin/.pyenv/versions/3.5.6/lib/python3.5/site-packages/ansible/plugins/connection/network_cli.py", line 336, in _connect
self._terminal.on_become(passwd=auth_pass)
File "/Users/jed.giblin/.pyenv/versions/3.5.6/lib/python3.5/site-packages/ansible/plugins/terminal/dellos6.py", line 54, in on_become
if self._get_prompt().endswith('#'):
TypeError: endswith first arg must be bytes or a tuple of bytes, not str

fatal: [192.168.1.2]: FAILED! => {
"msg": "endswith first arg must be bytes or a tuple of bytes, not str"
}
to retry, use: --limit @/Users/jed.giblin/code/backup/ansible-playbooks/showversion.retry

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************************
192.168.1.2           : ok=0    changed=0    unreachable=0    failed=1

# Fixed code
def on_become(self, passwd=None):
    if self._get_prompt().endswith(b"#"):
        return

    cmd = {"command": "enable"}
    if passwd:
        cmd["prompt"] = to_text(r"[\r\n]?password:$", errors="surrogate_or_strict")
        cmd["answer"] = passwd
    try:
        self._exec_cli_command(to_bytes(json.dumps(cmd), errors="surrogate_or_strict"))
    except AnsibleConnectionFailure:
        raise AnsibleConnectionFailure("unable to elevate privilege to enable mode")
    # in dellos6 the terminal settings are accepted after the privilege mode
    try:
        self._exec_cli_command(b"terminal length 0")
    except AnsibleConnectionFailure:
        raise AnsibleConnectionFailure("unable to set terminal parameters")