Ansible basic principles

A, ansible Introduction and use

1, ansible Introduction and Features

ansible is an automated tool operation and maintenance, based on Python development can be realized batch system settings, batch deployment, batch execution command functions. Features are as follows:

Ansible based entirely on the Python development requires python version 2.6 or higher.

Ansible a wealth of built-in modules, nearly 600 functional modules fully meet the daily needs

Ansible default management machine via SSH protocol, so clients do not need to use after any configuration, management-side configuration is good.

Ansible currently belong Redhat company, the latest version Ansible2.5.

2, ansible application environment

Automated deployment of application code

System Management Automation

Support the continued delivery automation

Support cloud computing, big data platform environment

Batch task execution can be written in the script, you do not distribute to remote can perform

Support non-root user management operation, support sudo

Written using python, and easier to maintain.

3, ansible installation

Here's installation environment is centos7.4 version of the operating system, you first need to install third-party epel Source:

[root@ACA8D5EF ~]# yum install epel-release

Ansible dependent python environment, but it is already a part of RHEL / Centos therefore recommended by mounting yum ansible:

[root@ACA8D5EF ~]# yum install ansible

4, ansible command suite

After installing ansible, ansible provided a total of seven instructions are: ansible, ansible-doc, ansible-galaxy, ansible-lint, ansible-playbook, ansible-pull, ansible-vault.

(1)、ansible

ansible is the core part of the instruction, which is mainly used to perform ad-hoc command, i.e. a single command. Default behind the need to talk to the host and Options section, when you do not specify a default module, using the command module.

(2)、ansible-doc

This command is used to view the module information, there are two common parameters and -s -l, as follows:

For example, to list all installed modules

# ansible-doc -l

View a specific module usage, such as viewing command module here

# ansible-doc -s command

(3)、ansible-galaxy

ansible-galaxy instructions for facilitating the download from the third party site https://galaxy.ansible.com/ extension module, which will be understood that under similar yum centos, pip or easy_install under python image.

(4)、ansible-lint

ansible-lint is a tool to check the syntax of the playbook. Usage is ansible-lint playbook.yml.

(5)、ansible-playbook

The directive is the most used commands, which after reading the playbook through the file, perform the appropriate action, this will be back as a priority in terms.

(6)、ansible-pull

This instruction requires the use of another mode comes to the ansible: pull mode, push mode, and that the opposite often usual, which applies to the following scenarios:

 There are a huge number of machines need to be configured, even with very high thread still have to spend a lot of time

 Anisble to run on a machine without a network connection, such as startup after installation.

(7)、ansible-vault

ansible-vault is mainly used in the configuration file contains sensitive information, do not want to be seen, vault can help you to encrypt / decrypt the configuration file, it is a high-level usage. For example in the main playbooks when it comes to passwords or other configuration variables, you can use this command encryption, so that we see is a cat through the password string class files when editing requires a password to open pre-set. This playbook file is executed, the need to add -ask-vault-pass parameters, the same password is required to run properly.

Two, ansible architecture and operating principles

1, ansible basic architecture

 

 Core : ansible

core modules (Core Modules) : built-in module is ansible, Ansible resource distribution module to the remote node to execute a particular task or match a particular state.

 Expansion Module (Custom Modules) : If the core module is not sufficient to perform certain functions, you can add expansion modules.

 plugin (Plugins) : complete smaller tasks. Auxiliary modules to complete a certain function.

 script (playbooks) : ansible mission profile, the plurality of tasks is defined in the script, it performed automatically by ansible. Nginx such as installing a service, then we can split this into a playbook for several tasks. For example: nginx first step is to download the installation package. The second step I may consider the need to do is to configure the document by my prior written nginx.conf the target server. The third step, we need to start up the service. The fourth step, we may need to check whether the port is normally open. These steps can then be integrated by the playbook, and then sent to the next through the inventory on the host you want to execute the script.

connector plug (ConnectiorPlugins) : ansible connection-based plug-in connection to each host, the default is based on the SSH connection to the target machine to perform operations, but it also supports other connection methods, so the need for plug-in connection, management-side support for local, ssh, paramiko three ways end connection is managed.

master list (for Inventory, Host) : policy definition ansible management host, the general only small environments need to write to the host IP address in the host file, but to the large-scale environment you need to use static or dynamic host inventory list of the afterlife target needs to perform a host.

2, ansible task execution mode

ansible perform automated tasks, divided into two execution modes:

. 1, ad-hoc : Bulk single module, a single execution of the command, called ad-hoc

2, playbook : This can be understood as an object-oriented programming, like the example above that you can put more into the task you want to perform a playbook, of course, a number of tasks on the logic of things is better to have up and down links. The overall goal can be accomplished through a number of tasks, this is the playbook.

3, ansible task execution process

Guess you like

Origin www.cnblogs.com/yxf-/p/11493963.html