# Buggy code
def parse_module(self, data):
    objects = list()
    for line in data.splitlines():
        if line == "":
            break
        if line[0].isdigit():
            obj = {}
            match_port = re.search(r"\d\s*(\d*)", line, re.M)
            if match_port:
                obj["ports"] = match_port.group(1)

            match = re.search(r"\d\s*\d*\s*(.+)$", line, re.M)
            if match:
                l = match.group(1).split("  ")
                items = list()
                for item in l:
                    if item == "":
                        continue
                    items.append(item.strip())

                if items:
                    obj["type"] = items[0]
                    obj["model"] = items[1]
                    obj["status"] = items[2]

            objects.append(obj)
    return objects


# Traceback (IndexError)
2019-05-03 10:52:31,055 p=3889 u=ataylor |  Using module file /usr/lib/python2.7/dist-packages/ansible/modules/network/nxos/nxos_facts.py
2019-05-03 10:52:31,057 p=3889 u=ataylor |    3902 1556898751.05656: transferring module to remote /home/ataylor/.ansible/tmp/ansible-local-3889K3jTQT/ansible-tmp-1556898750.89-125587640637833/AnsiballZ_nxos_facts.py
2019-05-03 10:52:31,078 p=3889 u=ataylor |    3902 1556898751.07842: done transferring module to remote
2019-05-03 10:52:31,079 p=3889 u=ataylor |    3902 1556898751.07925: _low_level_execute_command(): starting
2019-05-03 10:52:31,085 p=3889 u=ataylor |    3902 1556898751.08003: _low_level_execute_command(): executing: /bin/sh -c 'chmod u+x /home/ataylor/.ansible/tmp/ansible-local-3889K3jTQT/ansible-tmp-1556898750.89-125587640637833/ /home/ataylor/.ansible/tmp/ansible-local-3889K3jTQT/ansible-tmp-1556898750.89-125587640637833/AnsiballZ_nxos_facts.py &amp;&amp; sleep 0'
2019-05-03 10:52:31,091 p=3889 u=ataylor |    3902 1556898751.08703: in local.exec_command()
2019-05-03 10:52:31,092 p=3889 u=ataylor |    3902 1556898751.09235: opening command with Popen()
2019-05-03 10:52:31,133 p=3889 u=ataylor |    3902 1556898751.12744: done running command with Popen()
2019-05-03 10:52:31,141 p=3889 u=ataylor |    3902 1556898751.13825: getting output with communicate()
2019-05-03 10:52:31,190 p=3889 u=ataylor |    3902 1556898751.18933: done communicating
2019-05-03 10:52:31,192 p=3889 u=ataylor |    3902 1556898751.19122: done with local.exec_command()
2019-05-03 10:52:31,193 p=3889 u=ataylor |    3902 1556898751.19282: _low_level_execute_command() done: rc=0, stdout=, stderr=
2019-05-03 10:52:31,193 p=3889 u=ataylor |    3902 1556898751.19340: _low_level_execute_command(): starting
2019-05-03 10:52:31,194 p=3889 u=ataylor |    3902 1556898751.19410: _low_level_execute_command(): executing: /bin/sh -c '/usr/bin/python /home/ataylor/.ansible/tmp/ansible-local-3889K3jTQT/ansible-tmp-1556898750.89-125587640637833/AnsiballZ_nxos_facts.py &amp;&amp; sleep 0'
2019-05-03 10:52:31,195 p=3889 u=ataylor |    3902 1556898751.19524: in local.exec_command()
2019-05-03 10:52:31,196 p=3889 u=ataylor |    3902 1556898751.19614: opening command with Popen()
2019-05-03 10:52:31,231 p=3889 u=ataylor |    3902 1556898751.22851: done running command with Popen()
2019-05-03 10:52:31,233 p=3889 u=ataylor |    3902 1556898751.23220: getting output with communicate()
2019-05-03 10:52:42,174 p=3889 u=ataylor |    3901 1556898762.17137: done communicating
2019-05-03 10:52:42,175 p=3889 u=ataylor |    3901 1556898762.17454: done with local.exec_command()
2019-05-03 10:52:42,196 p=3889 u=ataylor |    3901 1556898762.17632: _low_level_execute_command() done: rc=1, stdout=, stderr=Traceback (most recent call last):
File "/home/ataylor/.ansible/tmp/ansible-local-3889K3jTQT/ansible-tmp-1556898749.55-206921865596234/AnsiballZ_nxos_facts.py", line 113, in <module>
_ansiballz_main()
File "/home/ataylor/.ansible/tmp/ansible-local-3889K3jTQT/ansible-tmp-1556898749.55-206921865596234/AnsiballZ_nxos_facts.py", line 105, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/ataylor/.ansible/tmp/ansible-local-3889K3jTQT/ansible-tmp-1556898749.55-206921865596234/AnsiballZ_nxos_facts.py", line 48, in invoke_module
imp.load_module('__main__', mod, module, MOD_DESC)
File "/tmp/ansible_nxos_facts_payload_7kJAzy/__main__.py", line 1003, in <module>
File "/tmp/ansible_nxos_facts_payload_7kJAzy/__main__.py", line 986, in main
File "/tmp/ansible_nxos_facts_payload_7kJAzy/__main__.py", line 753, in populate
File "/tmp/ansible_nxos_facts_payload_7kJAzy/__main__.py", line 884, in parse_module
IndexError: list index out of range

# Fixed code
def parse_module(self, data):
    objects = list()
    for line in data.splitlines():
        if line == "" or re.search(r"\b" + "Sw" + r"\b", line):
            break
        if line[0].isdigit():
            obj = {}
            match_port = re.search(r"\d\s*(\d*)", line, re.M)
            if match_port:
                obj["ports"] = match_port.group(1)

            match = re.search(r"\d\s*\d*\s*(.+)$", line, re.M)
            if match:
                l = match.group(1).split("  ")
                items = list()
                for item in l:
                    if item == "":
                        continue
                    items.append(item.strip())

                if items:
                    obj["type"] = items[0]
                    obj["model"] = items[1]
                    obj["status"] = items[-1]

            objects.append(obj)
    return objects