Top
Best
New

Posted by carlos-menezes 4/12/2025

YAML: The Norway Problem (2022)(www.bram.us)
222 points | 164 commentspage 3
thyrsus 4/13/2025|
I do a lot of ansible which needs to run on multiple versions, and their yaml typing are not consistent - whenever I have a variable in a logic statement, I nearly always need to apply the "| bool" filter.
mdaniel 4/13/2025||
This is likely hair splitting, but you are far more likely getting bitten by the monster amount of variance in jinja2 versions/behaviors than by anything "yaml-y"

For example, yaml does not care about this whatsoever

  - name: skip on Tuesdays
    when: ansible_date_time.weekday != "Tuesday"
but different ansible versions are pretty yolo about whether one needs to additionally wrap those fields in jinja2 mustaches

  - name: skip on Tuesdays
    when: '{{ ansible_date_time.weekday != "Tuesday" }}'
and another common bug is when the user tries to pass in a boolean via "-e" because those are coerced into string key-value pairs as in

  $ ansible -e not_today=true -m debug -a var=not_today all
  localhost | SUCCESS => {
    "not_today": "true"
  }
but if one uses the jinja/python compatible flavor, it does the thing

  $ ansible -e not_today=True -m debug -a var=not_today all
  localhost | SUCCESS => {
    "not_today": true
  }

It may be more work than you care for, since sprinkling rampant |bool likely doesn't actively hurt anything, but the |type_debug filter[1] can help if it's behaving mysteriously

1: https://docs.ansible.com/ansible/11/collections/ansible/buil...

polski-g 4/13/2025||
Yep. I just want strict yaml:

anything encased in quotes is a string, anything not is not a string (bool, int or float)

awestroke 4/13/2025|||
Including keys?
TZubiri 4/13/2025||
That edge case sounds like a reasonable tradeoff you would make for such a simple and readable generic data format.

Escaped json probably hits that sweetspot by being a bit uglier than yaml, but 100 times simpler than xml, though.

tetha 4/13/2025|
Mh, since I just commented about ansible, you just made XML-based ansible flash in front of my eyes. I think I'm in a bit of pain now.

    <tasks>
        <ansible.builtin.copy notify="restart minio">
            <src> files/minio.service </src>
            <dest> /etc/systemd/system/minio.service </dest>
            <owner> root </owner>
            <group> root </group>
            <mode> 0x644 </mode>
        </ansible.builtin.copy>
    </tasks>
But you could use XSLT to generate documentation in XHTML from your playbooks about what files are deployed, what services are managed...
mdaniel 4/13/2025||
I will die on the hill than writing out ansible.builtin. are characters of my life I'll never get back, and refuse to. If it's built in why do I have to qualify it?!

Also, watch out: 0x644 != 0644 which is the mode you meant

endofreach 4/13/2025||
The article mentioned people with the last name "null". I never thought about that. It sounds like really fun in modern days to have that last name.
mdaniel 4/13/2025|
There have been several write-ups about it: https://news.ycombinator.com/item?id=43113997 https://news.ycombinator.com/item?id=15046223
singpolyma3 4/13/2025||
Quote your strings
pavel_lishin 4/13/2025|
Empty the footgun before firing.
maelito 4/13/2025||
We should use very basic yaml parsers without these kind of functions.
praptak 4/13/2025||
Related: the YAML exponent problem[0]

TLDR: unquoted hex hash in YAML is fine until it happens to match \d+E\d+ when it gets interpreted as a float in scientific notation.

[0]https://www.brautaset.org/posts/yaml-exponent-problem.html

normie3000 4/13/2025||
Google App Engine used to do this to environment variables defined in YAML. IIRC it would convert the string "true" to "Yes", which was a fun surprise when deploying Java And NodeJS apps.
riffraff 4/13/2025||
Usual reminder that this is not a problem in YAML 1.2 released 15 years ago.

Sadly many libraries still don't support it.

lifthrasiir 4/13/2025|
This effectively means that a new version of specification didn't solve the problem at all.
stephenr 4/13/2025||
It's not a coincidence that YAML is a perfect acronym for "yet another migraine looming".

I mean ok it is technically a coincidence but it definitely feels like the direct result of the "what could possibly go wrong" approach the spec writers apparently took

ghuntley 4/13/2025|
See also https://noyaml.com (feel send in PRs with your gripes/gotchas re: YAML)
More comments...