Change variable in Ansible template based on group

Question:

I’ve got an Ansible inventory file a bit like this:

I also have a Jinja2 template file that needs a certain value set to “true” if a host belongs to the “es-masters” group.

I’m sure that there’s a simple way of doing it but after some Googling and reading the documentation, I’ve drawn a blank.

I’m looking for something simple and programmatic like this to go in the Jinja2 template:

Any ideas?

Answer:

You do it the other way around.
You check if the identifier (hostname or IP or whatever is in your inventory) is in the defined group. Not if the group is in the hostvars.

But, what you better should do is this:

Provide default in template

Than override in group_vars

Leave a Reply