TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why are we templating YAML?

263 pointsby jaxxstormover 6 years ago

36 comments

joeduffyover 6 years ago
My belief is that we&#x27;ve been slowly building up to using general purpose languages, one small step at a time, throughout the infrastructure as code, DevOps, and SRE journeys this past 10 years. INI files, XML, JSON, and YAML aren&#x27;t sufficiently expressive -- lacking for loops, conditionals, variable references, and any sort of abstraction -- so, of course, we add templates to it. But as the author (IMHO rightfully) points out, we just end up with a funky, poor approximation of a language.<p>I think this approach is a byproduct of thinking about infrastructure and configuration -- and the cloud generally -- as an &quot;afterthought,&quot; not a core part of an application&#x27;s infrastructure. Containers, Kubernetes, serverless, and more hosted services all change this, and Chef, Puppet, and others laid the groundwork to think differently about what the future looks like. More developers today than ever before need to think about how to build and configure cloud software.<p>We started the Pulumi project to solve this very problem, so I&#x27;m admittedly biased, and I hope you forgive the plug -- I only mention it here because I think it contributes to the discussion. Our approach is to simply use general purpose languages like TypeScript, Python, and Go, while still having infrastructure as code. An important thing to realize is that infrastructure as code is based on the idea of a <i>goal state</i>. Using a full blown language to generate that goal state generally doesn&#x27;t threaten the repeatability, determinism, or robustness of the solution, provided you&#x27;ve got an engine handling state management, diffing, resource CRUD, and so on. We&#x27;ve been able to apply this universally across AWS, Azure, GCP, <i>and</i> Kubernetes, often mixing their configuration in the same program.<p>Again, I&#x27;m biased and want to admit that, however if you&#x27;re sick of YAML, it&#x27;s definitely worth checking out. We&#x27;d love your feedback:<p>- Project website: <a href="https:&#x2F;&#x2F;pulumi.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pulumi.io&#x2F;</a><p>- All open source on GitHub: <a href="https:&#x2F;&#x2F;github.com&#x2F;pulumi&#x2F;pulumi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pulumi&#x2F;pulumi</a><p>- Example of abstractions: <a href="https:&#x2F;&#x2F;blog.pulumi.com&#x2F;the-fastest-path-to-deploying-kubernetes-on-aws-with-eks-and-pulumi" rel="nofollow">https:&#x2F;&#x2F;blog.pulumi.com&#x2F;the-fastest-path-to-deploying-kubern...</a><p>- Example of serverless as event handlers: <a href="https:&#x2F;&#x2F;blog.pulumi.com&#x2F;lambdas-as-lambdas-the-magic-of-simple-serverless-functions" rel="nofollow">https:&#x2F;&#x2F;blog.pulumi.com&#x2F;lambdas-as-lambdas-the-magic-of-simp...</a><p>Pulumi may not be <i>the</i> solution for everyone, but I&#x27;m fairly optimistic that this is where we&#x27;re all heading.<p>Joe
评论 #19111994 未加载
评论 #19110709 未加载
评论 #19110779 未加载
评论 #19110941 未加载
评论 #19112417 未加载
评论 #19111777 未加载
评论 #19112106 未加载
评论 #19111195 未加载
评论 #19114460 未加载
评论 #19111806 未加载
评论 #19111190 未加载
评论 #19111630 未加载
评论 #19112621 未加载
评论 #19110371 未加载
评论 #19110400 未加载
评论 #19113784 未加载
评论 #19111818 未加载
评论 #19110842 未加载
评论 #19110644 未加载
BossingAroundover 6 years ago
I know I&#x27;m in a minority, but I really dislike YAML... I recently did a lot of Ansible and boy, at the beginning, I was just struggling a lot. Syntactic whitespace kills me.<p>I don&#x27;t like it in Python either, but for some reason, when I write Python, it&#x27;s a lot easier. Maybe YAML is just a bit more complex (and Python has better IDE support..?)
评论 #19111313 未加载
评论 #19110069 未加载
评论 #19110071 未加载
评论 #19110261 未加载
评论 #19111669 未加载
评论 #19109836 未加载
评论 #19109147 未加载
评论 #19109476 未加载
评论 #19111167 未加载
评论 #19114030 未加载
评论 #19111469 未加载
评论 #19112341 未加载
aetherlordover 6 years ago
I didn&#x27;t see this mentioned anywhere else, so another alternative (that I&#x27;ve seen and really like conceptually, but haven&#x27;t used so far) to all this wildness with YAML and JSON -&gt; <a href="https:&#x2F;&#x2F;github.com&#x2F;dhall-lang&#x2F;dhall-lang" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dhall-lang&#x2F;dhall-lang</a>, and for kubernetes specifically -&gt; <a href="https:&#x2F;&#x2F;github.com&#x2F;dhall-lang&#x2F;dhall-kubernetes" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dhall-lang&#x2F;dhall-kubernetes</a>
评论 #19109460 未加载
评论 #19109443 未加载
评论 #19129904 未加载
miohtamaover 6 years ago
If you have been around long enough you still remember the world that was excited about XML and templating it using XSLT. As a hindsight it was a horrible world.<p>Even though YAML is not optimal, it is a human friendly compromise between too verbose XML and machine only JSON. It lacks native templating, leading to funny constructs e.g. with Ansible files. However human kind has made progress and will make progress further, so it is just a matter of time until someone comes up with sane &quot;native templated YAML&quot; and all projects will adopt it.
评论 #19109957 未加载
评论 #19112385 未加载
评论 #19111723 未加载
评论 #19112001 未加载
jrockwayover 6 years ago
I saw this title and immediately knew the article would be about Helm. I don&#x27;t think anyone wants to use Helm. People use it for a set-and-forget thing that they don&#x27;t care about (who cares that it&#x27;s called impressive-leopard-kubernetes-dashboard, after all.)<p>kustomize is much more sane for your own stuff: <a href="https:&#x2F;&#x2F;github.com&#x2F;kubernetes-sigs&#x2F;kustomize" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kubernetes-sigs&#x2F;kustomize</a><p>It is actually a little bit too magical for my taste, but I continue to use it because it hasn&#x27;t done anything stupid. I have one file that maps logical names to images in a container repository. If I create a service called &quot;foo&quot; pointing to selector.app.label=&quot;foo&quot; in the base, then in production it&#x27;s called foo-prd and the label magically updates to foo-prd for the selector. It actually understands what it&#x27;s generating, and while they might have taken it a little bit too far, it&#x27;s far better than just dumb text replacement.
评论 #19111808 未加载
评论 #19110859 未加载
SamWhitedover 6 years ago
As others in this thread have said: I ask this question all the time, except s&#x2F;templating&#x2F;using&#x2F;.<p>YAML is insanely over complicated; it&#x27;s as bad or worse than XML for config files, and it doesn&#x27;t even have the nice streaming mode. Not to mention that it&#x27;s a bit of a security nightmare (seriously, who put pointers into the YAML spec?).<p>And, on a more subjective note, YAML is just confusing: between all the significant whitespace and the random single character symbols that no one ever remembers what they do, I never get a YAML document right on the first try.<p>Templating it really does add a whole new level of headache too.
评论 #19109941 未加载
评论 #19111033 未加载
评论 #19119885 未加载
评论 #19113137 未加载
niftichover 6 years ago
File-based configs are a troublesome abstraction: they package unrelated concerns into a rigid document whose form must take a particular, application-dependent shape, and the assembly and disassembly of that document essentially becomes an API where key-value pairs are mixed with complex glue code. The application has to do this internally, but anyone who&#x27;s generating their configs are also doing parts of this externally.<p>Templates try to bandage over that by drilling down the abstraction to key-value pairs themselves. And imperative constructs that sneak into templating languages are an artifact of wanting to gain expressiveness without losing the benefits of declarative form -- but really, the two are at odds.<p>YAML is a red herring -- we had the same headaches with XML a decade prior. The problem is always that there&#x27;s relationships among the data (or even multiple instances of the config) that we care about, but that the structure of a single config file at rest cannot model.<p>Databases -- let&#x27;s say, an SQL one -- are actually among the better solutions, because they allow the universe of config items to live in structured places without overspecifying the exact form the data must take when serialized into a file. Then, data can be normalized where it makes sense to avoid repetition and introduce propagation. An SQL database gives all the tools needed to accomplish this, using mostly declarative code.<p>Databases in a KV sense are often used for configuration, and SQLite&#x27;s rise has increased richly structured configs that are specified at a higher level than what&#x27;s typically done with other serialization formats, but the full approach has not caught on outside big enterprise systems and complex applications. Which is a shame, because it&#x27;s hardly more complex than the current awkward pairing of a full serializer and a templating engine.
评论 #19113803 未加载
TeMPOraLover 6 years ago
Wait, what?<p>I feel this article is missing the <i>bigger</i> problem - one that for some reason just cannot die.<p>The problem is that of <i>gluing strings together</i>. YAML is not an unstructured text file, it&#x27;s a tree notation. Whatever &quot;templating&quot; or &quot;generation&quot; mechanism you want to use, it needs to respect the tree nature of the language it operates on. It needs to respect semantics.<p>Gluing strings together is literally what causes SQL Injection to exist. It caused countless of defacements on the web, and countless of broken websites. I would think we&#x27;ve learned our lessons, but for some reason, I see these template languages still alive and kicking.
评论 #19112699 未加载
评论 #19112519 未加载
epageover 6 years ago
There have been times I&#x27;ve wanted to templatize my configuration but I don&#x27;t want to do it with text-based templates but templates within the configuration files syntax (be it yaml, toml, or something else). Not sure what this is called, I&#x27;ve been calling it &quot;structural templating&quot;.<p>So far the only things close to this are<p>- Azure pipeline&#x27;s syntax: <a href="https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;azure&#x2F;devops&#x2F;pipelines&#x2F;process&#x2F;templates?view=azure-devops" rel="nofollow">https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;azure&#x2F;devops&#x2F;pipelines&#x2F;proc...</a> - Something called Jasonette: <a href="https:&#x2F;&#x2F;docs.jasonette.com&#x2F;templates&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docs.jasonette.com&#x2F;templates&#x2F;</a> - Something called Jsonnet: <a href="https:&#x2F;&#x2F;jsonnet.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jsonnet.org&#x2F;</a><p>Azure Pipeline&#x27;s approach I think is closest to what I&#x27;ve been looking for.<p>Anything else in this space?
评论 #19110381 未加载
评论 #19110238 未加载
fiddlerwoaroofover 6 years ago
Dhall-lang ( <a href="https:&#x2F;&#x2F;dhall-lang.org" rel="nofollow">https:&#x2F;&#x2F;dhall-lang.org</a> ) is another, somewhat interesting, attempt to solve this program: it comes with a non-Turing complete programming language, so you can bring some abstraction to your configuration files without having to worry about things like infinite loops.
MrStonedOneover 6 years ago
The real question is why are we using yaml at all?
评论 #19109315 未加载
评论 #19109258 未加载
评论 #19108969 未加载
评论 #19109049 未加载
评论 #19108982 未加载
评论 #19109048 未加载
评论 #19108971 未加载
评论 #19109405 未加载
评论 #19109058 未加载
equaluniqueover 6 years ago
Maybe we should be exploring using Dhall instead of YAML.<p>&gt;One of the clearest signals I’ve gotten from users is that Dhall is “the YAML killer”, for the following reasons:<p>&gt;Dhall solves many of the problems that pervade enterprise YAML configuration, including excessive repetition and templating errors<p>&gt;Dhall still provides many of the good parts of YAML, such as multi-line strings and comments, except with a sane standard<p>&gt;Dhall can be converted to YAML using a tiny statically linked executable, which provides a smooth migration path for “brownfield” deployment.<p>Source: <a href="http:&#x2F;&#x2F;www.haskellforall.com&#x2F;2019&#x2F;01&#x2F;dhall-year-in-review-2018-2019.html?m=1" rel="nofollow">http:&#x2F;&#x2F;www.haskellforall.com&#x2F;2019&#x2F;01&#x2F;dhall-year-in-review-20...</a>
rhackerover 6 years ago
LOL we are doing the same with k8s. We deploy to any environment, where each environment is a different k8s namespace. We even have a namespace for each developer. The variables are things like the image name (the tag is effectively a git commit id, or sometimes different for not-committed yet stuff). Beyond that just about nothing really needs to be a variable, but we do have different RAM amounts.<p>We have a couple ways that we template this out, but mostly we literally just do this in bash:<p><pre><code> sed -e &quot;s&#x2F;\$CI_COMMIT_SHA&#x2F;$CI_COMMIT_SHA&#x2F;&quot; kube-deploy.template.yaml | kubectl -n $ENV apply -f - </code></pre> (Where CI_COMMIT_SHA comes from gitlab) ENV comes from our gitlab CI file.<p>That all being said, the extent of our k8s integration is lots of stuff like that. We could write a JS file that creates a JSON k8s template, but honestly, that would be more work and more learning than we had to for what we&#x27;re doing. Why would we do more just because we want to avoid templating in a YAML file?
CryoLogicover 6 years ago
I think they are missing the real selling point of JSON. It&#x27;s basically interoperable with JavaScript objects.<p>That means you write it, send it, store it, operate on it, etc. with little or no modification.<p>The author says &quot;converting between the two is trivial&quot; which may be true, but the developer overhead is less trivial. And it will always be JSON in the client - JS doesn&#x27;t support YAML objects.
评论 #19109017 未加载
评论 #19108979 未加载
评论 #19109001 未加载
评论 #19111620 未加载
the8472over 6 years ago
Helm reminds me of the 90s level of webtech. I.e. php cgi files mixing html, logic and includes.
评论 #19110189 未加载
fasteoover 6 years ago
Off-topic: The whole discussion is about deploy-time configuration management, but our problem is more about run-time configuration management.<p>We have done the classical memcached+database custom solution, but I was wondering if there is any accepted library&#x2F;tool to change application run-time behavior. We have tried consul KV store [1], but does not quite fit in our environment.<p>My ideal solution would be a webapp with some text editor (think codemirror). Changes in this text file would push the configuration data to a running application.<p>[1] <a href="https:&#x2F;&#x2F;learn.hashicorp.com&#x2F;consul&#x2F;getting-started&#x2F;kv" rel="nofollow">https:&#x2F;&#x2F;learn.hashicorp.com&#x2F;consul&#x2F;getting-started&#x2F;kv</a>
nickjjover 6 years ago
Who knows.<p>It makes me throw up a little in my mouth every time I see hundreds of lines of YAML to configure something like Traefik with Kubernetes. The worst is when people say they prefer that because &quot;I don&#x27;t have to write a config file for my backend&quot;. That&#x27;s true but instead now you have extremely verbose configuration mixed in with other verbose configuration.<p>But in YAML&#x27;s defense I think it&#x27;s more of a problem with the tools that use it more so than YAML itself. Ansible is a great example of how amazing YAML can be to manage complex configuration in a concise way.
评论 #19110503 未加载
peterwwillisover 6 years ago
YAML is a data stream, not a program. Please do not shove programs into data.<p>Your data does not need to be &quot;expressive&quot;, it just needs to provide input to a program. If your data files need to be complex, you need a program to generate them for you.<p>I&#x27;ve danced the dance of ini -&gt; json -&gt; yaml -&gt; weird hybrid -&gt; embedded logic, and it ends with &quot;program that asks for what the thing you want looks like and generates data files&quot;. Industrial software design figured this out ages ago.
评论 #19112240 未加载
descover 6 years ago
My approach to this these days is:<p>* all configuration, without exception, is XML.<p>* all configuration may be generated from any other format imaginable, but it&#x27;s sure as fuck going into the Big Main Godlike Application as XML.<p>Separation, interfaces, etc. Disclaimer: I work in .NET almost exclusively. The .NET configuration APIs generally work, as long as you <i>only ever use them for reading</i>; treating config as something the application itself can fiddle with is a fast route to madness.
louiskottmannover 6 years ago
I feel like Ansible generating YAML with Jinja templates is really a sweet-spot, with idempotency and reusability.<p>I find it pushes me to write plain YAML files for variables and defaults (Ansible), while allowing strong templating of generated files (Jinja) and letting the result be readable (YAML). By readable I mean minimum programming bloat (code spread on many lines just to write a for loop) and minimum extra syntax that clutters the screen (brackets and quotes). It also lets me write very little custom code (aside from variables, obviously).<p>If I had to use a more &quot;powerful&quot; YAML-like replacement, it would mix all these into files, written differently by people with different styles, and it would have bloat all over the place.<p>The main issue I have with helm is that values.yml is not templatable by default so you have to generate it if you want reusability.<p>YAML does one thing and does it well, it&#x27;s readable and bloat-free. Maybe we need more tools like &quot;kubectl explain&quot; to know the syntax though.
mschaefover 6 years ago
Reading the commentary on whitespace, my thoughts immediately jumped to the C preprocessor. Even though it&#x27;s built into the language, it has the same sorts of problems as a template engine has with generating YAML: the preprocessor just wasn&#x27;t enough aware of the syntactic structure of the language to make it easy to generate anything of significant complexity.<p>I&#x27;m not proud of this (and like to think I could come up with something better these days), but this code was a bit of a nightmare for that reason:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;mschaef&#x2F;vcsh&#x2F;blob&#x2F;master&#x2F;vm&#x2F;number.c#L256" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mschaef&#x2F;vcsh&#x2F;blob&#x2F;master&#x2F;vm&#x2F;number.c#L256</a><p>Lisp macros do better, but they have the problem that the macros (and their potentially unusual evaluation rules) can easily just blend in with ordinary function calls.
sankyoover 6 years ago
In the Clojure world we use EDN (extensible data notation) which is a subset of Clojure. <a href="https:&#x2F;&#x2F;github.com&#x2F;edn-format&#x2F;edn" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;edn-format&#x2F;edn</a><p>You can extend it, convert it to JSON if necessary, and it is easy to read.
fredstedover 6 years ago
Helm charts are great, and accomplishes the task, but things get really weird and complex if you&#x27;re not careful. Oh man, the indentation and _helper.tpl nightmares. It&#x27;s not obvious at all. And there&#x27;s still a lot of repetition for each chart; writing a deployment or whatever is so verbose in K8s.<p>On the other hand, Ansible uses yaml and there it works great. I feel like Ansible uses yaml in a way that&#x27;s easier to understand and the way it was meant to be written. With Ansible, you&#x27;re writing configuration, not templates of configuration. I don&#x27;t think a layer on top of Ansible like Helm is for K8s wouldn&#x27;t make sense.
ssspajuover 6 years ago
I&#x27;d rephrase the question: &quot;Why are we templating YAML with text-based templating tools?&quot;<p>I and @akx wrote a templating tool called Emrichen that&#x27;s specifically designed for producing YAML and JSON from YAML templates:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;con2&#x2F;emrichen" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;con2&#x2F;emrichen</a><p>In contrast to other template systems, Emrichen templates are not just &quot;based on YAML&quot;, they _are_ YAML. YAML tags like &quot;!Var varname&quot; are used to perform things like variable substitution, loops etc. Variables can be of any JSON type, not just strings, and the template is evaluated top–down.
alxarchover 6 years ago
Over the last week I created a tool processing YAML and JSON files using Jsonnet. It&#x27;s called [ycat](<a href="https:&#x2F;&#x2F;github.com&#x2F;alxarch&#x2F;ycat" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;alxarch&#x2F;ycat</a>) and is inspired by `jq` but uses Jsonnet for processing. It can also be used just as `cat` to concatenate JSON&#x2F;YAML files. It&#x27;s still young but very usefull, especially for handling complex kubernetes configurations.
zapharover 6 years ago
Wholly agree with this which is why I&#x27;ve been experimenting with a project similar in goals to jsonnet as a side project of my own. I didn&#x27;t know about jsonnet when I started or I&#x27;d probably have just used&#x2F;contributed to that instead.<p>Why template yaml when you could just generate it? Or generate json, or toml, or xml, or environment variables...
评论 #19110965 未加载
nikolayover 6 years ago
Jsonnet is nice, but not actively developed, unfortunately. I highly recommend you to support UCG [0], which is written in Rust (Jsonnet has two implementations, which is one source of the slowness).<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;zaphar&#x2F;ucg" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;zaphar&#x2F;ucg</a>
illumin8over 6 years ago
His main argument is that you need to template differently for different environments (dev&#x2F;stage&#x2F;prod) and cloud regions (us-west&#x2F;us-east&#x2F;emea&#x2F;apac).<p>This is actually a solved problem, and you shouldn&#x27;t be doing it in your YAML&#x2F;JSON templates. You should be using an external parameter store to do this, and using a single template for everything.<p>See <a href="https:&#x2F;&#x2F;aws.amazon.com&#x2F;blogs&#x2F;compute&#x2F;query-for-the-latest-amazon-linux-ami-ids-using-aws-systems-manager-parameter-store&#x2F;" rel="nofollow">https:&#x2F;&#x2F;aws.amazon.com&#x2F;blogs&#x2F;compute&#x2F;query-for-the-latest-am...</a><p>This is a simple use case: I want to deploy the latest AMI (Amazon Machine Image) in any region, so I always get the latest patched Linux base image to run my application on. I don&#x27;t (and shouldn&#x27;t) want to update my YAML&#x2F;JSON every time a new image is published.<p>So, why are people having to go to these crazy templating macro lengths? Just store the changing bits in an external config&#x2F;parameter store like etcd and let your infrastructure as code templates remain unchanged.
评论 #19111516 未加载
评论 #19110220 未加载
评论 #19109897 未加载
l0b0over 6 years ago
YAML is the bastard offspring of XML. A bunch of ways to write semantically identical stuff is bullshit. Let data files be data files, and build them using languages actually suited for the job. JSON is plenty complex for 105% of the use cases of YAML, with much fewer downsides.
jeremysalwenover 6 years ago
When I joined Google, I realized that it was kinda surprising I hadn&#x27;t seen something like GCL in the outside world (not to say it doesn&#x27;t exist, just it&#x27;s ubiquitous enough for me to hear about it). This seems to be an example of that hole being filled.
kyberiasover 6 years ago
Why is it so hard to write the meat of the argument in the first paragraph? So much setup...
shussonover 6 years ago
I&#x27;ve recently settled on typescript object literals for creating complex config files.<p>Adv:<p>- It&#x27;s still quite declarative.<p>- supports expressions.<p>- supports merging objects using the spread `...` operator. This enables breaking up large configs files into smaller files.<p>- supports type constraints.<p>- serialises to JSON easily.
评论 #19113071 未加载
zoobabover 6 years ago
I use j2cli to template my YAMLs, pretty powerful to template stuff without using ansible. You just need to right environment variables. And you can put if logic if you want.
gjvcover 6 years ago
We cannot now be far off some ansible [1]-like tool using LISP s-expressions for its configuration language.<p>[1] or any of that ilk
spacesuitman2over 6 years ago
A consistent observation has been that all config languages tend to become turing complete over time.
Animatsover 6 years ago
Next, inheritance for JSON! Look how well it worked for CSS.