Repository: ansible/ansible

Issue:
Redshift return values (url, public_ip_address, and port) are missing
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
redshift

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.1.0
  config file = None
  configured module search path = [u'/Users/brad.chamberlain/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.4.1.0/libexec/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Sep 25 2017, 09:53:22) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"

Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).

-->

<no output / empty>

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->

Running from macOS High Sierra 10.13.1

Running against AWS Redshift

##### SUMMARY
<!--- Explain the problem briefly -->

The redshift module creates the Redshift instance as expected, but the "cluster" dict return value is missing the "url", "public_ip_address", and "port" key/value pairs.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

Running this in a role (with or without the "wait" parameters) will create the Redshift instance, but the aforementioned key/value pairs are missing from the "cluster" dict return value.

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: redshift
  redshift:
    command: create
    wait: yes
    wait_timeout: 600
    region: "{{ redshift_region }}"
    node_type: "{{ redshift_node_type }}"
    identifier: "{{ redshift_name }}"
    availability_zone: "{{ redshift_az }}"
    cluster_type: single-node
    db_name: "{{ redshift_db_name }}"
    username: "{{ redshift_username }}"
    password: "{{ redshift_password }}"
    publicly_accessible: yes
    vpc_security_group_ids: "{{ redshift_sg_id }}"
    skip_final_cluster_snapshot: yes
  register: redshift_instance

- debug: var=redshift_instance
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

I would expect to see the "url", "public_ip_address", and "port" key/value pairs in the "cluster" dict return value.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

The "cluster" dict return value is missing the aforementioned key/value pairs. As expected, I can see key/value pairs for status, availability_zone, db_name, create_time, private_ip_address, identifier, and maintenance_window. I also see "username", though that is not mentioned in the list of return values on http://docs.ansible.com/ansible/latest/redshift_module.html.

<!--- Paste verbatim command output between quotes below -->
```
TASK [listener : redshift] *******************************************************************************************************************************************************************************
changed: [localhost]

TASK [listener : debug] **********************************************************************************************************************************************************************************
ok: [localhost] => {
    "redshift_instance": {
        "changed": true,
        "cluster": {
            "availability_zone": "us-east-1b",
            "create_time": 1511629400.256,
            "db_name": "dbname",
            "identifier": "id",
            "maintenance_window": "tue:03:00-tue:03:30",
            "private_ip_address": "172.31.2.250",
            "status": "available",
            "username": "admin"
        },
        "failed": false
    }
}
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/cloud/amazon/redshift.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/cloud/amazon/redshift.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @j-carl @willthames
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/redshift.py b/lib/ansible/modules/cloud/amazon/redshift.py
--- a/lib/ansible/modules/cloud/amazon/redshift.py
+++ b/lib/ansible/modules/cloud/amazon/redshift.py
@@ -243,11 +243,14 @@ def _collect_facts(resource):
         '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


Test patch: