magic variable for target group?

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?

Thanks!
Guy

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?

> > 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
>
> ... variable "groups"
>
> "A dictionary/map with all the groups in inventory and each group
> has the list of hosts that belong to it"
> ...
> Do you have any use-case which needs such variable?

Yes. I would like to have common roles, e.g. httpd, that could be
"app-aware" based on the target group.

What do you mean by "'app-aware' role based on the target group"?