If Statement 1 Or Statement 2 In Jinja2 Template

:slight_smile: 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

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]: 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 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… :slight_smile:

Cheers!

2 Likes