No, what he's asking is how, in the middle of the template, do you
make a decision based on whether something is in a group or not.
Different question, it's about how you avoid having two templates if
just a part of them changes.
I believe this is what you want...
{% if inventory_hostname in groups["webservers"] %}
Thanks for pointing this out - group_by is definitely a nice dimension to
know about. This has helped me solve the problem for now, although on
reflection I think it would be conciser to be able to an equality test on
an attribute called group within the context of the j2 template. But this
gets me moving for now
check the list/thread for Micheal’s post, it is the exact solution you wanted, group by forces the division up to the playbook level, it works but the ‘in-template’ solution Micheal points out is exactly what you wanted.