# Buggy code
def load_current_config(self):
    # called in base class in run function
    self._current_config = dict()
    switchports_config = self._get_switchport_config()
    if not switchports_config:
        return
    for if_name, if_data in iteritems(switchports_config):
        self._current_config[if_name] = self._create_switchport_data(if_name, 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 load_current_config(self):
    # called in base class in run function
    self._os_version = self._get_os_version()
    self._current_config = dict()
    switchports_config = self._get_switchport_config()
    if not switchports_config:
        return
    for if_name, if_data in iteritems(switchports_config):
        self._current_config[if_name] = self._create_switchport_data(if_name, if_data)