On Tue, 1 Dec 2020 11:41:20 -0500
Guy Matz <
guy...@gmail.com> wrote:
> Hi! Does anyone know if there's a variable set for the target group of a
> play?
>
> For example, for this:
> - hosts: *prime*
> roles:
> - nginx
> - postfix
>
> Does any variable get set to "prime" in a deterministic way?
No. There is no such "special variable"
https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html
There is only variable *group_names*
"List of groups the current host is part of"
and variable "groups"
"A dictionary/map with all the groups in inventory and each group
has the list of hosts that belong to it"
Ansible doesn't store the structure of inventory groups. Quoting from
"How variables are merged"
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#how-variables-are-merged
"... This keeps Ansible focused on the Host and Task, so groups
don’t really survive outside of inventory and host matching. ..."
Do you have any use-case which needs such variable?
--
Vladimir Botka