# Set fact for another group in playbook

**URL:** <https://forum.ansible.com/t/set-fact-for-another-group-in-playbook/18089>\
**Category:** Ansible Project\
**Created:** [April 26, 2015, 9:56am UTC](https://forum.ansible.com/t/set-fact-for-another-group-in-playbook/18089 "2015-04-26T09:56:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergei\_Antipov](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Sergei\_Antipov](https://forum.ansible.com/u/Sergei_Antipov)\
**Post date:** [April 26, 2015, 9:56am UTC](https://forum.ansible.com/t/set-fact-for-another-group-in-playbook/18089/1 "2015-04-26T09:56:22Z")

</div>

Hello all.  
I can’t find a solution for my problem.

I need to create Amazon RDS instance and EC2 instance. And inside EC2 instance I need RDS public ip address.  
What I do:

1. 
  - hosts: localhost  
code to create rds and register it with rds\_database variable  
debug tasks here say rds\_database.instance.endpoint is exist

code to create ec2 instance and add\_hosts inside web group

1. 
  - hosts: web  
debug: msg=“{{ rds\_database.instance.endpoint }}”

fatal: [xxx.xxx.xxx.xxx] =\> {‘msg’: “AnsibleUndefinedVariable: One or more undefined variables: ‘rds\_database’ is undefined”, ‘failed’: True}

I tried

- include: another.yml rds\_database=“{{ rds\_database.instance.endpoint }}”, but this variable not evaluated before include.

Should I use fact caching or I do something wrong?

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [June 19, 2015, 8:24am UTC](https://forum.ansible.com/t/set-fact-for-another-group-in-playbook/18089/2 "2015-06-19T08:24:19Z")

</div>

Use Ansible’s dynamic inventory and access the hostname like so:

`  
“{{ hostvars[groups['rds\_instance\_name\_goes\_here][0]].ec2\_\_address }}”

`  
Make sure the instance is set to “publicly available” and the security group around it allows such connections.
