# rds module | determining endpoint when module exits without complete result data

**URL:** <https://forum.ansible.com/t/rds-module-determining-endpoint-when-module-exits-without-complete-result-data/21592>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [May 28, 2016, 9:46pm UTC](https://forum.ansible.com/t/rds-module-determining-endpoint-when-module-exits-without-complete-result-data/21592 "2016-05-28T21:46:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darren\_S](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Darren\_S](https://forum.ansible.com/u/Darren_S)\
**Post date:** [May 28, 2016, 9:46pm UTC](https://forum.ansible.com/t/rds-module-determining-endpoint-when-module-exits-without-complete-result-data/21592/1 "2016-05-28T21:46:53Z")

</div>

OS X 10.10.5  
Python 2.7.11  
Ansible 2.0.2.0  
boto 2.40.0  
boto3 1.3.1  
botocore 1.4.24

Using the following tasks in a play:

- name: db | rds | create RDS instance  
&nbsp;&nbsp;become: no  
&nbsp;&nbsp;local\_action: rds  
&nbsp;&nbsp;args:  
&nbsp;&nbsp;&nbsp;&nbsp;command: create  
&nbsp;&nbsp;&nbsp;&nbsp;instance\_name: "{{ rds\_instance\_name }}"  
&nbsp;&nbsp;&nbsp;&nbsp;instance\_type: "{{ rds\_instance\_class }}"  
&nbsp;&nbsp;&nbsp;&nbsp;vpc\_security\_groups: "{{ rds\_instance\_vpc\_security\_groups }}"  
&nbsp;&nbsp;&nbsp;&nbsp;multi\_zone: "{{ rds\_instance\_multi\_zone }}"  
&nbsp;&nbsp;&nbsp;&nbsp;subnet: "{{ rds\_instance\_subnet\_group }}"  
&nbsp;&nbsp;&nbsp;&nbsp;db\_engine: "{{ rds\_instance\_engine }}"  
&nbsp;&nbsp;&nbsp;&nbsp;publicly\_accessible: "{{ rds\_instance\_public }}"  
&nbsp;&nbsp;&nbsp;&nbsp;db\_name: "{{ mysql\_app\_db\_name }}"  
&nbsp;&nbsp;&nbsp;&nbsp;size: "{{ mysql\_app\_db\_size }}"  
&nbsp;&nbsp;&nbsp;&nbsp;username: "{{ mysql\_admin\_user }}"  
&nbsp;&nbsp;&nbsp;&nbsp;password: "{{ mysql\_admin\_pass }}"  
&nbsp;&nbsp;async: 600  
&nbsp;&nbsp;poll: 60  
&nbsp;&nbsp;register: rds  
&nbsp;&nbsp;tags: [db, rds]

- name: db | rds | output db info  
&nbsp;&nbsp;debug:  
&nbsp;&nbsp;&nbsp;&nbsp;msg: "The new MySQL DB endpoint is {{ rds.instance.endpoint }}"  
&nbsp;&nbsp;&nbsp;&nbsp;#var: rds  
&nbsp;&nbsp;tags: [db, rds]

The result is that data in rds.instance is not populated completely at  
the time the module returns successfully (changed status in this  
case). Importantly, the 'endpoint' value is not missing. In the AWS  
RDS console, it can be seen that the RDS instance is continuing to be  
deployed (in "modifying" status for several minutes) and has not  
populated a number of attributes. This is the result in Ansible when  
it returns "early":

TASK [app : db | rds | create RDS instance] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [example.com -\> localhost]

TASK [app : db | rds | output db info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [example.com] =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"msg": "The new MySQL DB endpoint is "  
}

Though above, the debug 'msg' attribute shows in this case that  
rd.instance.endpoint is empty, on a previous run I dumped the rds  
variable and it shows many fields unpopulated:

TASK [app : db | rds | output db info] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [example.com] =\> {  
&nbsp;&nbsp;&nbsp;&nbsp;"rds": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ansible\_job\_id": "34553352208.25036",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"changed": false,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"finished": 1,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"instance": {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"availability\_zone": "us-west-2b",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"backup\_retention": 1,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"create\_time": 1464425508.477,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"endpoint": null,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"id": "database",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"instance\_type": "db.m4.large",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"iops": null,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"maintenance\_window": "sun:10:23-sun:10:53",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"multi\_zone": false,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"port": null,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"replication\_source": null,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"status": "modifying",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"username": "mysqladmin",  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"vpc\_security\_groups": "sg-4f02f029"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;&nbsp;&nbsp;}  
}

In the examples [1] for the Ansible rds module, the task uses  
wait/wait\_timeout before returning and shows that the registered  
variable has a full set of fields. I assumed that since the RDS  
instance creation can take a great deal of time on AWS side, it may be  
better to use asynchronous calls to avoid any long waits/timeouts.  
Should this work properly using async/poll? Any reason why the module  
returns but is not able to supply a complete instance dictionary? Is  
there a better approach for this case?

[1] [http://docs.ansible.com/ansible/rds\_module.html](http://docs.ansible.com/ansible/rds_module.html)

Regards,

---

<div class="post-metadata">

**Author:** ![ecoutin\_boingo](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@ecoutin\_boingo](https://forum.ansible.com/u/ecoutin_boingo)\
**Post date:** [June 3, 2016, 9:21pm UTC](https://forum.ansible.com/t/rds-module-determining-endpoint-when-module-exits-without-complete-result-data/21592/2 "2016-06-03T21:21:33Z")

</div>

Here are two ideas:

I’m about to implement this.

1.-Do fire and forget then check back when it’s ready and you REALLY need it:  
[http://docs.ansible.com/ansible/playbooks\_async.html](http://docs.ansible.com/ansible/playbooks_async.html) (see last example)  
[http://toroid.org/ansible-parallel-dispatch](http://toroid.org/ansible-parallel-dispatch)  
In my case I have plenty of things to do before I need the endpoint so is fine for me to wait while the instance gets instantiated, asynchronously.

2.-If you need to do this across plays(or not) you can use the rds\_facts to gather the facts of the instance and loop until you get the value that you need. Is basically the same thing you’re doing.

---

<div class="post-metadata">

**Author:** ![Darren\_S](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@Darren\_S](https://forum.ansible.com/u/Darren_S)\
**Post date:** [June 3, 2016, 11:25pm UTC](https://forum.ansible.com/t/rds-module-determining-endpoint-when-module-exits-without-complete-result-data/21592/3 "2016-06-03T23:25:41Z")

</div>

Thanks for the ideas. I took another look at this using the rds  
module's 'wait' and 'wait\_timeout' arguments and realized that they  
did what I wanted after all. When the instance setup is complete and  
it goes to available status, the task immediately completes - and  
these set a maximum amount of time to wait for it. Sorry for the  
noise, I didn't need to overcomplicate it after all.

I ended up with this task:

- name: "provision rds instance (timeout: {{ rds\_instance\_deploy\_timeout }}s)"  
&nbsp;&nbsp;become: no  
&nbsp;&nbsp;local\_action: rds  
&nbsp;&nbsp;args:  
&nbsp;&nbsp;&nbsp;&nbsp;command: create  
&nbsp;&nbsp;&nbsp;&nbsp;instance\_name: "{{ rds\_instance\_name }}"  
&nbsp;&nbsp;&nbsp;&nbsp;instance\_type: "{{ rds\_instance\_class }}"  
&nbsp;&nbsp;&nbsp;&nbsp;vpc\_security\_groups: "{{ rds\_instance\_vpc\_security\_groups }}"  
&nbsp;&nbsp;&nbsp;&nbsp;multi\_zone: "{{ rds\_instance\_multi\_zone }}"  
&nbsp;&nbsp;&nbsp;&nbsp;subnet: "{{ rds\_instance\_subnet\_group }}"  
&nbsp;&nbsp;&nbsp;&nbsp;db\_engine: "{{ rds\_instance\_engine }}"  
&nbsp;&nbsp;&nbsp;&nbsp;publicly\_accessible: "{{ rds\_instance\_public }}"  
&nbsp;&nbsp;&nbsp;&nbsp;maint\_window: "{{ rds\_instance\_maintenance\_window }}"  
&nbsp;&nbsp;&nbsp;&nbsp;backup\_retention: "{{ rds\_instance\_backup\_retention }}"  
&nbsp;&nbsp;&nbsp;&nbsp;size: "{{ mysql\_app\_db\_size }}"  
&nbsp;&nbsp;&nbsp;&nbsp;db\_name: "{{ mysql\_app\_db\_name }}"  
&nbsp;&nbsp;&nbsp;&nbsp;username: "{{ mysql\_admin\_user }}"  
&nbsp;&nbsp;&nbsp;&nbsp;password: "{{ mysql\_admin\_pass }}"  
&nbsp;&nbsp;&nbsp;&nbsp;wait: yes  
&nbsp;&nbsp;&nbsp;&nbsp;wait\_timeout: "{{ rds\_instance\_deploy\_timeout }}"  
&nbsp;&nbsp;register: rds  
&nbsp;&nbsp;when: rds\_create\_new\_instance  
&nbsp;&nbsp;tags: [db, rds]

---

<div class="post-metadata">

**Author:** ![ecoutin\_boingo](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@ecoutin\_boingo](https://forum.ansible.com/u/ecoutin_boingo)\
**Post date:** [June 4, 2016, 3:15am UTC](https://forum.ansible.com/t/rds-module-determining-endpoint-when-module-exits-without-complete-result-data/21592/4 "2016-06-04T03:15:08Z")

</div>

You’re welcome,

I’m doing something similar but the opposite in some ways.  
I want to wait for the instance to have the endpoint fied populated with a CNAME. This has nothing to do with the whole instance being available.

This is what I’ve learned since I posted.

1.-DO NOT USE debug combined with an until condition to loop, it won’t work. Use gather facts with a do until or wait\_for the condition you’re looking for.  
2.-The rds instance goes through the following status values:  
creating  
backing-up  
modifying  
available  
deleting.

When the instance transitions from creating to backing-up the endpoint shows up.

It doesn’t matter what you evaluate you’re right, you HAVE To wait for the instance to become available to get any data:

[https://github.com/ansible/ansible-modules-core/issues/3865](https://github.com/ansible/ansible-modules-core/issues/3865)

---

<div class="post-metadata">

**Author:** ![ecoutin\_boingo](https://avatars.discourse-cdn.com/v4/letter/e/ac91a4/32.png) [@ecoutin\_boingo](https://forum.ansible.com/u/ecoutin_boingo)\
**Post date:** [June 4, 2016, 4:49am UTC](https://forum.ansible.com/t/rds-module-determining-endpoint-when-module-exits-without-complete-result-data/21592/5 "2016-06-04T04:49:58Z")

</div>

You shouldn’t have to wait for the instance to go through EVERY status to get the dictionary, fields should be available as soon as they are. If async doesn’t solve the problem either then this should be a feature or bug fix. See ticket above.

---

<div class="post-metadata">

**Author:** ![einar.coutin](https://avatars.discourse-cdn.com/v4/letter/e/34f0e0/32.png) [@einar.coutin](https://forum.ansible.com/u/einar.coutin)\
**Post date:** [June 8, 2016, 9:30pm UTC](https://forum.ansible.com/t/rds-module-determining-endpoint-when-module-exits-without-complete-result-data/21592/6 "2016-06-08T21:30:01Z")

</div>

The solution was to piggy back on aws cli to pull the RDS endpoint after waiting for the RDS instance to shift out of creating into backing-up (use a !=“creating” comparison)
