I think you can do this using the map filter 

something like (untested)

- name: Set server names address for webapp proxy server
      set_fact:
        servers: "{{ ec2_facts.instances|map('private_ip_address')|list }}"


Have a look at: http://jinja.pocoo.org/docs/dev/templates/#map

HTH 

Jon

On Tuesday, 22 March 2016 21:22:02 UTC, Stephen Granger wrote:
>
> I'm using the ec2_remote_facts module to get a list of instances based on 
> filters.
>
> I want to create another list that contains the 
> ec2_facts.instances[0-n].private_ip 
>
> This is the logic I'm after
>
> - name: Set server names address for webapp proxy server
>       set_fact:
>         servers[item]: "{{ ec2_facts.instances[item].private_ip_address }}"
>       with_sequence: "start=0 end={{ ec2_facts.instances|(length -1) }}"
>
> but it doesn't work
>
> "msg": "ERROR! 'list object' has no attribute u'0'"
>
> I can manually set each fact
>
> - name: Set server names address for webapp proxy server
>       set_fact:
>         servers: ["{{ ec2_facts.instances[0].private_ip_address }}", "{{ 
> ec2_facts.instances[1].private_ip_address }}" ]
>
> But this is not optimal as it doesn't work for variable length lists.
>
> -- 
> Steve
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/8b75727a-4daf-44da-9463-7731e89f4152%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to