How to list all currently targeted hosts in an Ansible play

Question:

I am running an Ansible play and would like to list all the hosts targeted by it. Ansible docs mentions that this is possible, but their method doesn’t seem to work with a complex targeted group (targeting like hosts: web_servers:&data_center_primary)

I’m sure this is doable, but cant seem to find any further documentation on it. Is there a var with all the currently targeted hosts?

Answer:

You are looking for ‘play_hosts’ variable

would result in

inventory:

Leave a Reply