this seems a basic question and have a simple answer.

{% for host in groups['dbservers'] %}
   {{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}
{% endfor %}

the interesting point is I normally run a specfic roles/tasks by tagging 
like this

ansible-playbook site.yml --limit=appservers --tags=sb_tomcat

note: since we limit appservers only then Ansible have no idea to get facts 
from other servers ( dbserver, memcache) in this case.

I have to do cheat like this

ansible-playbook site.yml --limit=dbservers, appservers --tags=sb_tomcat  ( 
add dbservers to gather facts)
but it's not enough, I have to add a fake task like this for dbservers with 
tag sb_tomcat

- name: Dont fool me
  command: echo "can you hear me"
  tags:
    - sb_tomcat   

Doing this to tell Ansible to gather dbserver facts and 
{% for host in groups['dbservers'] %}
   {{ hostvars[host]['ansible_eth1']['ipv4']['address'] }}
{% endfor %}

works.

Questions:
+ In real case, we really need a specfic tag. Do we have another way to 
gather fact explitcitly without modifying --limit or add fake tasks?

Regards,
Pilgrim
On Wednesday, February 4, 2015 at 5:36:39 PM UTC+7, Le Van wrote:
>
> Hi,
>
> I'm using Ansible to provision an application deployment.
>
> here is my structure
>
> hosts
> [dbservers]
> db.local
>
> [memcached]
> mc.local
>
> [appservers]
> app1.local
> #app2.local
>
>
> I'm using Tomcat and have a context like this in appservers ( app1.local)
> roles/tomcat/templates/context.j2
>
> <Context path="" reloadable="false" docBase="/apps/deploy/current" 
> workDir="work" >
>  <Environment name="memcached" value="*mc.local*" type="java.lang.String" 
> override="false"/>
>  <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
>
>    <Resource   name="jdbc/postgres/configuration"
>       
>         url="jdbc:postgresql://*db.local*:5432/configuration"
>    />
> </Context>
>
> My questions are:
> + How can I resolve mc.local ( db.local) to IP?
> Doing this, I don't have to set  hosts in appservers like
> /etc/hosts
> 192.168.. mc.local
> ....
>
> + In case of using dymamic inventory ( Ec2), how can I refer a db ( from 
> db tags), resolve its ip and resolve the template.
> + Or is there another way to accomplish this?
>
> I guess this model is trivial and should have a normal way out there ( but 
> I'm still a Ansible newbie to get it)
>
> Thanks,
> Pilgrim
>
>
>

-- 
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/50c62d6e-6c07-471f-81ab-8838fe9e1c7a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to