[Dynamic Inventory] ec2_tag_Name is undefined

403 views
Skip to first unread message

Mateus Dubiela Oliveira

unread,
Apr 28, 2015, 1:53:14 PM4/28/15
to ansible...@googlegroups.com

TL;DR: When I create a instance the ec2_* variables are undefined.


Hello,

I'm using ansible to create instances and using the ec2_tag_Name to set up the machine's hostname. The problem is, on the first run the playbook crashes saying that the 'ec2_tag_Name' variable is undefinded, which is odd, since it should be automagicly defined by the ec2.py script. I've tried to run  [$ ./ec2.py --refresh-cache]after the machine's creation but with no luck.

My current workaround is to simply run the playbook twice, the variable is defined on the second run.

Here is a example playbook with this behaviour.

Thank you!


Brenda Bell

unread,
Apr 28, 2015, 9:32:26 PM4/28/15
to ansible...@googlegroups.com
For starters, you have a typo in your add_host task: publid_dns_name should be public_dns_name.

When you run your playbook the first time, there *is* no inventory. If you want to be able to access your new instances from the same playbook that creates them, you'll need to reference them by either the registered variable (ec2) or the group you're adding them to (my_cool_instance_group).

Dynamic inventory isn't dynamically modified as you create instances. It simply populates your inventory when the playbook starts. That's the inventory you have to work with until the playbook is complete and you refresh the cache.

Mateus Dubiela Oliveira

unread,
Apr 30, 2015, 12:49:17 PM4/30/15
to ansible...@googlegroups.com

I get it now, I need to use the dynamic inventory in order to use it's variables.

Thanks for the reply!
Reply all
Reply to author
Forward
0 new messages