That means the first host in the group “mongo_Servers”. [0] notion means the first element in a list. similarly [1] means the second element in a list.
How can I use this when function to work with the hosts in my inventory file? I had when: inventory_hostname == play_hosts[0] but I notice that it only selects a random server. I want it to select all of the servers. Using a * doesn’t work…
I don't understand why you want to do this, inventory_hostname will always be in play_hosts, so it will always be true.
Maybe you are looking for "with_items: play_hosts"?
To check if something is in a list the syntax is
when: <variable> in <list>