# Buggy code
def main():
    argument_spec = dict(
        flush_routes=dict(type="bool"),
        enforce_rtr_alert=dict(type="bool"),
        restart=dict(type="bool", default=False),
        state=dict(choices=["present", "default"], default="present"),
        include_defaults=dict(default=False),
        config=dict(),
        save=dict(type="bool", default=False),
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

    warnings = list()
    check_args(module, warnings)

    state = module.params["state"]
    restart = module.params["restart"]

    if state == "default" and (
        module.params["flush_routes"] is not None
        or module.params["enforce_rtr_alert"] is not None
    ):
        module.fail_json(msg="When state=default other params have no effect.")

    args = [
        "flush_routes",
        "enforce_rtr_alert",
    ]

    existing = invoke("get_existing", module, args)
    end_state = existing

    proposed = dict(
        (k, v) for k, v in module.params.items() if v is not None and k in args
    )

    proposed_args = proposed.copy()
    if state == "default":
        proposed_args = dict((k, False) for k in args)

    result = {}
    if (
        state == "present"
        or (state == "default" and True in existing.values())
        or restart
    ):
        candidate = CustomNetworkConfig(indent=3)
        invoke("get_commands", module, existing, proposed_args, candidate)
        response = load_config(module, candidate)
        result.update(response)

    else:
        result["updates"] = []

    if restart:
        proposed["restart"] = restart
    result["connected"] = module.connected
    if module._verbosity > 0:
        end_state = invoke("get_existing", module, args)
        result["end_state"] = end_state
        result["existing"] = existing
        result["proposed"] = proposed

    result["warnings"] = warnings

    module.exit_json(**result)


# Traceback (AttributeError)
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_D0RHMz/ansible_module_nxos_igmp.py", line 257, in <module>
main()
File "/tmp/ansible_D0RHMz/ansible_module_nxos_igmp.py", line 244, in main
result['connected'] = module.connected
AttributeError: 'AnsibleModule' object has no attribute 'connected'
FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_D0RHMz/ansible_module_nxos_igmp.py\", line 257, in <module>\n    main()\n  File \"/tmp/ansible_D0RHMz/ansible_module_nxos_igmp.py\", line 244, in main\n    result['connected'] = module.connected\nAttributeError: 'AnsibleModule' object has no attribute 'connected'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def main():
    argument_spec = dict(
        flush_routes=dict(type="bool"),
        enforce_rtr_alert=dict(type="bool"),
        restart=dict(type="bool", default=False),
        state=dict(choices=["present", "default"], default="present"),
        include_defaults=dict(default=False),
        config=dict(),
        save=dict(type="bool", default=False),
    )

    argument_spec.update(nxos_argument_spec)

    module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)

    warnings = list()
    check_args(module, warnings)

    current = get_current(module)
    desired = get_desired(module)

    state = module.params["state"]
    restart = module.params["restart"]

    commands = list()

    if state == "default":
        if current["flush_routes"]:
            commands.append("no ip igmp flush-routes")
        if current["enforce_rtr_alert"]:
            commands.append("no ip igmp enforce-router-alert")

    elif state == "present":
        if desired["flush_routes"] and not current["flush_routes"]:
            commands.append("ip igmp flush-routes")
        if desired["enforce_rtr_alert"] and not current["enforce_rtr_alert"]:
            commands.append("ip igmp enforce-router-alert")

    result = {"changed": False, "updates": commands, "warnings": warnings}

    if commands:
        if not module.check_mode:
            load_config(module, commands)
        result["changed"] = True

    if module.params["restart"]:
        run_commands(module, "restart igmp")

    module.exit_json(**result)