News for hackers. Stuff that matters.
Re:Interesting Uses of Ansible's ternary filter by raziel2p on Thursday February 22, 2024 @07:22AM (#39466080)
Why would you use this instead of e.g.

    {{ "--quiet" if ansible_verbosity == 0 }}
https://jinja.palletsprojects.com/en/3.1.x/templates/#if-exp...
Re:Interesting Uses of Ansible's ternary filter by zufallsheld on Thursday February 22, 2024 @07:38AM (#39466215)
Probably because the author of this piece of code was not aware of it. :)

Thanks, I updated the blog-post.

Re:Interesting Uses of Ansible's ternary filter by switch007 on Thursday February 22, 2024 @07:36AM (#39466194)
I was wondering the same thing. I tested it and it works fine. It defaults to an empty string if there is no "else".
Re:Interesting Uses of Ansible's ternary filter by cpburns2009 on Thursday February 22, 2024 @12:22PM (#39470182)
I'm genuinely surprised you can use if-else expressions in Jinja. Jinja uses such neutered expressions I would have looked for an equivalent ternary/iff filter.
Re:Interesting Uses of Ansible's ternary filter by mdaniel on Thursday February 22, 2024 @02:06PM (#39471532)
They support for-if from python, too: https://jinja.palletsprojects.com/en/3.1.x/templates/#loop-f... but I haven't tried the "recursive" keyword to know if ansible supports that. I say "ansible supports that" because they don't just drop jinja2 into ansible and call it a draw, they have a bunch of custom execution integrations: https://github.com/ansible/ansible/blob/v2.16.3/lib/ansible/...