Introduction to YAML:
* YAML is a format used to express data sequences. YAML is the abbreviation of YAML Ain't Markup Lanaguage, that is, YAML is not XML.
* characteristics:
1. It has good continuity and is easy to implement.
2. Strong expressive ability and good expansibility;
3. Good interaction with scripting language;
4. Have a consistent information model;
5. It can be processed based on flow.
YAML grammar:
* YAML Its grammar is similar to that of other languages. It can also express data structures such as hash tables and scalars.
* YAML The structure is shown by spaces; the items in the sequence are shown by "-"To represent; Map The key-value pairs are divided by ":". YAML File extensions are usually: yaml,Such as: example.yaml
* Basic grammatical rules:
1.Case-sensitive
2.Use indentation to represent hierarchical relationships
3.Not allowed to use indentation Tab Keys, only spaces are allowed.
4.The number of indented spaces is not important, as long as the elements of the same level are aligned to the left.
* Example:
name:zhangsan
age:20
name:lisi
age:22
people:
-name:zhangsan
age:20
-name:lisi
age:22
Common data types:
Data structures supported by YAML:
1. Object: A set of key-value pairs, also known as mapping/hashes/dictionary
For example: name:Example Developer (key value)
2. Array: A set of sequentially arranged values, also known as sequence s/list s
For example:
-Apple
-Orange
3. Pure Quantity: Individual, Non-separable Values
For example:
number: 10.10
sure: true
Ansible Basic Elements:
** The basic elements of Ansible include Inventory, Variables, Conditional Testing**
** Among them: **
* ** Inventory **: 1, host variables 2, group variables 3, group nesting 4, Inventory parameters
* ** Variables **: 1. Passing Variables through Command Line 2. Passing Variables through roles
* ** Conditional Test **: when Statement and Iteration
Ansible Basic Elements Detailed:
** Inventory(Host List)**
* Ansible In order to manage hosts more conveniently, the managed hosts are grouped and named in the list of hosts. The default list of hosts is/etc/ansible/hosts Papers.
* Inventory In the file, the characters in brackets are used as group names to manage the hosts in groups, and the same host can also be divided into different groups at the same time.
* Such as:
[webserver]
192.168.72.129
[mysql]
192.168.72.130
**①,Host variable**
//Host variables can be added at definition time for use in subsequent Playbook s, such as:
[webserver]
www1.magedu.com http_port=80 maxRequestsChild=808
**②,Group variable**
//Group variables refer to the variables that can be used directly in Playbook for a specified host, such as:
[webserver]
ntp_server=ntp.example.org
nfs_server=nfs.example.org
**③,group nesting**
[tomcat]
http.example.org
[nginx]
nginx.example.org
[webserver:children]
tomcat
nginx
**④,Inventory parameter**
//Parameter//Meaning
ansible_ssh_host //The remote host name to be connected. This variable can be used to set the alias of the host you want to set.
ansible_ssh_port ssh //Port number. If it is not the default port number, set it through this variable.
ansible_ssh_user //Default ssh username
ansible_ssh_pass ssh //Password (which is not safe, we strongly recommend -- ask-pass or SSH key)
ansible_ssh_private_key_file ssh //Private key file used. Suitable for multiple keys, and you do not want to use SSH proxy.
ansible_ssh_common_args //This setting is attached to the default command lines of sftp, scp, and ssh
ansible_sftp_extra_args //This setting is attached to the default sftp command line.
ansible_scp_extra_args //This setting is attached to the default scp command line.
ansible_ssh_extra_args //This setting is attached to the default ssh command line.
ansible_ssh_pipelining //Determine whether SSH pipes are used. This can override the settings in ansible.cfg.
ansible_shell_type //The shell type of the target system. By default, command execution uses the `sh'grammar, which can be set to `csh' or `fish'.
ansible_python_interpreter //The Python path of the target host. Suitable for situations where there are multiple Pythons in the system, or command paths are not "/ usr/bin/python", such as * BSD, or / usr/bin/python
ansible_*_interpreter //The "*" here can be an interpreter for ruby or perl or other languages, similar to ansible_python_interpreter
ansible_shell_executable //This will set the shell that the ansible controller will use on the target machine, overriding the configuration in ansible.cfg, defaulting to / bin/sh.