Issue with registered variables

Hi guys , I am having a really hard time with registered variables. I banged my head around all day… but could not figure this out. :frowning:

I simply want to register my task result as a variable and access it later on.

This is my debug: var= result: https://pastebin.mozilla.org/8950629
and I simply want to get dns_name

I call it like this:

  • name: Wait for servers to boot up
    wait_for:
    host: “{{ item.dns_name }}”
    port: 22
    delay: 30
    timeout: 300
    state: started
    with_items: ec2_result.instances

But I am getting error saying that

fatal: [localhost]: FAILED! => {“failed”: true, “msg”: "the field ‘args’ has an invalid value, which appears to include a variable that is undefined. The error was: ‘unicode object’ has no attribute ‘dns_name’\n\n

Can you guys please point me to right direction?
Thank you.

As of Ansible 2.2 with_items does not support bare variables.

As such you need to use:

with_items: “{{ ec2_result.instances }}”

Otherwise it will treat ec2_result.instances as a string.

Thank you so much Matt Martz! You’re awesome!