How can I make the list include IP numbers of each webserver host. I know I can use ansible_eth0.ipv4.address to map from hostname to IP, but I don’t know how to map a whole list to another list. And I can’t see any way to define a variable as the result of a loop.
I see, thanks. I’d still be interested if there’s any other way to do it, as it would be useful elsewhere too and prefer not to duplicate plays if possible.
name: Create mysql servers
mysql_user: name=app host=“{{ hostvars[item][‘ansible_eth0’][‘ipv4’][‘address’] if hostvars[item][‘ansible_eth0’] is defined else item }}”
with_items:
localhost
127.0.0.1
"{{ groups[‘webservers’] }}
The above example should work with 1.5, although I do believe that is over complicated, hard to read and not easily understand.
You could expand that to a regular {% if … %}{{ address }}{% else %}{{ item }}{% endif %} type line, but that gets even longer and harder to read in my opinion with all of the special characters that get mixed into that line.