# Buggy code
def _create_switchport_data(self, if_name, if_data):
    return {
        "name": if_name,
        "mode": self.get_config_attr(if_data, "Mode"),
        "access_vlan": self.get_access_vlan(if_data),
        "trunk_allowed_vlans": self.get_allowed_vlans(if_data),
    }


# 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 _create_switchport_data(self, if_name, if_data):
    if self._os_version >= self.ONYX_API_VERSION:
        if_data = if_data[0]

    return {
        "name": if_name,
        "mode": self.get_config_attr(if_data, "Mode"),
        "access_vlan": self.get_access_vlan(if_data),
        "trunk_allowed_vlans": self.get_allowed_vlans(if_data),
    }