# Buggy code
def main():
    """main entry point for module execution"""
    argument_spec = dict(
        banner=dict(required=True, choices=["login", "motd"]),
        text=dict(),
        state=dict(default="present", choices=["present", "absent"]),
    )

    required_if = [("state", "present", ("text",))]

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

    result = {"changed": False}

    want = map_params_to_obj(module)
    have = map_config_to_obj(module)

    commands = map_obj_to_commands((want, have), module)
    result["commands"] = commands

    if commands:
        commit = not module.check_mode
        response = load_config(module, commands, commit=commit)
        if response.get("diff") and module._diff:
            result["diff"] = {"prepared": response.get("diff")}
        result["session_name"] = response.get("session")
        result["changed"] = True

    module.exit_json(**result)


# Traceback (KeyError)
16316 1488225144.93538: in local.exec_command()
<veos01> EXEC /bin/sh -c 'python /home/johnb/.ansible/tmp/ansible-tmp-1488225144.91-133299287621947/eos_banner.py; rm -rf "/home/johnb/.ansible/tmp/ansible-tmp-1488225144.91-133299287621947/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
16316 1488225144.93550: opening command with Popen()
16316 1488225144.93824: done running command with Popen()
16316 1488225144.93869: getting output with communicate()
16316 1488225145.11188: done communicating
16316 1488225145.11215: done with local.exec_command()
16316 1488225145.11232: _low_level_execute_command() done: rc=0, stdout=, stderr=Traceback (most recent call last):
File "/tmp/ansible_rdVUTA/ansible_module_eos_banner.py", line 161, in <module>
main()
File "/tmp/ansible_rdVUTA/ansible_module_eos_banner.py", line 145, in main
have = map_config_to_obj(module)
File "/tmp/ansible_rdVUTA/ansible_module_eos_banner.py", line 109, in map_config_to_obj
output = run_commands(module, ['show banner %s' % module.params['banner']])
File "/tmp/ansible_rdVUTA/ansible_modlib.zip/ansible/module_utils/eos.py", line 442, in run_commands
File "/tmp/ansible_rdVUTA/ansible_modlib.zip/ansible/module_utils/eos.py", line 79, in get_connection
KeyError: 'transport'

[WARNING]: Removed unexpected internal key in module return: _ansible_parsed = False

# Fixed code
def main():
    """main entry point for module execution"""
    argument_spec = dict(
        banner=dict(required=True, choices=["login", "motd"]),
        text=dict(),
        state=dict(default="present", choices=["present", "absent"]),
    )

    argument_spec.update(eos_argument_spec)

    required_if = [("state", "present", ("text",))]

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

    warnings = list()
    check_args(module, warnings)

    result = {"changed": False}
    if warnings:
        result["warnings"] = warnings

    want = map_params_to_obj(module)
    have = map_config_to_obj(module)

    commands = map_obj_to_commands((want, have), module)
    result["commands"] = commands

    if commands:
        commit = not module.check_mode
        response = load_config(module, commands, commit=commit)
        if response.get("diff") and module._diff:
            result["diff"] = {"prepared": response.get("diff")}
        result["session_name"] = response.get("session")
        result["changed"] = True

    module.exit_json(**result)