Finding out what groups a host is a member of in a template?

For the life of me I can’t seem to find this in the docs but I’m sure it’s possible.

I have a template and I want to expand a string to all the groups that host is a member of.

I’m using them as tags in our monitoring system.

The group_names variable will hold that info. It is a list of all groups that the current host is a member of.