# List of all ansible\_ssh\_host in group

**URL:** <https://forum.ansible.com/t/list-of-all-ansible-ssh-host-in-group/19259>\
**Category:** Ansible Project\
**Created:** [September 14, 2015, 2:23pm UTC](https://forum.ansible.com/t/list-of-all-ansible-ssh-host-in-group/19259 "2015-09-14T14:23:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Teil](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Andrew\_Teil](https://forum.ansible.com/u/Andrew_Teil)\
**Post date:** [September 14, 2015, 2:23pm UTC](https://forum.ansible.com/t/list-of-all-ansible-ssh-host-in-group/19259/1 "2015-09-14T14:23:28Z")

</div>

Hi. I have the following inventory structure

master1 ansible\_ssh\_host=10.0.45.11  
master2 ansible\_ssh\_host=10.0.45.12  
master3 ansible\_ssh\_host=10.0.45.13  
slave1 ansible\_ssh\_host=10.0.45.51  
slave2 ansible\_ssh\_host=10.0.45.52  
slave3 ansible\_ssh\_host=10.0.45.53

[master\_servers]  
master1  
master2  
master3

…

Now I need a URL that looks something like this zk://10.0.45.11:2181,10.0.45.12:2181,10.0.45.13:2181/mesos  
For that reason I need a list of _ **ansible\_ssh\_host** _ variables for all servers in the group _ **master\_servers** _.

I ended up with this  
[hostvars[groups[‘master\_servers’][0]].ansible\_ssh\_host, hostvars[groups[‘master\_servers’][1]].ansible\_ssh\_host, hostvars[groups[‘master\_servers’][2]].ansible\_ssh\_host]

but this solution takes only three servers not all in the group

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 14, 2015, 3:02pm UTC](https://forum.ansible.com/t/list-of-all-ansible-ssh-host-in-group/19259/2 "2015-09-14T15:02:08Z")

</div>

We do something like this for our mongodb connection string:

‘mongodb://{% for h in groups.database %}{{ h }}{% if not loop.last %},{% endif %}{% endfor %}/{{ mongo\_database }}?replicaSet={{ mongo\_replicaset }}’

---

<div class="post-metadata">

**Author:** ![Takeshi\_Yaegashi](https://avatars.discourse-cdn.com/v4/letter/t/838e76/32.png) [@Takeshi\_Yaegashi](https://forum.ansible.com/u/Takeshi_Yaegashi)\
**Post date:** [September 15, 2015, 2:10am UTC](https://forum.ansible.com/t/list-of-all-ansible-ssh-host-in-group/19259/3 "2015-09-15T02:10:59Z")

</div>

Hello,

You can achieve it by using the following jinja2 template:

`
