# Buggy code
def map_obj_to_commands(updates, module):
    commands = list()
    want, have = updates
    state = module.params["state"]

    if state == "absent" and have.get("text"):
        if isinstance(have["text"], str):
            commands.append("no banner %s" % module.params["banner"])
        elif have["text"].get("loginBanner") or have["text"].get("motd"):
            commands.append({"cmd": "no banner %s" % module.params["banner"]})

    elif state == "present":
        if isinstance(have["text"], str):
            if want["text"] != have["text"]:
                commands.append("banner %s" % module.params["banner"])
                commands.extend(want["text"].strip().split("\n"))
                commands.append("EOF")
        else:
            have_text = have["text"].get("loginBanner") or have["text"].get("motd")
            if have_text:
                have_text = have_text.strip()

            if to_text(want["text"]) != have_text or not have_text:
                # For EAPI we need to construct a dict with cmd/input
                # key/values for the banner
                commands.append(
                    {
                        "cmd": "banner %s" % module.params["banner"],
                        "input": want["text"].strip("\n"),
                    }
                )

    return commands


# Traceback (AttributeError)
The full traceback is:
Traceback (most recent call last):
File "/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py", line 197, in <module>
main()
File "/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py", line 183, in main
commands = map_obj_to_commands((want, have), module)
File "/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py", line 115, in map_obj_to_commands
have_text = have['text'].get('loginBanner') or have['text'].get('motd')
AttributeError: 'unicode' object has no attribute 'get'

fatal: [veos01]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py\", line 197, in <module>\n    main()\n  File \"/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py\", line 183, in main\n    commands = map_obj_to_commands((want, have), module)\n  File \"/var/folders/bp/pf3l672j2s79st6d4ps6q7200000gn/T/ansible__CH5Gb/ansible_module_eos_banner.py\", line 115, in map_obj_to_commands\n    have_text = have['text'].get('loginBanner') or have['text'].get('motd')\nAttributeError: 'unicode' object has no attribute 'get'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def map_obj_to_commands(updates, module):
    commands = list()
    want, have = updates
    state = module.params["state"]

    if state == "absent" and have.get("text"):
        if isinstance(have["text"], str):
            commands.append("no banner %s" % module.params["banner"])
        elif have["text"].get("loginBanner") or have["text"].get("motd"):
            commands.append({"cmd": "no banner %s" % module.params["banner"]})

    elif state == "present":
        if isinstance(have["text"], string_types):
            if want["text"] != have["text"]:
                commands.append("banner %s" % module.params["banner"])
                commands.extend(want["text"].strip().split("\n"))
                commands.append("EOF")
        else:
            have_text = have["text"].get("loginBanner") or have["text"].get("motd")
            if have_text:
                have_text = have_text.strip()

            if to_text(want["text"]) != have_text or not have_text:
                # For EAPI we need to construct a dict with cmd/input
                # key/values for the banner
                commands.append(
                    {
                        "cmd": "banner %s" % module.params["banner"],
                        "input": want["text"].strip("\n"),
                    }
                )

    return commands