# Buggy code
def delete_cluster(module, redshift):
    """
    Delete a cluster.

    module: Ansible module object
    redshift: authenticated redshift connection object
    """

    identifier = module.params.get("identifier")
    wait = module.params.get("wait")
    wait_timeout = module.params.get("wait_timeout")
    skip_final_cluster_snapshot = module.params.get("skip_final_cluster_snapshot")
    final_cluster_snapshot_identifier = module.params.get(
        "final_cluster_snapshot_identifier"
    )

    try:
        redshift.delete_cluster(
            identifier, skip_final_cluster_snapshot, final_cluster_snapshot_identifier
        )
    except boto.exception.JSONResponseError as e:
        module.fail_json(msg=str(e))

    if wait:
        try:
            wait_timeout = time.time() + wait_timeout
            resource = redshift.describe_clusters(identifier)[
                "DescribeClustersResponse"
            ]["DescribeClustersResult"]["Clusters"][0]

            while (
                wait_timeout > time.time() and resource["ClusterStatus"] != "deleting"
            ):
                time.sleep(5)
                if wait_timeout <= time.time():
                    module.fail_json(
                        msg="Timeout waiting for resource %s" % resource.id
                    )

                resource = redshift.describe_clusters(identifier)[
                    "DescribeClustersResponse"
                ]["DescribeClustersResult"]["Clusters"][0]

        except boto.exception.JSONResponseError as e:
            module.fail_json(msg=str(e))

    return (True, {})


# Traceback (TypeError)
TASK [Launch Redshift instances] ******************************************************************************************************************************************************************************
task path: /home/rdriutti/code/ansible/create-cluster.yml:6
Using module file /home/rdriutti/code/ansible/lib/ansible/modules/cloud/amazon/redshift.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: rdriutti
<localhost> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/rdriutti/.ansible/tmp/ansible-tmp-1520300144.74-278909426876762 `" &amp;&amp; echo ansible-tmp-1520300144.74-278909426876762="` echo /home/rdriutti/.ansible/tmp/ansible-tmp-1520300144.74-278909426876762 `" ) &amp;&amp; sleep 0'
<localhost> PUT /home/rdriutti/.ansible/tmp/ansible-local-18151rOE_gi/tmpX7AGbv TO /home/rdriutti/.ansible/tmp/ansible-tmp-1520300144.74-278909426876762/redshift.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/rdriutti/.ansible/tmp/ansible-tmp-1520300144.74-278909426876762/ /home/rdriutti/.ansible/tmp/ansible-tmp-1520300144.74-278909426876762/redshift.py &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /home/rdriutti/.ansible/tmp/ansible-tmp-1520300144.74-278909426876762/redshift.py &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/rdriutti/.ansible/tmp/ansible-tmp-1520300144.74-278909426876762/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_QpwK2x/ansible_module_redshift.py", line 515, in <module>
main()
File "/tmp/ansible_QpwK2x/ansible_module_redshift.py", line 500, in main
(changed, cluster) = create_cluster(module, conn)
File "/tmp/ansible_QpwK2x/ansible_module_redshift.py", line 298, in create_cluster
redshift.create_cluster(identifier, node_type, username, password, **params)
TypeError: create_cluster() got an unexpected keyword argument 'enhanced_vpc_routing'

fatal: [localhost -> localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_QpwK2x/ansible_module_redshift.py\", line 515, in <module>\n    main()\n  File \"/tmp/ansible_QpwK2x/ansible_module_redshift.py\", line 500, in main\n    (changed, cluster) = create_cluster(module, conn)\n  File \"/tmp/ansible_QpwK2x/ansible_module_redshift.py\", line 298, in create_cluster\n    redshift.create_cluster(identifier, node_type, username, password, **params)\nTypeError: create_cluster() got an unexpected keyword argument 'enhanced_vpc_routing'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}

# Fixed code
def delete_cluster(module, redshift):
    """
    Delete a cluster.

    module: Ansible module object
    redshift: authenticated redshift connection object
    """

    identifier = module.params.get("identifier")
    wait = module.params.get("wait")
    wait_timeout = module.params.get("wait_timeout")

    params = {}
    for p in ("skip_final_cluster_snapshot", "final_cluster_snapshot_identifier"):
        if p in module.params:
            # https://github.com/boto/boto3/issues/400
            if module.params.get(p) is not None:
                params[p] = module.params.get(p)

    try:
        redshift.delete_cluster(
            ClusterIdentifier=identifier,
            **snake_dict_to_camel_dict(params, capitalize_first=True),
        )
    except is_boto3_error_code("ClusterNotFound"):
        return (False, {})
    except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:  # pylint: disable=duplicate-except
        module.fail_json_aws(e, msg="Failed to delete cluster")

    if wait:
        attempts = wait_timeout // 60
        waiter = redshift.get_waiter("cluster_deleted")
        try:
            waiter.wait(
                ClusterIdentifier=identifier, WaiterConfig=dict(MaxAttempts=attempts)
            )
        except (
            botocore.exceptions.ClientError,
            botocore.exceptions.BotoCoreError,
        ) as e:
            module.fail_json_aws(e, msg="Timeout deleting the cluster")

    return (True, {})