Get a list of ansible hosts

25 views
Skip to first unread message

Tobi

unread,
Jun 13, 2022, 8:16:54 AM6/13/22
to Ansible Project
Hello everyone! 

I'm new here and also quiet new to ansible as well :) 

I will try to summarize:

The goal:
I wanna get a list of ansible hosts (could be made out of the ansible inv e.g.) and each element should be seperated by a space. The reason for that is that I want to run a bash script which needs a list attached to it like "script.sh host_1 host_2 host_3 ..." 

The problem:
I need to specify one host, which needs to be in front of every other host e.g. "script.sh host_2 host_1 host_3 ..."

My ansible inventory.ini example looks like:
[manager]

[utility_nodes]
host_1.example.de host_template=Utility1 
host_2.example.de host_template=Utility2 

[master_nodes] 
host_3.example.de host_template=Master1 
host_4.example.de host_template=Master2 


Many thanks in advance and
Best regards
Tobi

Walter Rowe

unread,
Jun 13, 2022, 8:53:18 AM6/13/22
to Ansible Project
https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html

groups

A dictionary/map with all the groups in inventory and each group has the list of hosts that belong to it


Brian Coca

unread,
Jun 13, 2022, 2:56:47 PM6/13/22
to Ansible Project
{{' '.join(listofhosts) }}

as to what provides the 'list of hosts' it could be just
groups['groupname'] or if you need host patterns
lookup('inventory_hostnames', 'all:!manager')


--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages