I have a playbook, and in one of the templates I need to walk over all the 
hosts in certain groups grabbing their hostvars etc.

I followed http://docs.ansible.com/faq.html and everything seems to work as 
expected but with one quirk:

In template I have:

     {% for host in groups['nova'] %}
      {% set myvars=hostvars[host] %}
      <service name="nova" type="compute" disabled="False" description="" 
order="1">
          <user name="{{ myvars.service_user }}" password="{{ 
myvars.service_user_password }}" email="{{ myvars.service_user_email }}"/>
          <mysql user="{{ myvars.service_mysql_user }}" password="{{ 
myvars.service_mysql_user_password }}"/>
          <host name="{{ host }}"/>
          <endpoint>
            <address type="admin" host="{{ myvars.service_admin_ip }}" 
uri_suff=":$(compute_port)s/v1.1/$(tenant_id)s" />
            <address type="public" host="{{ myvars.service_public_ip }}" 
uri_suff=":$(compute_port)s/v1.1/$(tenant_id)s"/>
            <address type="internal" host="{{ myvars.service_internal_ip 
}}" uri_suff=":$(compute_port)s/v1.1/$(tenant_id)s"/>
          </endpoint>
          <region name="{{ myvars.service_region }}"/>
      </service>
     {% endfor %}

in group_vars/nova.yml I have:

...
service_admin_ip: 192.168.0.138
service_public_ip: "{{ ansible_default_ipv4.address }}"
service_internal_ip: "{{ ansible_default_ipv4.address }}"
service_region: RegionOne
...

so as a result I get:

       <service name="nova" type="compute" disabled="False" description="" 
order="1">
          <user name="nova" password="nova" email="[email protected]"/>
          <mysql user="nova" password="nova"/>
          <host name="192.168.0.138"/>
          <endpoint>
            <address type="admin" host="192.168.0.138" 
uri_suff=":$(compute_port)s/v1.1/$(tenant_id)s" />
            <address type="public" host="{{ansible_default_ipv4.address}}" 
uri_suff=":$(compute_port)s/v1.1/$(tenant_id)s"/>
            <address type="internal" 
host="{{ansible_default_ipv4.address}}" 
uri_suff=":$(compute_port)s/v1.1/$(tenant_id)s"/>
          </endpoint>
          <region name="RegionOne"/>

Note that service_public_ip did not get resolved as expected (even though 
facts were collected for that host already), and service_admin_ip works 
fine when I hardcode it and don't use facts. Is there a way to get around 
this issue? I do not want to drop ansible_default_ipv4 stuff into the 
role's playbook but prefer to keep it "configurable" with some sane default 
(default_ipv4). What am I missing in this?

P.S.
I have some other plays where group_vars/all.yml defines vars in similar 
fashion (referencing some of the facts) and those work just fine.

-- 
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/1f44b0bd-5b90-49e4-8156-30684931a0c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to