Automated operation and maintenance tools are many, from a functional implementation, maintenance costs, the system used to select, compare several common operation and maintenance tools:
Puppet based Ruby development, the C / S architecture, scalability, based on the SSL, remote command execution is relatively weak
SaltStack Python based development, the C / S architecture, relatively more lightweight puppet, YAML syntax configuration, so that a simpler configuration script
Ansible based on Python paramiko development, distributed, no client, lightweight, and Jinja2 YAML configuration syntax to use template language, more remote command execution operations.
so. Ansible!
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 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, easier to maintain
Ansible basic architecture
- ansible core
- core modules Core modules: a module that comes with the distribution ansible, Ansible module resources to the remote node to execute a particular task or match a particular state.
- custom modeles expansion module: if the core module is not sufficient to perform certain functions, you can add expansion modules.
- plugins plugins: complete smaller tasks. Auxiliary modules to complete a certain function.
- playbooks batch job configuration file: ansible task configuration file, multiple tasks defined in the script is executed 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.
- host inventory host group to define multiple hosts: ansible connections based on 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, the management side support local, ssh, paramiko three ways to connect the management side.
- connection plugins connect plugins connect remote host part: 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 afterlife goals need to perform host.
Ansible task execution process
Task execution process:
Press down on the order of execution:
1) reads the configuration: configuration file read ansible
2) a list of all machines crawling or groups managed: the list of hosts from the list (corresponding to the hosts file)
3) Use host-pattern filter machine lists: filter which machines do what
4) The execution module and configuration parameters: a dynamic read from the module or modules directory, according to the operation module performs the function of the remote host
5) Runner execute and return: DETAILED two steps: Connection links - to define the connection mode, Action Phase - given machine list, then access to the variables / resource files
6) output end: the implementation of the results of the feedback will manage end
working principle:
Management of the distal end of the management host (or script execution command), the remote host end of the execution result management feedback
specific:
首先管理端需要安装ansible工具;
其次配置ansible配置文件(/etc/ansible/ ansible.cfg)和定义被控制的主机或分组列表(/etc/ansible/hosts)并对相关主机变量进行定义;
然后ansible执行模块,将管理端本地执行路径(~/.ansible/tmp)将操作执行(命令或脚本),通过local/ssh/paramiko方式传到远端主机用户目录下(~/.ansible/tmp)并执行;
最后将执行结果反馈至管理端