Set fact for another group in playbook

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:

    • 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

    • 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?

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.