getting the fqdns of all the hosts in a group

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

- name: run special command
  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

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 :slight_smile:

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

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/ :slight_smile:

https://groups.google.com/d/msg/ansible-project/LWRGQQYPtqs/b7rOazw36vQJ

HTH,
Mark