# Buggy code
def _collect_facts(resource):
    """Transfrom cluster information to dict."""
    facts = {
        "identifier": resource["ClusterIdentifier"],
        "create_time": resource["ClusterCreateTime"],
        "status": resource["ClusterStatus"],
        "username": resource["MasterUsername"],
        "db_name": resource["DBName"],
        "availability_zone": resource["AvailabilityZone"],
        "maintenance_window": resource["PreferredMaintenanceWindow"],
        "url": resource["Endpoint"]["Address"],
        "port": resource["Endpoint"]["Port"],
    }

    for node in resource["ClusterNodes"]:
        if node["NodeRole"] in ("SHARED", "LEADER"):
            facts["private_ip_address"] = node["PrivateIPAddress"]
            facts["public_ip_address"] = node["PublicIPAddress"]
            break

    return facts


# 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 _collect_facts(resource):
    """Transfrom cluster information to dict."""
    facts = {
        "identifier": resource["ClusterIdentifier"],
        "status": resource["ClusterStatus"],
        "username": resource["MasterUsername"],
        "db_name": resource["DBName"],
        "maintenance_window": resource["PreferredMaintenanceWindow"],
        "enhanced_vpc_routing": resource["EnhancedVpcRouting"],
    }

    for node in resource["ClusterNodes"]:
        if node["NodeRole"] in ("SHARED", "LEADER"):
            facts["private_ip_address"] = node["PrivateIPAddress"]
            if facts["enhanced_vpc_routing"] is False:
                facts["public_ip_address"] = node["PublicIPAddress"]
            else:
                facts["public_ip_address"] = None
            break

    # Some parameters are not ready instantly if you don't wait for available
    # cluster status
    facts["create_time"] = None
    facts["url"] = None
    facts["port"] = None
    facts["availability_zone"] = None

    if resource["ClusterStatus"] != "creating":
        facts["create_time"] = resource["ClusterCreateTime"]
        facts["url"] = resource["Endpoint"]["Address"]
        facts["port"] = resource["Endpoint"]["Port"]
        facts["availability_zone"] = resource["AvailabilityZone"]

    return facts