# getting the fqdns of all the hosts in a group

**URL:** <https://forum.ansible.com/t/getting-the-fqdns-of-all-the-hosts-in-a-group/14172>\
**Category:** Ansible Project\
**Created:** [December 18, 2013, 12:39am UTC](https://forum.ansible.com/t/getting-the-fqdns-of-all-the-hosts-in-a-group/14172 "2013-12-18T00:39:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Martin2](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@James\_Martin2](https://forum.ansible.com/u/James_Martin2)\
**Post date:** [December 18, 2013, 12:39am UTC](https://forum.ansible.com/t/getting-the-fqdns-of-all-the-hosts-in-a-group/14172/1 "2013-12-18T00:39:21Z")

</div>

I have a command that needs the fqdn's of all servers within an  
inventory group as input.

- name: run special command  
&nbsp;&nbsp;command: mycommand "foo.host bar.host baz.host"

Is there a simple way to create such a string without having to write  
out a template, cat it, register it, and using the registered  
variable's stdout?

Thanks,

James

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 18, 2013, 12:56am UTC](https://forum.ansible.com/t/getting-the-fqdns-of-all-the-hosts-in-a-group/14172/2 "2013-12-18T00:56:16Z")

</div>

Can you get away with using the inventory hostnames? I’m guessing perhaps not.

{{ “,”.join(groups.webservers) }}

It would probably require writing a lookup plugin.

{{ lookup(“jsm\_magic\_all\_my\_facts”, “webservers”, “ansible\_hostname”) }}

Others may have better suggestions but that’s what my brain is thinking currently 🙂

---

<div class="post-metadata">

**Author:** ![kahlil.hodgson](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@kahlil.hodgson](https://forum.ansible.com/u/kahlil.hodgson)\
**Post date:** [December 18, 2013, 1:09am UTC](https://forum.ansible.com/t/getting-the-fqdns-of-all-the-hosts-in-a-group/14172/3 "2013-12-18T01:09:52Z")

</div>

You might be able to chain together the map filter with something  
(untested) like:

{{ hostvars.websevers|map(attribute='ansible\_fqdn')|join(', ') }}

Probably need another link in the chain to get a list of vars for a  
group or some magic slicing.

K

Kahlil (Kal) Hodgson GPG: C9A02289  
Head of Technology (m) +61 (0) 4 2573 0382  
DealMax Pty Ltd (w) +61 (0) 3 9008 5281

Suite 1415  
401 Docklands Drive  
Docklands VIC 3008 Australia

"All parts should go together without forcing. You must remember that  
the parts you are reassembling were disassembled by you. Therefore,  
if you can't get them together again, there must be a reason. By all  
means, do not use a hammer." -- IBM maintenance manual, 1925

---

<div class="post-metadata">

**Author:** ![Mark\_Casey](https://avatars.discourse-cdn.com/v4/letter/m/b4bc9f/32.png) [@Mark\_Casey](https://forum.ansible.com/u/Mark_Casey)\
**Post date:** [February 7, 2014, 4:09pm UTC](https://forum.ansible.com/t/getting-the-fqdns-of-all-the-hosts-in-a-group/14172/4 "2014-02-07T16:09:41Z")

</div>

I was trying to get IPs from multiple hosts instead of their hostnames. I found a solution from another thread and adapted it. (…and am just cross linking in the hopes of helping the next person [http://xkcd.com/979/](http://xkcd.com/979/) 🙂

[https://groups.google.com/d/msg/ansible-project/LWRGQQYPtqs/b7rOazw36vQJ](https://groups.google.com/d/msg/ansible-project/LWRGQQYPtqs/b7rOazw36vQJ)

HTH,  
Mark
