I\'ve got an Ansible inventory file a bit like this:
[es-masters] host1.my-network.com [es-slaves] host2.my-network.com host3.my-network.com [es:children] es-m
To avoid error with non existing group you should check first if the group exists:
{% if 'es-masters' in group_names and ansible_fqdn in groups['es-masters'] %} node_master=true {% else %} node_master=false {% endif %}