# Buggy code
def parse_fan_info(self, data):
    objects = list()

    for l in data.splitlines():
        if "-----------------" in l or "Status" in l:
            continue
        line = l.split()
        if len(line) > 1:
            obj = {}
            obj["name"] = line[0]
            obj["model"] = line[1]
            obj["hw_ver"] = line[-2]
            obj["status"] = line[-1]
            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_fan_info(self, data):
    objects = list()

    for l in data.splitlines():
        if "-----------------" in l or "Status" in l:
            continue
        line = l.split()
        if len(line) > 1:
            obj = {}
            if re.search(r"Direction", data, re.M):
                obj["direction"] = line[-2]
            obj["name"] = line[0]
            obj["model"] = line[1]
            obj["hw_ver"] = line[2]
            obj["status"] = line[-1]
            objects.append(obj)
    return objects