About YAML:
* YAML是一种用来表达资料序列的格式。YAML是YAML Ain‘t Markup Lanaguage的缩写,即YAML不是XML。* 特点: 1.具有很好的可续性,易于实现; 2.表达能力强,扩展性好; 3.和脚本语言的交互性好; 4.有一个一致的信息模型; 5.可以基于流来处理;
YAML Syntax:
* YAML的语法和其他语言类似,也可以表达散列表、标量等数据结构。* YAML结构通过空格来展示;序列里的项用“-”来代表;Map里的键值对用“:”来分割。YAML文件扩展名通常为:yaml,如:example.yaml* 基本语法规则: 1.大小写敏感 2.使用缩进表示层级关系 3.缩进时不允许使用Tab键,只允许使用空格。 4.缩进的空格数目不重要,只要相同层级的元素左侧对齐即可* 示例:name:zhangsanage:20name:lisiage:22people:-name:zhangsan age:20 -name:lisi age:22
Common Types of data:
YAML支持的数据结构:1.对象:键值对的集合,又称为映射(mapping)/ 哈希(hashes) / 字典(dictionary) 例如:name:Example Developer (键值)2.数组:一组按次序排列的值,又称为序列(sequence) / 列表(list) 例如: -Apple -Orange3.纯量:单个的、不可再分的值 例如: number:10.10 sure:true
Ansible Basic elements:
**Ansible基本元素主要包括:Inventory(主机清单)、变量、条件测试****其中:*** **Inventory(主机清单)**:①、主机变量 ②、组变量 ③、组嵌套 ④、Inventory参数* **变量**:①、通过命令行传递变量 ②、通过roles传递变量* **条件测试**:when语句和迭代
Ansible Basic elements:
** Inventory(主机清单)*** Ansible为了更加便捷的管理主机,在主机清单中将被管理主机进行分组命名,默认的主机清单为/etc/ansible/hosts文件。* Inventory文件中以中括号中的字符标识为组名,将主机分组管理,也可以将同一主机同时划分到不同的组中。* 如:[webserver]192.168.72.129[mysql]192.168.72.130
**①, Host variables * * You can add host variables when you define them for use in subsequent playbook, such as: [Webserver]www1.magedu.com http_port=80 Maxrequestschild=808**②, group variables * * Group variables are variables that can be used directly in playbook for the specified host settings, such as: [Webserver]ntp_server=ntp.example.orgnfs_server=nfs.example.org**③, group nesting **[ Tomcat]http.example.org[nginx]nginx.example.org[webserver:children]tomcatnginx**④, Inventory parameters * * Parameters Meaning Ansible_ssh_host//the remote hostname to which the connection is to be connected. This variable can be set with the alias of the host you want to set. Ansible_ssh_port SSH//port number. If it is not the default port number, this variable is set. ANSI Ble_ssh_user//default SSH username ansible_ssh_pass ssh//password (this method is not secure, we strongly recommend using--ask-pass or SSH key) ansible_ssh_private _key_file SSH//used private key file. Applies to multiple keys, and you don't want to use an SSH proxy. Ansible_ssh_common_args//This setting is appended to the default command line for SFTP,SCP and SSH ansible_sftp_e Xtra_args//This setting is appended to the default SFTP command line. Ansible_scp_extra_args//This setting is appended to the default SCP command line. Ansible_ssh_extra_args//This setting is attached to the default SSH command line. Ansible_ssh_pipelining//Determines whether to use the SSH pipeline. This can override the Ansible.cfg setting. The shell type of the Ansible_shell_type//target system. By default, the execution of the command uses the ' SH ' syntax, which can be set to ' csh ' or ' fish '. AnsiblThe python path of the E_python_interpreter//target host. The case: There are multiple python in the system, or the command path is not "/usr/bin/python", such as *bsd, or/usr/bin/pythonan Sible_*_interpreter//The "*" here can be a ruby or Perl or other language interpreter, function and Ansible_python_interpreter similar to ansible_shell_executable// This sets the shell that the Ansible controller will use on the target machine, overwriting the configuration in Ansible.cfg, which defaults to/bin/sh.
Ansible Automation Koriyuki Yaml, base element