Repository: ansible/ansible

Issue:
python3 asa_command cannot use a string pattern 
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and devel branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Bug Report
 

##### COMPONENT NAME
<!---
Name of the module, plugin, task or feature
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->
asa_command
##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.0b1
  config file = /mnt/hgfs/Share/HCS/ansible.cfg
  configured module search path = ['/home/ddean1/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ddean1/ansible/lib/python3.5/site-packages/ansible
  executable location = /home/ddean1/ansible/bin/ansible
  python version = 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
ANSIBLE_FORCE_COLOR(/mnt/hgfs/Share/HCS/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/mnt/hgfs/Share/HCS/ansible.cfg) = -o ControlMaster=auto -o ControlPersist=30s
DEFAULT_GATHERING(/mnt/hgfs/Share/HCS/ansible.cfg) = explicit
DEFAULT_HOST_LIST(/mnt/hgfs/Share/HCS/ansible.cfg) = ['/mnt/hgfs/Share/HCS/hosts']
HOST_KEY_CHECKING(/mnt/hgfs/Share/HCS/ansible.cfg) = False
RETRY_FILES_ENABLED(/mnt/hgfs/Share/HCS/ansible.cfg) = False

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Cisco ASA version = 9.2(2)4

##### SUMMARY
<!--- Explain the problem briefly -->
unable to execute commands using asa_command on cisco asa
##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
any basic playbook using asa_command should reproduce the issue 

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: "ASA Health Check"
  hosts: lab_asa
  connection: local

  tasks:
    - name: "Get Running config"
      asa_command:
        commands:
          - show running-config 
        context: system
      register: output

    - debug: msg="{{ output.stdout_lines[0] }}"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Return `show running-config` as `output` and display it in `stdout` using the debug module
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
command fails and returns `fatal: [hcs_asa_core]: FAILED! => {"failed": true, "msg": "cannot use a string pattern on a bytes-like object"}`
<!--- Paste verbatim command output between quotes below -->
```
(ansible) ddean1@DevBox ~/Share/HCS[master*]$ ansible-playbook ASA_Health_Check.yml -k -vvvv
ansible-playbook 2.5.0b1
  config file = /mnt/hgfs/Share/HCS/ansible.cfg
  configured module search path = ['/home/ddean1/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ddean1/ansible/lib/python3.5/site-packages/ansible
  executable location = /home/ddean1/ansible/bin/ansible-playbook
  python version = 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
Using /mnt/hgfs/Share/HCS/ansible.cfg as config file
SSH password: 
setting up inventory plugins
Parsed /mnt/hgfs/Share/HCS/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /home/ddean1/ansible/lib/python3.5/site-packages/ansible/plugins/callback/default.py

PLAYBOOK: ASA_Health_Check.yml **********************************************************************************************************************************************************************************************************
1 plays in ASA_Health_Check.yml

PLAY [ASA Health Check] *****************************************************************************************************************************************************************************************************************
META: ran handlers

TASK [Get Runninf config] ***************************************************************************************************************************************************************************************************************
task path: /mnt/hgfs/Share/HCS/ASA_Health_Check.yml:6
<10.204.81.101> using connection plugin network_cli (was local)
<10.204.81.101> starting connection from persistent connection plugin
<10.204.81.101> local domain socket does not exist, starting it
<10.204.81.101> control socket path is /home/ddean1/.ansible/pc/70c4561b1e
<10.204.81.101> 
The full traceback is:
Traceback (most recent call last):
  File "/home/ddean1/ansible/bin/ansible-connection", line 70, in start
    self.connection._connect()
  File "/home/ddean1/ansible/lib/python3.5/site-packages/ansible/plugins/connection/network_cli.py", line 315, in _connect
    self.receive()
  File "/home/ddean1/ansible/lib/python3.5/site-packages/ansible/plugins/connection/network_cli.py", line 410, in receive
    if self._find_prompt(window):
  File "/home/ddean1/ansible/lib/python3.5/site-packages/ansible/plugins/connection/network_cli.py", line 481, in _find_prompt
    if regex.search(response):
TypeError: cannot use a string pattern on a bytes-like object

fatal: [hcs_asa_core]: FAILED! => {
    "failed": true,
    "msg": "cannot use a string pattern on a bytes-like object"
}

PLAY RECAP ******************************************************************************************************************************************************************************************************************************
hcs_asa_core               : ok=0    changed=0    unreachable=0    failed=1   

```



Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
Files identified in the description:
* [lib/ansible/modules/network/asa/asa_command.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/network/asa/asa_command.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @ogenstad @privateip
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/plugins/terminal/asa.py b/lib/ansible/plugins/terminal/asa.py
--- a/lib/ansible/plugins/terminal/asa.py
+++ b/lib/ansible/plugins/terminal/asa.py
@@ -30,12 +30,12 @@
 class TerminalModule(TerminalBase):
 
     terminal_stdout_re = [
-        re.compile(r"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
-        re.compile(r"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$")
+        re.compile(br"[\r\n]?[\w+\-\.:\/\[\]]+(?:\([^\)]+\)){,3}(?:>|#) ?$"),
+        re.compile(br"\[\w+\@[\w\-\.]+(?: [^\]])\] ?[>#\$] ?$")
     ]
 
     terminal_stderr_re = [
-        re.compile(r"error:", re.I),
+        re.compile(br"error:", re.I),
         re.compile(br"Removing.* not allowed, it is being used")
     ]
 


Test patch: