The other way to do it would be something like:

- 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.

-- 
Matt Martz
[email protected]

On March 5, 2014 at 5:27:40 AM, Michael Mahemoff ([email protected]) wrote:

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.

On Tuesday, March 4, 2014 9:16:15 PM UTC, Matt Martz wrote:
I would split your create user into 2 tasks.  1 for localhost and the other for 
web servers:

- name: Create localhost mysql users
  mysql_user: name=app host="{{ item }}"
  with_items:
    - localhost
    - 127.0.0.1

- name: Create webservers mysql users
  mysql_user: name=app host="{{ 
hostvars[item]['ansible_eth0']['ipv4']['address'] }}"
  with_items: groups['webservers']

-- 
Matt Martz
[email protected]

On March 4, 2014 at 3:09:35 PM, Michael Mahemoff ([email protected]) wrote:

I have a rule like this:

- name: Create user
  mysql_user: name=app
                     host=={{ item }}
                     ...
  with_items:
    - localhost
    - 127.0.0.1
    - "{{ groups['webservers'] }}"
    # - <here I want to list ip numbers of the webservers group>

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.
--
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/9821a9c0-b62b-4e50-bfe7-10559124ebb6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
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/be29a096-6e1a-47f9-8cbd-1129577719d8%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

-- 
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/etPan.53172512.6b8b4567.8c0b%40mobiletuvix.rackspace.corp.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to