You can comment out just by adding #
.
comment(YAML)
#If you add, it will be a comment.
The YAML list is the same as the JSON, Ruby array, and Python list. (Strictly speaking, it's called a sequence in YAML)
list(YAML)
-Taro
-17 years old
-male
This is shown in JSON as follows.
list(JSON)
[
"Taro"
"17 years old"
"male"
]
A YAML dictionary is equal to a JSON object, a Python dictionary. (Strictly called mapping)
dictionary(YAML)
name:Pablo Diego Jose Francisco de Paula Juan Nepomuseno Maria de los Remedios Crispin Crispiano de la Sandissima Trinidad Luis y Picasso
age:17 years old
gender:male
In JSON, it is written as follows.
list(JSON)
{
"name": "Pablo Diego Jose Francisco de Paula Juan Nepomuseno Maria de los Remedios Crispin Crispiano de la Sandisima Trinidad Luis y Picasso",
"age" : "17 years old",
"gender": "male"
}
Line wrapping is possible with >
.
The YAML parser replaces line breaks with whitespace.
Wrap back(YAML)
name: >
Pablo Diego Jose Francisco de Paula Juan Nepomuseno>
Maria de los Remedios Crispin Crispiano de la>
Sandisima Trinidad Luis y Picasso
Just enclose the variable name in {{}}
.
Variable assignment(YAML)
name: Picasso
{{name}}
Below is a sample playbook.
Playbook.yml
---
- hosts: all
tasks:
- name: Hello World!
debug:
msg: "Hello World!"
If you write the above code in JSON, it will be as follows.
Playbook.json
[
{
"hosts": "all",
"tasks": {
"name": "Hello World!",
"debug": {
"msg": "Hello World!"
}
}
}
]
In other words, you can see that the playbook is written in the form of a dictionary list.
In the playbook
Below are some of the supported options in the playbook list.
name A comment indicating the contents of the list. Ansible outputs this at the start of execution.
hosts Specify the set of hosts to set.
become If this option is set to true, Ansible will sudo as the root user and execute all instructions (tasks). (Useful for managing Ubuntu servers.)
vars A list of variables and values.
tasks A list of instructions (tasks) to be executed on the host.
handler If Ansible detects a change in state, you can take further action by using a handler.
tasks
The modules that can be specified under tasks are listed below.
apt
Install and remove packages using the package manager apt.
copy
Copy the file from the local machine to the host.
file
Set file, symbolic link, and directory attributes.
service
Start, stop, and restart services.
template
Generate a file from the template and copy the file to the host.
(By the way, the difference between copy and template is whether variables can be used)
** Related materials **
Introduction to Ansible (1)'Hello World'
Introduction to Ansible Part ③'Inventory'
** References **
First Ansible (written by Lorin Hochstein, translated by Ryuji Tamagawa, O'Reilly Japan Co., Ltd.)
Recommended Posts