# Buggy code
def _parse_interfaces_config(self, if_type, if_config):
    ipaddr_attr = self.IP_ADDR_ATTR_MAP[if_type]
    for if_data in if_config:
        if_name = self.get_config_attr(if_data, "header")
        regex = self.IF_TYPE_MAP[if_type]
        match = regex.match(if_name)
        if not match:
            continue
        ipv4 = self.get_config_attr(if_data, ipaddr_attr)
        if ipv4:
            ipv4 = ipv4.replace(" ", "")
        ipv6 = self.get_config_attr(if_data, "IPv6 address(es)")
        if ipv6:
            ipv6 = ipv6.replace("[primary]", "")
            ipv6 = ipv6.strip()
        if_id = match.group(1)
        switchport = self.get_config_attr(if_data, "Switchport mode")
        if_obj = {
            "name": if_name,
            "if_id": if_id,
            "if_type": if_type,
            "ipv4": ipv4,
            "ipv6": ipv6,
            "switchport": switchport,
        }
        self._current_config[if_name] = if_obj


# Traceback (AttributeError)
# ansible-playbook test1_playbook.yml -vvv
ansible-playbook 2.5.3
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
Using /etc/ansible/ansible.cfg as config file
Parsed /etc/ansible/hosts inventory source with ini plugin

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

PLAY [lab2700] **********************************************************************************************************************************************************************************************
META: ran handlers

TASK [Conf Network INt] *************************************************************************************************************************************************************************************
task path: /etc/ansible/test1_playbook.yml:7
Wednesday 18 July 2018  12:30:37 +0200 (0:00:00.098)       0:00:00.098 ********
Using module file /usr/lib/python2.7/site-packages/ansible/modules/network/onyx/onyx_l2_interface.py
<r-ethernet-sw241> ESTABLISH LOCAL CONNECTION FOR USER: root
<r-ethernet-sw241> EXEC /bin/sh -c '/usr/bin/python &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_Y5F_Jl/ansible_module_onyx_l2_interface.py", line 284, in <module>
main()
File "/tmp/ansible_Y5F_Jl/ansible_module_onyx_l2_interface.py", line 280, in main
OnyxL2InterfaceModule.main()
File "/tmp/ansible_Y5F_Jl/ansible_modlib.zip/ansible/module_utils/network/onyx/onyx.py", line 240, in main
File "/tmp/ansible_Y5F_Jl/ansible_modlib.zip/ansible/module_utils/network/onyx/onyx.py", line 218, in run
File "/tmp/ansible_Y5F_Jl/ansible_module_onyx_l2_interface.py", line 183, in load_current_config
self._create_switchport_data(if_name, if_data)
File "/tmp/ansible_Y5F_Jl/ansible_module_onyx_l2_interface.py", line 167, in _create_switchport_data
'mode': self.get_config_attr(if_data, 'Mode'),
File "/tmp/ansible_Y5F_Jl/ansible_modlib.zip/ansible/module_utils/network/onyx/onyx.py", line 194, in get_config_attr
AttributeError: 'list' object has no attribute 'get'

fatal: [lab2700]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_Y5F_Jl/ansible_module_onyx_l2_interface.py\", line 284, in <module>\n    main()\n  File \"/tmp/ansible_Y5F_Jl/ansible_module_onyx_l2_interface.py\", line 280, in main\n    OnyxL2InterfaceModule.main()\n  File \"/tmp/ansible_Y5F_Jl/ansible_modlib.zip/ansible/module_utils/network/onyx/onyx.py\", line 240, in main\n  File \"/tmp/ansible_Y5F_Jl/ansible_modlib.zip/ansible/module_utils/network/onyx/onyx.py\", line 218, in run\n  File \"/tmp/ansible_Y5F_Jl/ansible_module_onyx_l2_interface.py\", line 183, in load_current_config\n    self._create_switchport_data(if_name, if_data)\n  File \"/tmp/ansible_Y5F_Jl/ansible_module_onyx_l2_interface.py\", line 167, in _create_switchport_data\n    'mode': self.get_config_attr(if_data, 'Mode'),\n  File \"/tmp/ansible_Y5F_Jl/ansible_modlib.zip/ansible/module_utils/network/onyx/onyx.py\", line 194, in get_config_attr\nAttributeError: 'list' object has no attribute 'get'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}

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

Wednesday 18 July 2018  12:30:42 +0200 (0:00:04.811)       0:00:04.909 ********
===============================================================================
Conf Network INt ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 4.81s
/etc/ansible/test1_playbook.yml:7 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

# Fixed code
def _parse_interfaces_config(self, if_type, if_config):
    if self._os_version < self.ONYX_API_VERSION:
        for if_data in if_config:
            if_name = self.get_config_attr(if_data, "header")
            self._get_if_attributes(if_type, if_name, if_data)
    else:
        for if_config_item in if_config:
            for if_name, if_data in iteritems(if_config_item):
                if_data = if_data[0]
                self._get_if_attributes(if_type, if_name, if_data)