Problem with var within a playbook

Hi,

I’m having a problem with a particular variable.

I’m hoping figuring out the problem below will help me understand the issue with a larger playbook.

ansible --version

ansible 1.9.2

A simple playbook (I need the list of ip addresses as it is passed to an api in one request);

Looks like it’s better to use set_fact here (well, that method works). It would still be good to understand why the above fails though

Strangely, if I use ;

ip: “{% for host in play_hosts %}{{ hostvars[host][‘ansible_default_ipv4’][‘address’] }}{% if not loop.last %},{% endif %}{% endfor %}”

This all works across both tasks (or both plays, if split it into two plays) whereas using “groups[‘all’]” fails on the second task