If the price to pay is that there is some risk some dummy might start parsing the comments as code, so be it. This is not a really a problem in "regular" programming languages, I don't see why it would be in a configuration language.
Plus non standard stuff is not a valid argument. As there are many tools which support non standard behaviour, because useful features like comment are considered non standard
#!/usr/bin/env python3
"""A made up example of the line noise"""
from ansible import *
def main():
hosts = ["localhost"]
for h in hosts:
run_one_host(h)
def run_one_host(inventory_hostname: str):
connection = ansible.builtin.ssh(inventory_hostname)
print("sniff out the machine's os")
host_vars = ansible.builtin.setup(gather_subset="os", connection)
if host_vars["distribution"] == "ubuntu":
dest = "/etc/apt"
else ...
dest = "/etc/something else"
print("do something awesome")
copy_ok = ansible.builtin.copy(src="./some_file", dest=dest, connection)
...
That said, I can't readily imagine why you couldn't do exactly what you said because the AnsibleModule[1] contract is JSON over stdin/stdout (and one can write Ansible modules in any programming language[2] - they just default to Python)1: https://github.com/ansible/ansible/blob/v2.18.4/lib/ansible/...
2: https://docs.ansible.com/ansible-core/2.18/dev_guide/develop... and https://github.com/ansible/ansible/blob/v2.18.4/test/integra...
I understand and appreciate the "why" of the format, but this also could have been a non-editable "editor-like" presentation and achieved the same result.
> # ps. By design, this website is as usable as YAML.
It's intentionally bad.
> The good news (I realised) was that you can select all the text of the site, and then delete it. Problem solved.
or "I am doing ci job frontend, for each job I need to get a list of inputs it takes and their description, but without doing full code checkout" - good luck doing this if your jobs are in python/nodejs.
(to be fair, there are programming languages that are also severely limited and can be evaluated mostly safely, like Starlark, but I don't think they'd match your definition)
Here's how yaml's type inference should work:
- All object keys are strings (with or without quotes)
- Value atoms are parsed the exact same way as in JSON5
I'm kinda shocked this isn't a thing. StrictYAML is cool but a bit too cumbersome IMO.
https://github.com/toml-lang/toml/blob/1.0.0/toml.md#user-co...
This is far superior in illustrating the slippery slope.
Aside from that slide too an inevitable dinner with Turing completeness, there's often the problem of sourcing information from multiple files overlaying it backtracking where it's sourced from.
Docker files are an example of this, as is the complete list of config values in spring framework (it's like 30 different sources).
In addition config starts getting into secured secrets, service invocations, database lookups, operating system commands, and who else knows what.
So not only is it really a touring complete problem, it veers into hellscape that is system integration.
This website does the rare thing of, after complaining, providing a long list of alternatives. It's really nice.
JSON with functions as the high level format and JSON as the low level format is the way to go. Examples include Nix and Jsonnet. They're much nicer to deal with and less error prone.
Yay, octal numbers! But don't panic, lots of supposed C programmers fall for exactly the same trick when prefixing numbers with `0`.
Amusingly, the Stack Overflow answer you linked in your contribution is the second result in a Google search for "YAML multiline string" or the like, after yaml-multiline.info; the two combined appear to the canonical resource on the web.
Also, due to it failing to work as advertised, I just use `cfn-lint --info -e` to grab the transformed template and use that for realz.
(context: I've never had to write 1000-line yaml files for kubernetes)