Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
raziel2p
82 days ago
|
parent
|
context
|
favorite
| on:
Interesting Uses of Ansible's ternary filter
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...
zufallsheld
82 days ago
|
next
[–]
Probably because the author of this piece of code was not aware of it. :)
Thanks, I updated the blog-post.
cpburns2009
82 days ago
|
prev
|
next
[–]
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.
mdaniel
82 days ago
|
parent
|
next
[–]
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/...
switch007
82 days ago
|
prev
[–]
I was wondering the same thing. I tested it and it works fine. It defaults to an empty string if there is no "else".
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: