Linux shell get value of a field from a yml file

There are better tools than sed. You might be stuck on a minimal system, but other people looking for an answer probably won’t be. The python version of yq acts like jq: $ pip3 install yq $ yq -r .test.database database.yml sample shyaml works too, but has an odd restriction that you can only redirect … Read more

YAML indentation for array in hash

The short answer is that both are valid because they are unambiguous for the YAML parser. This fact was already pointed by the other answers, but allow me to add some gasoline to this discussion. YAML uses indentation not only for aesthetics or readability, it has a crucial meaning when composing different data structures and … Read more

Spaces in YAML keys

One thing is what is allowed, another is what is human readable. Spaces are allowed in keys according to the specification and for those you don’t need quotes (double or single, each with their own use). It is just a scalar string containing a space. As for human readability, I tend to think of a … Read more

Nested lists in yaml

And the answer is: URL: Description: URL of the website Value: “Fn::Join”: – “” – – “http://” – “Fn::GetAtt”: – ElasticLoadBalancer – DNSName (see http://pyyaml.org/wiki/PyYAMLDocumentation#YAMLsyntax – “block sequences can be nested”)

YAML comments in multi-line strings

No. Per the YAML 1.2 spec “Comments must not appear inside scalars”. Which is exactly the case here. There’s no way in YAML to escape the octothorpe symbol (#) so within a multi-line string there’s no way to disambiguate the comment from the raw string value. You can however interleave comments within a collection. For … Read more

What is a complex mapping key in YAML?

The spec isn’t very clear, but after a bit of head-scratching I figured it out. YAML has two kinds of block mapping keys: implicit and explicit. The implicit style is the kind you’re familiar with: mapping: foo: 1 bar baz: 2 “qux:quux”: 3 If we load this YAML in Ruby (for example) we get the … Read more

What is `

Well, those are elements of the YAML file format, which is used here to provide a configuration file for configtxgen. The “&” sign mean anchor and “*” reference to the anchor, this is basically used to avoid duplication, for example: person: &person name: “John Doe” employee: &employee << : *person salary : 5000 will reuse … Read more