# Buggy code
def execute_show_command(command, module, command_type="cli_show"):
    if command_type == "cli_show_ascii":
        cmds = [
            {
                "command": command,
                "output": "text",
            }
        ]
    else:
        cmds = [command]

    return run_commands(module, cmds)


# Traceback (TypeError)
TASK [nxos_igmp_interface : Configure igmp interface with default value] **********************************************************************************
task path: /root/agents-ci/ansible/test/integration/targets/nxos_igmp_interface/tests/common/sanity.yaml:26
<n9k-xxx.example.com> connection transport is cli
<n9k-xxx.example.com> using connection plugin network_cli
<n9k-xxx.example.com> socket_path: /root/.ansible/pc/3747b7341f
Using module file /root/agents-ci/ansible/lib/ansible/modules/network/nxos/nxos_igmp_interface.py
<n9k-xxx.example.com> ESTABLISH LOCAL CONNECTION FOR USER: root
<n9k-xxx.example.com> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<n9k-xxx.example.com> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1503412190.68-270476304915912 `" &amp;&amp; echo ansible-tmp-1503412190.68-270476304915912="` echo /root/.ansible/tmp/ansible-tmp-1503412190.68-270476304915912 `" ) &amp;&amp; sleep 0'
<n9k-xxx.example.com> PUT /tmp/tmpDBeP34 TO /root/.ansible/tmp/ansible-tmp-1503412190.68-270476304915912/nxos_igmp_interface.py
<n9k-xxx.example.com> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1503412190.68-270476304915912/ /root/.ansible/tmp/ansible-tmp-1503412190.68-270476304915912/nxos_igmp_interface.py &amp;&amp; sleep 0'
<n9k-xxx.example.com> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1503412190.68-270476304915912/nxos_igmp_interface.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1503412190.68-270476304915912/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_5eYN_h/ansible_module_nxos_igmp_interface.py", line 697, in <module>
main()
File "/tmp/ansible_5eYN_h/ansible_module_nxos_igmp_interface.py", line 558, in main
if get_interface_mode(interface, intf_type, module) == 'layer2':
File "/tmp/ansible_5eYN_h/ansible_module_nxos_igmp_interface.py", line 263, in get_interface_mode
interface_table = body['TABLE_interface']['ROW_interface']
TypeError: string indices must be integers, not str
FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_5eYN_h/ansible_module_nxos_igmp_interface.py\", line 697, in <module>\n    main()\n  File \"/tmp/ansible_5eYN_h/ansible_module_nxos_igmp_interface.py\", line 558, in main\n    if get_interface_mode(interface, intf_type, module) == 'layer2':\n  File \"/tmp/ansible_5eYN_h/ansible_module_nxos_igmp_interface.py\", line 263, in get_interface_mode\n    interface_table = body['TABLE_interface']['ROW_interface']\nTypeError: string indices must be integers, not str\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def execute_show_command(command, module, command_type="cli_show"):
    if command_type == "cli_show_ascii":
        cmds = [
            {
                "command": command,
                "output": "text",
            }
        ]
    else:
        cmds = [
            {
                "command": command,
                "output": "json",
            }
        ]

    return run_commands(module, cmds)