Group hosts by value from list object of inventory var

Hi.
I have an inventory like this:

[test_servers]
192.168.0.101 app_roles=‘[“relay_master”]’
192.168.0.102 app_roles=‘[“relay_slave”,“cache”,“web_master”]’
192.168.0.103 app_roles=‘[“relay_slave”,“cache”,“web_slave”]’

Is it possible to add servers that, for example, have “cache” in their app_roles to a group (like with group_by)?

yes, but I find it easier to just create groups for that

[test_servers]
192.168.0.101

[relay_masters]
192.168.0.101
10.10.1.101
and then have the plays target the servers, using --limit to restrict
to 'test_servers':

- hosts: relay_masters

or just make them separate inventories sharing group/host_vars and
choose with -i /inventories/testing

Came to the same conclusion. Thanks for confirming.