# Buggy code
def parse_version(self, data):
    match = re.search(r"Version (\S+),", data)
    if match:
        return match.group(1)


# Traceback (ansible.module_utils.network.NetworkError)
[[ansible@localhost V1]$ ansible-playbook iosfacts_wo_config_c_ios.yml -i hosts.ini --ask-vault-pass -vvv
Using /etc/ansible/ansible.cfg as config file
Vault password:

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

PLAY [c_ios] *******************************************************************

TASK [setup] *******************************************************************
Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/system/setup.py
<10.82.1.1> ESTABLISH LOCAL CONNECTION FOR USER: ansible
<10.82.1.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1484815415.2-154319293295953 `" &amp;&amp; echo ansible-tmp-1484815415.2-154319293295953="` echo $HOME/.ansible/tmp/ansible-tmp-1484815415.2-154319293295953 `" ) &amp;&amp; sleep 0'
<10.82.1.1> PUT /tmp/tmpNjPI97 TO /home/ansible/.ansible/tmp/ansible-tmp-1484815415.2-154319293295953/setup.py
<10.82.1.1> EXEC /bin/sh -c 'chmod u+x /home/ansible/.ansible/tmp/ansible-tmp-1484815415.2-154319293295953/ /home/ansible/.ansible/tmp/ansible-tmp-1484815415.2-154319293295953/setup.py &amp;&amp; sleep 0'
<10.82.1.1> EXEC /bin/sh -c '/usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1484815415.2-154319293295953/setup.py; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1484815415.2-154319293295953/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
ok: [10.82.1.1]

TASK [network device facts on ios devices: hardware] ***************************
task path: /home/ansible/AnsibleProjects/BNAS_Course/EasyWins/V1/iosfacts_wo_config_c_ios.yml:6
Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/network/ios/ios_facts.py
<10.82.1.1> ESTABLISH LOCAL CONNECTION FOR USER: ansible
<10.82.1.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1484815415.66-184587982314609 `" &amp;&amp; echo ansible-tmp-1484815415.66-184587982314609="` echo $HOME/.ansible/tmp/ansible-tmp-1484815415.66-184587982314609 `" ) &amp;&amp; sleep 0'
<10.82.1.1> PUT /tmp/tmpzBnhjn TO /home/ansible/.ansible/tmp/ansible-tmp-1484815415.66-184587982314609/ios_facts.py
<10.82.1.1> EXEC /bin/sh -c 'chmod u+x /home/ansible/.ansible/tmp/ansible-tmp-1484815415.66-184587982314609/ /home/ansible/.ansible/tmp/ansible-tmp-1484815415.66-184587982314609/ios_facts.py &amp;&amp; sleep 0'
<10.82.1.1> EXEC /bin/sh -c '/usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1484815415.66-184587982314609/ios_facts.py; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1484815415.66-184587982314609/" > /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_vPS19f/ansible_module_ios_facts.py", line 461, in <module>
main()
File "/tmp/ansible_vPS19f/ansible_module_ios_facts.py", line 443, in main
runner.run()
File "/tmp/ansible_vPS19f/ansible_modlib.zip/ansible/module_utils/netcli.py", line 170, in run
File "/tmp/ansible_vPS19f/ansible_modlib.zip/ansible/module_utils/netcli.py", line 98, in run_commands
File "/tmp/ansible_vPS19f/ansible_modlib.zip/ansible/module_utils/shell.py", line 253, in run_commands
File "/tmp/ansible_vPS19f/ansible_modlib.zip/ansible/module_utils/shell.py", line 250, in execute
ansible.module_utils.network.NetworkError: matched error in response: show memory statistics | include Processor
^
% Invalid input detected at '^' marker.

sy-eng-ch-grn-s-001#

fatal: [10.82.1.1]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "ios_facts"
},
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_vPS19f/ansible_module_ios_facts.py\", line 461, in <module>\n    main()\n  File \"/tmp/ansible_vPS19f/ansible_module_ios_facts.py\", line 443, in main\n    runner.run()\n  File \"/tmp/ansible_vPS19f/ansible_modlib.zip/ansible/module_utils/netcli.py\", line 170, in run\n  File \"/tmp/ansible_vPS19f/ansible_modlib.zip/ansible/module_utils/netcli.py\", line 98, in run_commands\n  File \"/tmp/ansible_vPS19f/ansible_modlib.zip/ansible/module_utils/shell.py\", line 253, in run_commands\n  File \"/tmp/ansible_vPS19f/ansible_modlib.zip/ansible/module_utils/shell.py\", line 250, in execute\nansible.module_utils.network.NetworkError: matched error in response: show memory statistics | include Processor\r\n                                ^\r\n% Invalid input detected at '^' marker.\r\n\r\nsy-eng-ch-grn-s-001#\n",
"module_stdout": "",
"msg": "MODULE FAILURE"
}
to retry, use: --limit @/home/ansible/AnsibleProjects/BNAS_Course/EasyWins/V1/iosfacts_wo_config_c_ios.retry

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

# Fixed code
def parse_version(self, data):
    match = re.search(r"Version (\S+?)(?:,\s|\s)", data)
    if match:
        return match.group(1)