# If Statement 1 Or Statement 2 In Jinja2 Template

**URL:** <https://forum.ansible.com/t/if-statement-1-or-statement-2-in-jinja2-template/44395>\
**Category:** Get Help\
**Created:** [September 1, 2025, 10:56am UTC](https://forum.ansible.com/t/if-statement-1-or-statement-2-in-jinja2-template/44395 "2025-09-01T10:56:12Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [September 5, 2025, 8:41pm UTC](https://forum.ansible.com/t/if-statement-1-or-statement-2-in-jinja2-template/44395/13 "2025-09-05T20:41:57Z")

</div>

> [@Dulux-Oz](#):
>
> the only change made (anywhere in the Ansible ecosystem) was the addition of two `(` characters and two `)` characters in the locations specified

🙂 It’s unfortunate you never posted the error you were getting. We’ve heard such claims before — sometimes from our own mouths.

I literally copy-n-pasted your expression from your first post

> [@Dulux-Oz](#):
>
> `{% if inventory_hostname in groups.group1 or inventory_hostname in groups.group2 %}`

Then defined an inventory with `group1` and `group2`, put my current machine into `group1` and ran it. It worked beautifully. Moved my machine from `group1` to `group2` and that worked as expected. Then I stuck a typo into the group names and it died with red text saying:

> fatal: [[tango.trailsong.org](http://tango.trailsong.org)]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable.. ‘dict object’ has no attribute ‘grooup1’\n\nThe error appears to be in ‘/home/utoddl/ansible/Dulux-Oz\_00.yml’: line 7, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: The test\n ^ here\n”}

Since you never posted the error you got, we’ve no way of knowing what the problem was, but it wasn’t the lack of parentheses.

I also have been making mistakes in this field professionally for 42 years. [Here’s a picture](https://forum.ansible.com/t/introduce-yourself-2023-edition/15/89) of my key-punch cards to prove it! Only now I can make mistakes on a scale we couldn’t imagine back then. But even then the refrain “I didn’t change anything else” was a clear sign that, well, you know… 🙂

Cheers!

---

_[View the full topic](https://forum.ansible.com/t/if-statement-1-or-statement-2-in-jinja2-template/44395)._
