Set fact for another group in playbook

71 views
Skip to first unread message

Sergei Antipov

unread,
Apr 26, 2015, 5:56:22 AM4/26/15
to ansible...@googlegroups.com
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

2. - 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?

Dan Vaida

unread,
Jun 19, 2015, 4:24:19 AM6/19/15
to ansible...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages