Ansible Jinja2 template - inventory_hostname as variable in if statement?

Still trying to understand the way to work jinja2 templates…

I’m looking for a way to alter the definition of a gateway address based on the name of the current inventory_hostname.

eth0gateway and eth0gateway_gen are variables in the playbook.

I would like to branch depending on if ecd0 is in, or starts with, the inventory_hostname.

Can someone lead me in the right direction here:

`
{% if {{inventory_hostname}}.find(‘ecd0’) > -1 %}
GATEWAY={{eth0gateway}}
{% else %}
GATEWAY={{eth0gateway_gen}}
{% endif %}

`

Thanks for any tips,
Chris.

In between Jinja statement delimiters {% and %} you can't use {{ }},
you are in Jinja and it knows about variables, so change the line to.

   {% if inventory_hostname.find('ecd0') > -1 %}