Consider the following document:
foo:
bar: Yes
According to the spec, this should be interpreted as a Boolean
, not as a String
.
However, it seems that this document yields the same interpretation:
foo:
bar: 'Yes'
If I misunderstand, and 'Yes'
(in quotes) should in fact be understood as a String
-typed value, where in the specs can I find justification for this?
However, if I do interpret correctly, and these documents are equivalent according to spec, how can I specify a string with the value "Yes"
as the value of a YAML property?
In general, you don't need quotes. Use quotes to force a string, e.g. if your key or value is 10 but you want it to return a String and not a Fixnum, write '10' or "10" . Use quotes if your value includes special characters, (e.g. : , { , } , [ , ] , , , & , * , # , ? , | , - , < , > , = , ! , % , @ , \ ).
We use the standard numeric literals for integers and floating-point numbers. Boolean values can be represented in YAML using the keywords like true and false or Yes and No .
Quotes are required when the string contains special or reserved characters. The double-quoted style provides a way to express arbitrary strings, by using \ to escape characters and sequences. For instance, it is very useful when you need to embed a \n or a Unicode character in a string.
All YAML files (regardless of their association with Ansible or not) can optionally begin with --- and end with ... . This is part of the YAML format and indicates the start and end of a document. All members of a list are lines beginning at the same indentation level starting with a "- " (a dash and a space):
It depends ;-)
In YAML 1.1 the bool type is defined as following:
A Boolean represents a true/false value. Booleans are formatted as English words (“true”/“false”, “yes”/“no” or “on”/“off”) for readability and may be abbreviated as a single character “y”/“n” or “Y”/“N”.
In YAML 1.2 the bool type is defined as following:
Booleans: [ true, True, false, FALSE ]
Assigning the value Yes
to a key is done via quotes:
foo: 'Yes'
bar: "Yes"
Assigning a boolean and to be compatible with future versions of YAML parsers should be done with
foo: false
bar: True
You can play around yourself with YAML syntax at the https://yamlvalidator.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With