getting the fqdns of all the hosts in a group

818 views
Skip to first unread message

James Martin

unread,
Dec 17, 2013, 7:39:21 PM12/17/13
to ansible...@googlegroups.com
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

Michael DeHaan

unread,
Dec 17, 2013, 7:56:16 PM12/17/13
to ansible...@googlegroups.com
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 :)





--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Kahlil Hodgson

unread,
Dec 17, 2013, 8:09:52 PM12/17/13
to ansible...@googlegroups.com
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

Mark Casey

unread,
Feb 7, 2014, 11:09:41 AM2/7/14
to ansible...@googlegroups.com
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/ :)

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

HTH,
Mark
Reply all
Reply to author
Forward
0 new messages