how to get ip address of an RDS instance using the RDS module ?

Hi All,

How can I get the public IP of an RDS instance the same way we do with the ec2 module (register: ec2/with_items: ec2.instances / {{ item.public_ip }} ) ?

I see in the RDS documentation (http://www.ansibleworks.com/docs/modules.html#rds) the register: new_database_facts
but I don’t know what item types can be queried.

Regards,
N.

You might also want to look at the ec2_facts module, which should work with an RDS instance I think. Also, the ec2 inventory script should return this information and it would be in the host variables.

Thanks James but I believe in my case will be more efficient and faster to get the ip right after the RDS creation from register: new_database_facts if available.

any ideas on this ?

On what in particular?

on how can I get an RDS instance public IP

I’m interested in determining the IP (and other facts) of a created RDS instance as well. When I create an RDS instance, I use the “wait: no” option because creating the instance takes a LONG time:

  • name: Create RDS Oracle
    local_action:
    module: rds
    command: create
    region: ${region}
    instance_type: db.m1.small

instance_name: ${rds.name}


wait: no

But I’d like to get the IP so I can create a Route53 entry, then use that later when I install software on the instance using this RDS.

Is there a way to retrieve this info? If not in this run – where “wait: no” would likely provide no means for the play to ask AWS for the RDS IP – then in a subsequent play?

Thanks.

You should never know or use the IP address for RDS. RDS has an endpoint and that is the only way you should be accessing it.

If you happen to be running a multi-az RDS deployment, the IP address with change whenever it feels like it.

Think of it the same as using an ELB, and only use the endpoint.

Understood, fair 'nuff.

Then let me rephrase the question: how can I get the endpoint name after creation, so I can use it to configure parameters on my app server with subsequent ansible plays?

Thanks.

Well, based on this:

https://github.com/ansible/ansible/blob/devel/library/cloud/rds#L520

It would see the endpoint is accessible by “your_registered_var.endpoint”, but if you specify “wait: no”, then you don’t get that information because the endpoint is only available once RDS is available, not directly after the first API call.

Patience is a virtue :slight_smile:

After successfuly creating a new RDS instance I’m still not able to get the endpoint address in the playbook :

“”"

  • name: get RDS instance facts
    local_action: rds command=facts instance_name={{ instance_name }} region={{ region }}
    register: rds

RDS creation can take a long time for the status to be ready casuing problems for the

  • name: RDS endpoint is → {{ rds.endpoint }}
    debug: msg=" RDS endpoint is → {{ rds.endpoint }}"
    “”"

-vvv ouput
“”"

TASK: [get RDS instance facts] ************************************************
<127.0.0.1> EXEC [‘/bin/sh’, ‘-c’, ‘mkdir -p $HOME/.ansible/tmp/ansible-1382542803.71-32171941018328 && chmod a+rx $HOME/.ansible/tmp/ansible-1382542803.71-32171941018328 && echo $HOME/.ansible/tmp/ansible-1382542803.71-32171941018328’]
<127.0.0.1> REMOTE_MODULE rds command=facts instance_name=mydb region=us-east-1
<127.0.0.1> PUT /tmp/tmp6fQTde TO /home/nicolasg/.ansible/tmp/ansible-1382542803.71-32171941018328/rds
<127.0.0.1> EXEC [‘/bin/sh’, ‘-c’, ‘/usr/bin/python /home/nicolasg/.ansible/tmp/ansible-1382542803.71-32171941018328/rds; rm -rf /home/nicolasg/.ansible/tmp/ansible-1382542803.71-32171941018328/ >/dev/null 2>&1’]
changed: [localhost] => {“changed”: true, “instance”: {“availability_zone”: “us-east-1b”, “backup_retention”: “1”, “backup_window”: “06:58-07:28”, “create_time”: “2013-10-23T15:36:15.863Z”, “endpoint”: “mydb.cf6uoyzbegkp.us-east-1.rds.amazonaws.com”, “id”: “mydb”, “instance_type”: “db.m1.small”, “iops”: null, “maintenance_window”: “thu:04:51-thu:05:21”, “multi_zone”: false, “port”: 3306, “replication_source”: null, “status”: “available”, “username”: “root”}}

TASK: [RDS endpoint is → {{rds.endpoint}}] **********************************
ok: [localhost] => {“msg”: " RDS endpoint is → {{rds.endpoint}}"}

“”"

Since it also kept me stuck for a few moments: the solution is to query rds.instance.endpoint instead of rds.endpoint.