Accessing play.hosts from a play

Is there a way to access the play.hosts from my play?

I would like to be able to do:

  • hosts: tag_role_cluster_host:&tag_environment_staging:&tag_deployment_us_east

and then use the host list generated by that set intersection to configure each of hosts with the complete list of it’s peers.

So that in a jinja template I could do something like:

{%- for host in play_hosts -%}
cluster-add-host {{ host }}
{%- endfor %}

I have other ways of accomplishing this, but they are not a clean as this and given that plays already provide set operators, I’d like to take advantage of them.

Ed.

hostvars.keys() will give you all the hosts for a given play.

-jlk