# Buggy code
def check_fail(module, output):
    error = [re.compile(rb"^error", re.I)]
    for x in output:
        for regex in error:
            if regex.search(x):
                module.fail_json(msg=x)


# Traceback (TypeError)
[lab@manjaro1 ansible-icx]$ /usr/bin/ansible-playbook playbook_vlan.yml -vvv
ansible-playbook 2.9.4
config file = /home/lab/ansible-icx/ansible.cfg
configured module search path = ['/home/lab/ansible-icx/moduless']
ansible python module location = /usr/lib/python3.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 3.7.4 (default, Oct  4 2019, 06:57:26) [GCC 9.2.0]
Using /home/lab/ansible-icx/ansible.cfg as config file
host_list declined parsing /home/lab/ansible-icx/hosts as it did not pass its verify_file() method
script declined parsing /home/lab/ansible-icx/hosts as it did not pass its verify_file() method
auto declined parsing /home/lab/ansible-icx/hosts as it did not pass its verify_file() method
Parsed /home/lab/ansible-icx/hosts inventory source with ini plugin

PLAYBOOK: playbook_vlan.yml ****************************************************************************************************************************************************************************************************************************************************
1 plays in playbook_vlan.yml

PLAY [10.173.6.79] *************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************************************************
task path: /home/lab/ansible-icx/playbook_vlan.yml:2
[WARNING]: Persistent connection logging is enabled for 10.173.6.79. This will log ALL interactions to /home/lab/ansible.log and WILL NOT redact sensitive configuration like passwords. USE WITH CAUTION!

<10.173.6.79> ESTABLISH LOCAL CONNECTION FOR USER: lab
<10.173.6.79> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687161.6594033-231553837652791 `" &amp;&amp; echo ansible-tmp-1579687161.6594033-231553837652791="` echo /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687161.6594033-231553837652791 `" ) &amp;&amp; sleep 0'
<10.173.6.79> Attempting python interpreter discovery
<10.173.6.79> EXEC /bin/sh -c 'echo PLATFORM; uname; echo FOUND; command -v '"'"'/usr/bin/python'"'"'; command -v '"'"'python3.7'"'"'; command -v '"'"'python3.6'"'"'; command -v '"'"'python3.5'"'"'; command -v '"'"'python2.7'"'"'; command -v '"'"'python2.6'"'"'; command -v '"'"'/usr/libexec/platform-python'"'"'; command -v '"'"'/usr/bin/python3'"'"'; command -v '"'"'python'"'"'; echo ENDFOUND &amp;&amp; sleep 0'
<10.173.6.79> EXEC /bin/sh -c '/usr/bin/python &amp;&amp; sleep 0'
<10.173.6.79> Python interpreter discovery fallback (unsupported Linux distribution: arch)
Using module file /usr/lib/python3.7/site-packages/ansible/modules/system/setup.py
<10.173.6.79> PUT /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/tmpcs8s82mw TO /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687161.6594033-231553837652791/AnsiballZ_setup.py
<10.173.6.79> EXEC /bin/sh -c 'chmod u+x /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687161.6594033-231553837652791/ /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687161.6594033-231553837652791/AnsiballZ_setup.py &amp;&amp; sleep 0'
<10.173.6.79> EXEC /bin/sh -c '/usr/bin/python /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687161.6594033-231553837652791/AnsiballZ_setup.py &amp;&amp; sleep 0'
<10.173.6.79> EXEC /bin/sh -c 'rm -f -r /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687161.6594033-231553837652791/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
[WARNING]: Platform linux on host 10.173.6.79 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html
for more information.

ok: [10.173.6.79]
META: ran handlers

TASK [configure new vlan] ******************************************************************************************************************************************************************************************************************************************************
task path: /home/lab/ansible-icx/playbook_vlan.yml:14
[WARNING]: Persistent connection logging is enabled for 10.173.6.79. This will log ALL interactions to /home/lab/ansible.log and WILL NOT redact sensitive configuration like passwords. USE WITH CAUTION!

<10.173.6.79> ESTABLISH LOCAL CONNECTION FOR USER: lab
<10.173.6.79> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979 `" &amp;&amp; echo ansible-tmp-1579687162.8806524-84374280455979="` echo /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979 `" ) &amp;&amp; sleep 0'
Using module file /usr/lib/python3.7/site-packages/ansible/modules/network/icx/icx_vlan.py
<10.173.6.79> PUT /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/tmpbc3l0me5 TO /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/AnsiballZ_icx_vlan.py
<10.173.6.79> EXEC /bin/sh -c 'chmod u+x /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/ /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/AnsiballZ_icx_vlan.py &amp;&amp; sleep 0'
<10.173.6.79> EXEC /bin/sh -c '/usr/bin/python /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/AnsiballZ_icx_vlan.py &amp;&amp; sleep 0'
<10.173.6.79> EXEC /bin/sh -c 'rm -f -r /home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/AnsiballZ_icx_vlan.py", line 102, in <module>
_ansiballz_main()
File "/home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/AnsiballZ_icx_vlan.py", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/AnsiballZ_icx_vlan.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.network.icx.icx_vlan', init_globals=None, run_name='__main__', alter_sys=True)
File "/usr/lib/python3.7/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.7/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/ansible_icx_vlan_payload_m_a3bget/ansible_icx_vlan_payload.zip/ansible/modules/network/icx/icx_vlan.py", line 784, in <module>
File "/tmp/ansible_icx_vlan_payload_m_a3bget/ansible_icx_vlan_payload.zip/ansible/modules/network/icx/icx_vlan.py", line 774, in main
File "/tmp/ansible_icx_vlan_payload_m_a3bget/ansible_icx_vlan_payload.zip/ansible/modules/network/icx/icx_vlan.py", line 671, in check_fail
TypeError: cannot use a bytes pattern on a string-like object

fatal: [10.173.6.79]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/AnsiballZ_icx_vlan.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/AnsiballZ_icx_vlan.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/lab/.ansible/tmp/ansible-local-26136kld8lje0/ansible-tmp-1579687162.8806524-84374280455979/AnsiballZ_icx_vlan.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible.modules.network.icx.icx_vlan', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.7/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.7/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib/python3.7/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_icx_vlan_payload_m_a3bget/ansible_icx_vlan_payload.zip/ansible/modules/network/icx/icx_vlan.py\", line 784, in <module>\n  File \"/tmp/ansible_icx_vlan_payload_m_a3bget/ansible_icx_vlan_payload.zip/ansible/modules/network/icx/icx_vlan.py\", line 774, in main\n  File \"/tmp/ansible_icx_vlan_payload_m_a3bget/ansible_icx_vlan_payload.zip/ansible/modules/network/icx/icx_vlan.py\", line 671, in check_fail\nTypeError: cannot use a bytes pattern on a string-like object\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************************
10.173.6.79                : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

# Fixed code
def check_fail(module, output):
    error = [re.compile(r"^error", re.I)]
    for x in output:
        for regex in error:
            if regex.search(x):
                module.fail_json(msg=x)