11 ms·
Because the tools only support markup languages, so we have to use stuff like Jinja or go templates to create those.
by cube2222 8y ago
Because the tools only support markup languages, so we have to use stuff like Jinja or go templates to create those.
- k__ 8y agoSure thing, but Jinja looks like a garbage fire. Why couldn't they use a regular programming language to create the markup? I mean this is done with HTML and JS all the time.
- linuxftw 8y agojinja is great, IMO, and well suited for it's intended purpose. jinja is in wide use in the python community.
- weberc2 8y agoMaybe jinja is well-suited to whatever its intended purpose is, but it's not well-suited for programmatically building markup. Using a dynamically typed scripting language to generate the markup at least has the benefit of allowing you to define appropriate semantics via functions ("give me a blob of YAML that represents a Kubernetes service with these parameters"). Sure, you can probably build your own concept of functions on top of Jinja, either by embedding them or building your own paradigm on top of Jinja's template inheritance, but it's a hack either way.
- linuxftw 8y agoWell, I think it was originally designed with server-side html templating in mind. It works great for that purpose. In the case of thread OP, that template is pretty messy, yes. In ansible, I would just create a custom module or action plugin in python to spit out whatever it is I need. I don't know how flexible salt is in this regard, but ansible is quite flexible. For simple cases, jinja works great if you're just doing a find/replace type operation in yaml.
- jfoutz 8y agoWith salt at least, that .sls file can just as easily be python. Just return the structure you need.
- simtel20 8y agoThanks for pointing that out. It's exhausting reading people in this thread getting very excited and demonstrative about the fact that a flexible system like salt provides a way to do this that results in a serialized data stream. They assume that they know better how this should be done, and posture about their superiority vs. some kind of straw man.
- weberc2 8y agoWe don't have to--you can generate the markup language with a scripting language and end up with something that is quite a lot cleaner. I've been toying around with Starlark as a yaml generator for Docker Compose, CloudFormation, and Kubernetes. This ends up working out a lot more nicely in practice than Helm's templating solution or CloudFormation's nested stacks.