cannot access ec2.instances data

Hello,

I am sure that I miss something obvious… but after having tried for a few hours, I just don’t know where to look for a solution …

I have the following playbook to create a new amazon instance and do a few things with it.
The instance is created correctly, but when I try to access to ec2_info.instances. private_ip variables, the playbook fail with an undefined variable error …

Does any one have an idea?

Many thanks in advance.

Fred

** playbook:

Hi,

“fatal: [127.0.0.1] => One or more undefined variables: ‘list’ object has no attribute ‘private_ip’”

That’s because ec2_info.instances is a list, not a dict.

If you use ec2_info.instances[0] you’ll get the first (and in your case only) instance returned by ec2 (which can create multiple instances)

So ec2_info.instances[0].private_ip will get you what you’re after.

Will

Hi Will,

I knew it was something obvious!
It is working much better now.

Thank you very much.

Fred