Swordsman Ansible Sword--yaml Language and Inventory host list

Source: Internet
Author: User
Tags naming convention scp command ssh port

YAML Introduction
    • YAML is a format used to express resource sequences, and is highly readable because of the reference to other multilingual languages. YAML is the abbreviation for Yaml Ain ' t a Markup language, which is that YAML is not XML. But in developing this language, YAML is actually meant to be yaml another Markup Language (still a markup language). The characteristics are as follows:
(1)、具有很好的可读性,易于实现;(2)、表达能力强,扩展性好;(3)、和脚本语言的交互性较好;(4)、有一个一致的信息模型;(5)、可以基于流来处理
1. YAML syntax
    • Yaml's syntax is similar to other languages, and it can also express data structures such as hash lists, scalars, and so on. The structure (structure) is displayed by a space, and the sequence (sequence) is denoted by "-", and the key value in the map is separated by ":". The Yaml file extension is typically: Yaml, such as: Example.yaml.
2. Common data types
    • There are commonly used data types in Yaml, list and dictionary, respectively.
1), List
    • All the elements of the list are prefaced with "-", such as:
- Apple- Orange- Strawberry- Mango
2), Dictionary
    • The Dictionary (dictionary) is identified by key and value, such as:
name: Example DeveloperJob: DeveloperSkill:Elite
    • You can also use Key:value as a representation in {}, such as:
{name: Example Developer,Job: Developer,Skill:Elite}
Inventory Host Inventory
    • Ansible for more convenient management of the host, in the host list will be managed host group naming, the default host inventory is the/etc/ansible/hosts file, the host manifest can be set to multiple, or dynamic inventory can be generated dynamically.
    • The inventory file is identified as a group name with the characters in brackets, the host group is managed, or the same host can be divided into different groups at the same time. If the managed host uses a non-default SSH port, it can also be marked with a colon plus port after the host name, such as:
[webserver]      #方括号设置组名www1.test.org    #定义被监控主机,这边可以是主机名也可以是IP地址,主机名需要修改/etc/hosts文件www2.test.org:2222     #冒号后定义远程连接端口,默认是ssh的2222端口
    • If the host name of the managed host follows a similar naming convention, you can use the list's way table to identify the individual hosts, such as:
[webserver]www[01:50].test.org ansible_ssh_user=root ansible_ssh_pass=123456    #支持01到50,用户为root,密码为123456[dbbservers]db-[a:f].test.org        #支持匹配a b c ... f
There are several important concepts in inventory.
    • 1), host variables
    • Host variables can be added when the host is defined for use in subsequent playbook, such as
[webserver]www1.test.com http_port=80 maxRequestsChild=808www2.test.com http_port=8080 maxRequestsChild=909
    • 2), group variables
    • A group variable is a variable that is set up to be used directly by the specified host in playbook, such as:
[servers:vars]ntp_server=ntp.test.orgnfs_server=nfs.test.org
    • 3), group nesting
    • Groups in inventory can also nest other groups, or you can specify variables like hosts in a group. However, these variables can only be used in the Ansible-playbook tool, and direct use of the Ansible tool is not supported, such as:
[apache]http1.test.orghttp2.test.org[nginx]ngx1.test.orgngx2.test.org[webservers:children]apachenginx
    • 4), Inventory parameters
    • Ansible You can also specify the interaction mode by using parameters, based on the managed host specified in SSH connection inventory:
Parameters Description
Ansible_ssh_host The name of the remote host that will be connected. This variable can be used to set the alias of the host you want to set.
Ansible_ssh_port SSH port number. This variable is set if it is not the default port number.
Ansible_ssh_user The default SSH user name
Ansible_ssh_pass SSH password (This method is not secure, we strongly recommend using--ask-pass or SSH keys)
Ansible_ssh_private_key_file The private key file that is used by SSH. For cases where there are multiple keys and you do not 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_extra_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 appended to the default SSH command line.
Ansible_ssh_pipelining Determine whether to use the SSH pipeline. This can override the Ansible.cfg setting.
Ansible_shell_type The shell type of the target system. By default, command execution uses the ' SH ' syntax, which can be set to ' csh ' or ' fish '.
Ansible_python_interpreter The python path of the destination host. Applicable: There are multiple python in the system, or the command path is 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 in function to Ansible_python_interpreter
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.
    • If you do not use SSH key authentication, you can then authenticate the management host:
[websers]192.168.100.1 ansible_ssh_user=root ansible_ssh_pass=123456     #IP地址、用户、密码

Swordsman Ansible Sword--yaml Language and Inventory host list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.