News for hackers. Stuff that matters.
Re:Why are we templating YAML? by deathanatos on Thursday February 07, 2019 @05:35PM (#19109315)
Easier to read and write than JSON.

JSON requires constant quoting, can't support multiline strings, has no comments, has no/little typing (e.g., no datetime type). It's not good if a human needs to encode data.

For configs, I think TOML beats YAML hands down; I think YAML's spot is at encoding data structures that humans need to read/write.

I do agree that YAML, the spec, is fairly complicated. But YAML, as used in most projects, by most people, is not, and can be picked up fairly quickly. It is easier to visually read as it removes much of the clutter that would exist in the comparable JSON. It isn't typically necessary to know the entirety of the YAML spec to be useful with YAML, and most of the parts you won't know will get introduced by an obvious-looking sigil, which can be used to figure out what you're dealing with.

When I've actually sat with folks struggling with YAML, it's almost always in configuration tools, and it's also always around the templating bits. Ansible, in particular, has a bizarre templating: it happens after YAML parsing, which is not the mental model most people use when approaching it. I've also found that most of the people I've spoken to intertwine YAML and Ansible's templating functions, thinking they're one in the same.

I do not think Ansible makes good use of YAML: I would rather write task files in an actual programming language, since they are — at their core — a program. (The tasks do have some metadata attached to them, but the core task itself is a program. A function in some real language can get metadata attached to it in a number of ways, and that would be a better solution.)

Re:Why are we templating YAML? by erik_seaberg on Thursday February 07, 2019 @10:49PM (#19111363)
YAML quoting is only optional if you're obsessive enough to always remember to quote the country code for Norway.
Re:Why are we templating YAML? by pytester on Thursday February 07, 2019 @08:18PM (#19110463)
>For configs, I think TOML beats YAML hands down

If you compare a medium sized, 3 level deep TOML document with an equivalent YAML document you'll find that the TOML document is up to 50% longer.

None of that additional verbosity adds meaning - or readability.

Part of this is the extra syntactic noise but most of it is because all of the key names have to be defined explicitly above the key values for each value whereas in YAML you just need to put the values below an indent.

TOML is tolerable for small, very lightly nested config files but even medium sized TOML configurations get ugly very fast.

Re:Why are we templating YAML? by guitarbill on Thursday February 07, 2019 @07:23PM (#19110082)
It's worth giving Ansible some credit here. Alternatives like Chef, can and do contain arbitrary Ruby logic which can make Chef "cookbooks" horrible to figure out and debug.

So while Ansible may not be great, other solutions also have drawbacks, and it isn't quite as easy as do <x>.

Re:Why are we templating YAML? by rbankston on Thursday February 07, 2019 @09:18PM (#19110884)
I've worked with both. The simple items are nicer in ansible but when there are a lot of custom roles and functions ansible isn't much better than chef from what I've seen in practice.