Get a list of ansible hosts

Hello everyone!

I’m new here and also quiet new to ansible as well :slight_smile:

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]
host_2.example.de

[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

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

{{' '.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')