Update YAMLSyntax.rst with yamllint (#66622)
* Update YAMLSyntax.rst with yamllint Co-authored-by: Sandra McCann <samccann@redhat.com>
This commit is contained in:
parent
68620ced7f
commit
f35293c052
|
@ -5,7 +5,7 @@ YAML Syntax
|
||||||
===========
|
===========
|
||||||
|
|
||||||
This page provides a basic overview of correct YAML syntax, which is how Ansible
|
This page provides a basic overview of correct YAML syntax, which is how Ansible
|
||||||
playbooks (our configuration management language) are expressed.
|
playbooks (our configuration management language) are expressed.
|
||||||
|
|
||||||
We use YAML because it is easier for humans to read and write than other common
|
We use YAML because it is easier for humans to read and write than other common
|
||||||
data formats like XML or JSON. Further, there are libraries available in most
|
data formats like XML or JSON. Further, there are libraries available in most
|
||||||
|
@ -18,7 +18,7 @@ is used in practice.
|
||||||
YAML Basics
|
YAML Basics
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
For Ansible, nearly every YAML file starts with a list.
|
For Ansible, nearly every YAML file starts with a list.
|
||||||
Each item in the list is a list of key/value pairs, commonly
|
Each item in the list is a list of key/value pairs, commonly
|
||||||
called a "hash" or a "dictionary". So, we need to know how
|
called a "hash" or a "dictionary". So, we need to know how
|
||||||
to write lists and dictionaries in YAML.
|
to write lists and dictionaries in YAML.
|
||||||
|
@ -40,21 +40,21 @@ A dictionary is represented in a simple ``key: value`` form (the colon must be f
|
||||||
|
|
||||||
# An employee record
|
# An employee record
|
||||||
martin:
|
martin:
|
||||||
name: Martin D'vloper
|
name: Martin D'vloper
|
||||||
job: Developer
|
job: Developer
|
||||||
skill: Elite
|
skill: Elite
|
||||||
|
|
||||||
More complicated data structures are possible, such as lists of dictionaries, dictionaries whose values are lists or a mix of both::
|
More complicated data structures are possible, such as lists of dictionaries, dictionaries whose values are lists or a mix of both::
|
||||||
|
|
||||||
# Employee records
|
# Employee records
|
||||||
- martin:
|
- martin:
|
||||||
name: Martin D'vloper
|
name: Martin D'vloper
|
||||||
job: Developer
|
job: Developer
|
||||||
skills:
|
skills:
|
||||||
- python
|
- python
|
||||||
- perl
|
- perl
|
||||||
- pascal
|
- pascal
|
||||||
- tabitha:
|
- tabitha:
|
||||||
name: Tabitha Bitumen
|
name: Tabitha Bitumen
|
||||||
job: Developer
|
job: Developer
|
||||||
skills:
|
skills:
|
||||||
|
@ -80,6 +80,8 @@ Ansible doesn't really use these too much, but you can also specify a boolean va
|
||||||
likes_emacs: TRUE
|
likes_emacs: TRUE
|
||||||
uses_cvs: false
|
uses_cvs: false
|
||||||
|
|
||||||
|
Use lowercase 'true' or 'false' for boolean values in dictionaries if you want to be compatible with default yamllint options.
|
||||||
|
|
||||||
Values can span multiple lines using ``|`` or ``>``. Spanning multiple lines using a "Literal Block Scalar" ``|`` will include the newlines and any trailing spaces.
|
Values can span multiple lines using ``|`` or ``>``. Spanning multiple lines using a "Literal Block Scalar" ``|`` will include the newlines and any trailing spaces.
|
||||||
Using a "Folded Block Scalar" ``>`` will fold newlines to spaces; it's used to make what would otherwise be a very long line easier to read and edit.
|
Using a "Folded Block Scalar" ``>`` will fold newlines to spaces; it's used to make what would otherwise be a very long line easier to read and edit.
|
||||||
In either case the indentation will be ignored.
|
In either case the indentation will be ignored.
|
||||||
|
@ -117,18 +119,18 @@ This really has nothing to do with Ansible, but will give you a feel for the for
|
||||||
skill: Elite
|
skill: Elite
|
||||||
employed: True
|
employed: True
|
||||||
foods:
|
foods:
|
||||||
- Apple
|
- Apple
|
||||||
- Orange
|
- Orange
|
||||||
- Strawberry
|
- Strawberry
|
||||||
- Mango
|
- Mango
|
||||||
languages:
|
languages:
|
||||||
perl: Elite
|
perl: Elite
|
||||||
python: Elite
|
python: Elite
|
||||||
pascal: Lame
|
pascal: Lame
|
||||||
education: |
|
education: |
|
||||||
4 GCSEs
|
4 GCSEs
|
||||||
3 A-Levels
|
3 A-Levels
|
||||||
BSc in the Internet of Things
|
BSc in the Internet of Things
|
||||||
|
|
||||||
That's all you really need to know about YAML to start writing `Ansible` playbooks.
|
That's all you really need to know about YAML to start writing `Ansible` playbooks.
|
||||||
|
|
||||||
|
@ -152,7 +154,7 @@ Because of this, the following is going to result in a YAML syntax error::
|
||||||
You will want to quote hash values using colons followed by a space or the end of the line::
|
You will want to quote hash values using colons followed by a space or the end of the line::
|
||||||
|
|
||||||
foo: 'somebody said I should put a colon here: so I did'
|
foo: 'somebody said I should put a colon here: so I did'
|
||||||
|
|
||||||
windows_drive: 'c:'
|
windows_drive: 'c:'
|
||||||
|
|
||||||
...and then the colon will be preserved.
|
...and then the colon will be preserved.
|
||||||
|
@ -160,7 +162,7 @@ You will want to quote hash values using colons followed by a space or the end o
|
||||||
Alternatively, you can use double quotes::
|
Alternatively, you can use double quotes::
|
||||||
|
|
||||||
foo: "somebody said I should put a colon here: so I did"
|
foo: "somebody said I should put a colon here: so I did"
|
||||||
|
|
||||||
windows_drive: "c:"
|
windows_drive: "c:"
|
||||||
|
|
||||||
The difference between single quotes and double quotes is that in double quotes
|
The difference between single quotes and double quotes is that in double quotes
|
||||||
|
@ -238,4 +240,3 @@ value::
|
||||||
implementing
|
implementing
|
||||||
`YAML 1.2 Specification <https://yaml.org/spec/1.2/spec.html>`_
|
`YAML 1.2 Specification <https://yaml.org/spec/1.2/spec.html>`_
|
||||||
For completeness, YAML 1.2 is the successor of 1.1
|
For completeness, YAML 1.2 is the successor of 1.1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue