# Buggy code
def main():
    argument_spec = dict(
        interface=dict(
            required=False,
        ),
        admin_state=dict(default="up", choices=["up", "down"], required=False),
        description=dict(required=False, default=None),
        mode=dict(choices=["layer2", "layer3"], required=False),
        interface_type=dict(
            required=False, choices=["loopback", "portchannel", "svi", "nve"]
        ),
        ip_forward=dict(required=False, choices=["enable", "disable"]),
        fabric_forwarding_anycast_gateway=dict(required=False, type="bool"),
        state=dict(
            choices=["absent", "present", "default"], default="present", required=False
        ),
        include_defaults=dict(default=True),
        config=dict(),
        save=dict(type="bool", default=False),
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=[["interface", "interface_type"]],
        supports_check_mode=True,
    )

    warnings = list()
    check_args(module, warnings)

    results = dict(changed=False, warnings=warnings)

    interface = module.params["interface"]
    interface_type = module.params["interface_type"]
    admin_state = module.params["admin_state"]
    description = module.params["description"]
    mode = module.params["mode"]
    ip_forward = module.params["ip_forward"]
    fabric_forwarding_anycast_gateway = module.params[
        "fabric_forwarding_anycast_gateway"
    ]
    state = module.params["state"]

    if interface:
        interface = interface.lower()
        intf_type = get_interface_type(interface)
        normalized_interface = normalize_interface(interface)

        if normalized_interface == "Vlan1" and state == "absent":
            module.fail_json(msg="ERROR: CANNOT REMOVE VLAN 1!")

        if intf_type == "nve":
            if description or mode:
                module.fail_json(
                    msg="description and mode params are not "
                    "supported in this module. Use "
                    "nxos_vxlan_vtep instead."
                )
        if (ip_forward or fabric_forwarding_anycast_gateway) and intf_type != "svi":
            module.fail_json(
                msg="The ip_forward and "
                "fabric_forwarding_anycast_gateway features "
                " are only available for SVIs."
            )
        args = dict(
            interface=interface,
            admin_state=admin_state,
            description=description,
            mode=mode,
            ip_forward=ip_forward,
            fabric_forwarding_anycast_gateway=fabric_forwarding_anycast_gateway,
        )

        if intf_type == "unknown":
            module.fail_json(msg="unknown interface type found-1", interface=interface)

        existing, is_default = smart_existing(module, intf_type, normalized_interface)
        proposed = get_proposed(existing, normalized_interface, args)
    else:
        intf_type = normalized_interface = interface_type
        proposed = dict(interface_type=interface_type)

    commands = []
    if interface:
        delta = dict()

        if state == "absent":
            if intf_type in ["svi", "loopback", "portchannel", "nve"]:
                if is_default != "DNE":
                    cmds = ["no interface {0}".format(normalized_interface)]
                    commands.append(cmds)
            elif intf_type in ["ethernet"]:
                if is_default is False:
                    cmds = ["default interface {0}".format(normalized_interface)]
                    commands.append(cmds)
        elif state == "present":
            if not existing:
                cmds = get_interface_config_commands(
                    proposed, normalized_interface, existing
                )
                commands.append(cmds)
            else:
                delta = dict(set(proposed.items()).difference(existing.items()))
                if delta:
                    cmds = get_interface_config_commands(
                        delta, normalized_interface, existing
                    )
                    commands.append(cmds)
        elif state == "default":
            if is_default is False:
                cmds = ["default interface {0}".format(normalized_interface)]
                commands.append(cmds)
            elif is_default == "DNE":
                module.exit_json(
                    msg="interface you are trying to default does not exist"
                )
    elif interface_type:
        if state == "present":
            module.fail_json(
                msg="The interface_type param can be used only with state absent."
            )

        existing = get_interfaces_dict(module)[interface_type]
        cmds = get_interface_type_removed_cmds(existing)
        commands.append(cmds)

    cmds = flatten_list(commands)
    end_state = existing

    if cmds:
        if module.check_mode:
            module.exit_json(changed=True, commands=cmds)
        else:
            load_config(module, cmds)
            results["changed"] = True
            if module.params["interface"]:
                if delta.get("mode"):  # or delta.get('admin_state'):
                    # if the mode changes from L2 to L3, the admin state
                    # seems to change after the API call, so adding a second API
                    # call to ensure it's in the desired state.
                    admin_state = delta.get("admin_state") or admin_state
                    c1 = "interface {0}".format(normalized_interface)
                    c2 = get_admin_state(delta, normalized_interface, admin_state)
                    cmds2 = [c1, c2]
                    load_config(module, cmds2)
                    cmds.extend(cmds2)
                end_state, is_default = smart_existing(
                    module, intf_type, normalized_interface
                )
            else:
                end_state = get_interfaces_dict(module)[interface_type]
            cmds = [cmd for cmd in cmds if cmd != "configure"]

    results["commands"] = cmds

    module.exit_json(**results)


# Traceback (AttributeError)
me@UKTH-NB306:~/git/ansible-dci-mgmt $ ansible-playbook -i /usr/local/etc/ansible/hosts bug.yaml -vvvv
ansible-playbook 2.4.0
config file = None
configured module search path = [u'/Users/me/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible
executable location = /usr/local/bin/ansible-playbook
python version = 2.7.13 (default, Apr  4 2017, 08:47:57) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)]
No config file found; using defaults
setting up inventory plugins
Parsed /usr/local/etc/ansible/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/plugins/callback/__init__.pyc

PLAYBOOK: bug.yaml ***************************************************************************************************************************************************************************************************************************
1 plays in bug.yaml

PLAY [hgt_dci] *******************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/basic.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/__init__.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/collector.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/namespace.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/default_collectors.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/_text.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/pycompat24.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/six/__init__.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/six/_six.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/timeout.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/freebsd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/virtual/openbsd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/base.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/dragonfly.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/dragonfly.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/aix.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/aix.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/linux.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/platform.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/hpux.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/user.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/hurd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/other/facter.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/virtual/sunos.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/hpux.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/distribution.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/virtual/freebsd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/__init__.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/openbsd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/darwin.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/linux.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/sunos.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/sunos.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/apparmor.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/openbsd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/local.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/other/ohai.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/other/__init__.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/service_mgr.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/hurd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/virtual/hpux.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/fips.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/selinux.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/virtual/__init__.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/pkg_mgr.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/dns.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/virtual/base.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/darwin.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/virtual/dragonfly.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/ssh_pub_keys.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/__init__.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/__init__.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/lsb.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/date_time.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/virtual/netbsd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/base.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/cmdline.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/freebsd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/netbsd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/hardware/netbsd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/caps.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/env.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/virtual/linux.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/system/python.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/network/generic_bsd.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/virtual/sysctl.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/utils.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/facts/sysctl.py
Using module file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/modules/system/setup.py
<1.1.1.157> ESTABLISH LOCAL CONNECTION FOR USER: me
<1.1.1.157> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
Using module file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/modules/system/setup.py
<1.1.1.158> ESTABLISH LOCAL CONNECTION FOR USER: me
<1.1.1.158> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<1.1.1.157> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-263804456879355 `" &amp;&amp; echo ansible-tmp-1499553151.25-263804456879355="` echo /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-263804456879355 `" ) &amp;&amp; sleep 0'
<1.1.1.158> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-98783112996400 `" &amp;&amp; echo ansible-tmp-1499553151.25-98783112996400="` echo /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-98783112996400 `" ) &amp;&amp; sleep 0'
<1.1.1.157> PUT /var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/tmpwQ8UT1 TO /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-263804456879355/setup.py
<1.1.1.158> PUT /var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/tmpgwvJOf TO /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-98783112996400/setup.py
<1.1.1.157> EXEC /bin/sh -c 'chmod u+x /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-263804456879355/ /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-263804456879355/setup.py &amp;&amp; sleep 0'
<1.1.1.158> EXEC /bin/sh -c 'chmod u+x /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-98783112996400/ /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-98783112996400/setup.py &amp;&amp; sleep 0'
<1.1.1.157> EXEC /bin/sh -c '/usr/bin/python /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-263804456879355/setup.py; rm -rf "/Users/me/.ansible/tmp/ansible-tmp-1499553151.25-263804456879355/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
<1.1.1.158> EXEC /bin/sh -c '/usr/bin/python /Users/me/.ansible/tmp/ansible-tmp-1499553151.25-98783112996400/setup.py; rm -rf "/Users/me/.ansible/tmp/ansible-tmp-1499553151.25-98783112996400/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
ok: [1.1.1.157]
ok: [1.1.1.158]
META: ran handlers

TASK [ENSURE PORT IS LAYER 2] ****************************************************************************************************************************************************************************************************************
task path: /Users/me/git/ansible-dci-mgmt/bug.yaml:17
<1.1.1.157> connection transport is nxapi
<1.1.1.158> connection transport is nxapi
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/basic.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/nxos.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/_text.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/pycompat24.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/six/__init__.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/six/_six.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/connection.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/network_common.py
Using module_utils file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/module_utils/urls.py
Using module file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/modules/network/nxos/nxos_interface.py
<1.1.1.157> ESTABLISH LOCAL CONNECTION FOR USER: me
<1.1.1.157> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
Using module file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/modules/network/nxos/nxos_interface.py
<1.1.1.158> ESTABLISH LOCAL CONNECTION FOR USER: me
<1.1.1.158> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<1.1.1.158> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-56984133901904 `" &amp;&amp; echo ansible-tmp-1499553152.88-56984133901904="` echo /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-56984133901904 `" ) &amp;&amp; sleep 0'
<1.1.1.157> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-28761587341096 `" &amp;&amp; echo ansible-tmp-1499553152.88-28761587341096="` echo /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-28761587341096 `" ) &amp;&amp; sleep 0'
<1.1.1.158> PUT /var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/tmpXYXrSD TO /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-56984133901904/nxos_interface.py
<1.1.1.157> PUT /var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/tmpt80d20 TO /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-28761587341096/nxos_interface.py
<1.1.1.158> EXEC /bin/sh -c 'chmod u+x /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-56984133901904/ /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-56984133901904/nxos_interface.py &amp;&amp; sleep 0'
<1.1.1.157> EXEC /bin/sh -c 'chmod u+x /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-28761587341096/ /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-28761587341096/nxos_interface.py &amp;&amp; sleep 0'
<1.1.1.158> EXEC /bin/sh -c '/usr/bin/python /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-56984133901904/nxos_interface.py; rm -rf "/Users/me/.ansible/tmp/ansible-tmp-1499553152.88-56984133901904/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
<1.1.1.157> EXEC /bin/sh -c '/usr/bin/python /Users/me/.ansible/tmp/ansible-tmp-1499553152.88-28761587341096/nxos_interface.py; rm -rf "/Users/me/.ansible/tmp/ansible-tmp-1499553152.88-28761587341096/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_8X3hEp/ansible_module_nxos_interface.py", line 712, in <module>
main()
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_8X3hEp/ansible_module_nxos_interface.py", line 638, in main
existing, is_default = smart_existing(module, intf_type, normalized_interface)
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_8X3hEp/ansible_module_nxos_interface.py", line 535, in smart_existing
all_interfaces = get_interfaces_dict(module)
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_8X3hEp/ansible_module_nxos_interface.py", line 391, in get_interfaces_dict
interface_list = body.get('TABLE_interface')['ROW_interface']
AttributeError: 'unicode' object has no attribute 'get'

failed: [1.1.1.157] (item=Eth1/11) => {
"changed": false,
"failed": true,
"item": "Eth1/11",
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_8X3hEp/ansible_module_nxos_interface.py\", line 712, in <module>\n    main()\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_8X3hEp/ansible_module_nxos_interface.py\", line 638, in main\n    existing, is_default = smart_existing(module, intf_type, normalized_interface)\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_8X3hEp/ansible_module_nxos_interface.py\", line 535, in smart_existing\n    all_interfaces = get_interfaces_dict(module)\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_8X3hEp/ansible_module_nxos_interface.py\", line 391, in get_interfaces_dict\n    interface_list = body.get('TABLE_interface')['ROW_interface']\nAttributeError: 'unicode' object has no attribute 'get'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}
<1.1.1.157> connection transport is nxapi
The full traceback is:
Traceback (most recent call last):
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_Pr3N93/ansible_module_nxos_interface.py", line 712, in <module>
main()
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_Pr3N93/ansible_module_nxos_interface.py", line 638, in main
existing, is_default = smart_existing(module, intf_type, normalized_interface)
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_Pr3N93/ansible_module_nxos_interface.py", line 535, in smart_existing
all_interfaces = get_interfaces_dict(module)
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_Pr3N93/ansible_module_nxos_interface.py", line 391, in get_interfaces_dict
interface_list = body.get('TABLE_interface')['ROW_interface']
AttributeError: 'unicode' object has no attribute 'get'

failed: [1.1.1.158] (item=Eth1/11) => {
"changed": false,
"failed": true,
"item": "Eth1/11",
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_Pr3N93/ansible_module_nxos_interface.py\", line 712, in <module>\n    main()\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_Pr3N93/ansible_module_nxos_interface.py\", line 638, in main\n    existing, is_default = smart_existing(module, intf_type, normalized_interface)\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_Pr3N93/ansible_module_nxos_interface.py\", line 535, in smart_existing\n    all_interfaces = get_interfaces_dict(module)\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_Pr3N93/ansible_module_nxos_interface.py\", line 391, in get_interfaces_dict\n    interface_list = body.get('TABLE_interface')['ROW_interface']\nAttributeError: 'unicode' object has no attribute 'get'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}
Using module file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/modules/network/nxos/nxos_interface.py
<1.1.1.158> connection transport is nxapi
<1.1.1.157> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
Using module file /usr/local/lib/python2.7/site-packages/ansible-2.4.0-py2.7.egg/ansible/modules/network/nxos/nxos_interface.py
<1.1.1.158> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<1.1.1.157> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-219207280744829 `" &amp;&amp; echo ansible-tmp-1499553155.52-219207280744829="` echo /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-219207280744829 `" ) &amp;&amp; sleep 0'
<1.1.1.158> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-24952773001123 `" &amp;&amp; echo ansible-tmp-1499553155.52-24952773001123="` echo /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-24952773001123 `" ) &amp;&amp; sleep 0'
<1.1.1.157> PUT /var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/tmpuJqAcm TO /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-219207280744829/nxos_interface.py
<1.1.1.158> PUT /var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/tmptooEAE TO /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-24952773001123/nxos_interface.py
<1.1.1.158> EXEC /bin/sh -c 'chmod u+x /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-24952773001123/ /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-24952773001123/nxos_interface.py &amp;&amp; sleep 0'
<1.1.1.157> EXEC /bin/sh -c 'chmod u+x /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-219207280744829/ /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-219207280744829/nxos_interface.py &amp;&amp; sleep 0'
<1.1.1.158> EXEC /bin/sh -c '/usr/bin/python /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-24952773001123/nxos_interface.py; rm -rf "/Users/me/.ansible/tmp/ansible-tmp-1499553155.52-24952773001123/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
<1.1.1.157> EXEC /bin/sh -c '/usr/bin/python /Users/me/.ansible/tmp/ansible-tmp-1499553155.52-219207280744829/nxos_interface.py; rm -rf "/Users/me/.ansible/tmp/ansible-tmp-1499553155.52-219207280744829/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_yTkiS2/ansible_module_nxos_interface.py", line 712, in <module>
main()
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_yTkiS2/ansible_module_nxos_interface.py", line 638, in main
existing, is_default = smart_existing(module, intf_type, normalized_interface)
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_yTkiS2/ansible_module_nxos_interface.py", line 535, in smart_existing
all_interfaces = get_interfaces_dict(module)
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_yTkiS2/ansible_module_nxos_interface.py", line 391, in get_interfaces_dict
interface_list = body.get('TABLE_interface')['ROW_interface']
AttributeError: 'unicode' object has no attribute 'get'

failed: [1.1.1.158] (item=Eth1/12) => {
"changed": false,
"failed": true,
"item": "Eth1/12",
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_yTkiS2/ansible_module_nxos_interface.py\", line 712, in <module>\n    main()\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_yTkiS2/ansible_module_nxos_interface.py\", line 638, in main\n    existing, is_default = smart_existing(module, intf_type, normalized_interface)\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_yTkiS2/ansible_module_nxos_interface.py\", line 535, in smart_existing\n    all_interfaces = get_interfaces_dict(module)\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_yTkiS2/ansible_module_nxos_interface.py\", line 391, in get_interfaces_dict\n    interface_list = body.get('TABLE_interface')['ROW_interface']\nAttributeError: 'unicode' object has no attribute 'get'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}
The full traceback is:
Traceback (most recent call last):
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_tmUHW6/ansible_module_nxos_interface.py", line 712, in <module>
main()
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_tmUHW6/ansible_module_nxos_interface.py", line 638, in main
existing, is_default = smart_existing(module, intf_type, normalized_interface)
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_tmUHW6/ansible_module_nxos_interface.py", line 535, in smart_existing
all_interfaces = get_interfaces_dict(module)
File "/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_tmUHW6/ansible_module_nxos_interface.py", line 391, in get_interfaces_dict
interface_list = body.get('TABLE_interface')['ROW_interface']
AttributeError: 'unicode' object has no attribute 'get'

failed: [1.1.1.157] (item=Eth1/12) => {
"changed": false,
"failed": true,
"item": "Eth1/12",
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_tmUHW6/ansible_module_nxos_interface.py\", line 712, in <module>\n    main()\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_tmUHW6/ansible_module_nxos_interface.py\", line 638, in main\n    existing, is_default = smart_existing(module, intf_type, normalized_interface)\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_tmUHW6/ansible_module_nxos_interface.py\", line 535, in smart_existing\n    all_interfaces = get_interfaces_dict(module)\n  File \"/var/folders/cw/v5xqyw_57bg56tq3vgjnjgqjllcqpz/T/ansible_tmUHW6/ansible_module_nxos_interface.py\", line 391, in get_interfaces_dict\n    interface_list = body.get('TABLE_interface')['ROW_interface']\nAttributeError: 'unicode' object has no attribute 'get'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}
to retry, use: --limit @/Users/me/git/ansible-dci-mgmt/bug.retry

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
1.1.1.157             : ok=1    changed=0    unreachable=0    failed=1
1.1.1.158             : ok=1    changed=0    unreachable=0    failed=1

# Fixed code
def main():
    argument_spec = dict(
        interface=dict(
            required=False,
        ),
        admin_state=dict(default="up", choices=["up", "down"], required=False),
        description=dict(required=False, default=None),
        mode=dict(choices=["layer2", "layer3"], required=False),
        interface_type=dict(
            required=False, choices=["loopback", "portchannel", "svi", "nve"]
        ),
        ip_forward=dict(required=False, choices=["enable", "disable"]),
        fabric_forwarding_anycast_gateway=dict(required=False, type="bool"),
        state=dict(
            choices=["absent", "present", "default"], default="present", required=False
        ),
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(
        argument_spec=argument_spec,
        mutually_exclusive=[["interface", "interface_type"]],
        supports_check_mode=True,
    )

    warnings = list()
    check_args(module, warnings)

    results = dict(changed=False, warnings=warnings)

    interface = module.params["interface"]
    interface_type = module.params["interface_type"]
    admin_state = module.params["admin_state"]
    description = module.params["description"]
    mode = module.params["mode"]
    ip_forward = module.params["ip_forward"]
    fabric_forwarding_anycast_gateway = module.params[
        "fabric_forwarding_anycast_gateway"
    ]
    state = module.params["state"]

    if interface:
        interface = interface.lower()
        intf_type = get_interface_type(interface)
        normalized_interface = normalize_interface(interface)

        if normalized_interface == "Vlan1" and state == "absent":
            module.fail_json(msg="ERROR: CANNOT REMOVE VLAN 1!")

        if intf_type == "nve":
            if description or mode:
                module.fail_json(
                    msg="description and mode params are not "
                    "supported in this module. Use "
                    "nxos_vxlan_vtep instead."
                )
        if (ip_forward or fabric_forwarding_anycast_gateway) and intf_type != "svi":
            module.fail_json(
                msg="The ip_forward and "
                "fabric_forwarding_anycast_gateway features "
                " are only available for SVIs."
            )
        args = dict(
            interface=interface,
            admin_state=admin_state,
            description=description,
            mode=mode,
            ip_forward=ip_forward,
            fabric_forwarding_anycast_gateway=fabric_forwarding_anycast_gateway,
        )

        if intf_type == "unknown":
            module.fail_json(msg="unknown interface type found-1", interface=interface)

        existing, is_default = smart_existing(module, intf_type, normalized_interface)
        proposed = get_proposed(existing, normalized_interface, args)
    else:
        intf_type = normalized_interface = interface_type
        proposed = dict(interface_type=interface_type)

    commands = []
    if interface:
        delta = dict()

        if state == "absent":
            if intf_type in ["svi", "loopback", "portchannel", "nve"]:
                if is_default != "DNE":
                    cmds = ["no interface {0}".format(normalized_interface)]
                    commands.append(cmds)
            elif intf_type in ["ethernet"]:
                if is_default is False:
                    cmds = ["default interface {0}".format(normalized_interface)]
                    commands.append(cmds)
        elif state == "present":
            if not existing:
                cmds = get_interface_config_commands(
                    proposed, normalized_interface, existing
                )
                commands.append(cmds)
            else:
                delta = dict(set(proposed.items()).difference(existing.items()))
                if delta:
                    cmds = get_interface_config_commands(
                        delta, normalized_interface, existing
                    )
                    commands.append(cmds)
        elif state == "default":
            if is_default is False:
                cmds = ["default interface {0}".format(normalized_interface)]
                commands.append(cmds)
            elif is_default == "DNE":
                module.exit_json(
                    msg="interface you are trying to default does not exist"
                )
    elif interface_type:
        if state == "present":
            module.fail_json(
                msg="The interface_type param can be used only with state absent."
            )

        existing = get_interfaces_dict(module)[interface_type]
        cmds = get_interface_type_removed_cmds(existing)
        commands.append(cmds)

    cmds = flatten_list(commands)
    end_state = existing

    if cmds:
        if module.check_mode:
            module.exit_json(changed=True, commands=cmds)
        else:
            load_config(module, cmds)
            results["changed"] = True
            if module.params["interface"]:
                if delta.get("mode"):
                    # if the mode changes from L2 to L3, the admin state
                    # seems to change after the API call, so adding a second API
                    # call to ensure it's in the desired state.
                    admin_state = delta.get("admin_state") or admin_state
                    c1 = "interface {0}".format(normalized_interface)
                    c2 = get_admin_state(delta, normalized_interface, admin_state)
                    cmds2 = [c1, c2]
                    load_config(module, cmds2)
                    cmds.extend(cmds2)
                end_state, is_default = smart_existing(
                    module, intf_type, normalized_interface
                )
            else:
                end_state = get_interfaces_dict(module)[interface_type]
            cmds = [cmd for cmd in cmds if cmd != "configure"]

    results["commands"] = cmds

    module.exit_json(**results)