Ansible automated operation and maintenance - Introduction to the basic structure

A, Ansible Profile

What is 1.1 Ansible

  1. Ansible in recent years more and more fire The development of a python-based operation and maintenance of automated toolsPrimarily to help automate IT operation and maintenance work, reduce human error, improve business automation rate, improve operation and maintenance efficiency.Ansible is based on module to run, it does not have any ability to batch deployment, Ansible primarily to provide a framework for volume deployment. Commonly deployed software automation, provisioning automation, management automation, systematic system tasks, continuous integration, zero downtime smooth upgrade.

1.2 Why Ansible

  1. Ansible based entirely on the Python development, And DevOps (promote development, technical operations and quality assurance (QA) communication between departments, collaboration and integration) in the country already is a trend, Python is becoming more common, operation and maintenance personnel to develop their own tools threshold gradually reduced, so to facilitate the secondary development of Ansible
  2. Ansible wealth of built-in moduleAnd even specifically for the commercial platform of functional modules, fully meet the daily required functions
  3. In Ansible decentralized concept (a node is any person, any person can also become a center) next, The copy operation to complete configuration management center migration
  4. Agentless (no clients)The client without any configuration, configured by the management after the end can be used

Structure composed of 1.3 Ansible

  1. AnsibleIs Ansible command tools, tool execution core; one-time or temporary operations are performed by the command.
  2. Ansible Playbook, Script task (also known set of tasks), task scheduling is defined Ansible set profile, executed by the order Ansible, Yam format.
  3. InventoryListing Ansible management host, the default is / etc / ansible / hosts file.
  4. Modules, Ansible execute the command function modules, so far Ansible2.3 version, a total of 1039 modules. It may also be custom module.
  5. Plugins, Plug-in, supplemented with modules, often the type of connection plug, plug-loop, variable plug filter insert, with a relatively small plug-in function.
  6. API, To provide an application programming interface called third-party programs.

1.4 Ansible How it works

Here Insert Picture Description

1, Ansible no clients, so Ansible dependent on the underlying communication software,Linux system-based communications OpenSSH, Windows-based systems PowerShell, management must be an end Linux system

2. Ansible different roles during use, can be divided into:userAnsible toolset with Role of the object

3、 Ansible users From multiple dimensions, divided into the following ways:

  • CMDB to store configuration information and manages the enterprise IT architecture, operation and maintenance personnel can be combined CMDB and Ansible, issued a directive calling Ansible complete set of tools to achieve the goal desired by the operator directly through the CMDB.
  • PUBLIC (public cloud) / PRIVATE (private cloud), Ansible run as an API call based, Ansible provides a rich API Interface Language: PHP, Python, etc.
  • Ad-Hoc direct use of temporary assembly calls Ansible set of tools to accomplish the task execution.
  • By executing Playbooks pre-choreographed set of tasks in sequence to complete the task execution.

4、Ansible toolset (ansible command is Ansible core tools, commander)

  • : INVENTORY inventory management host ansible/etc/ansible/hosts (Audience ansible command execution)
  • API: Application program calls for third-party programming interface
  • MODULES: Rich built-in function modules also can be customized
  • PLUGINS: built-in and custom plug-in, complementary function modules, plug-type connector, plug-loop, variable plug, like plug-boilers, the frequently used functions

5、 Ansible role of the object
Ansible the role of objects, not just Linux and non-Linux operating system of the host, also it can act on all types of public / private cloud, network infrastructure business / non-business equipment

6, calling the relationship between the components of Ansible

When the user uses ansible or ansible-playbook (extra playbook read files), the server terminal in an ad-hoc ansible input command set or playbook, ansible will follow the rules of the pre-programmed by one playbooks disassembled as Play, then play organized into tasks ansible identifiable (task). All module then calls the tasks involved (module) and plug-ins (plugin), the set of tasks transfer to temporary files, or commands to the remote client executes and returns the results based on the host list inventory defined by ssh, if the temporary file execution completion is automatically deleted.

Here Insert Picture Description

7、Ansible task execution mode Divided into the following two categories:

  • ad-hoc mode (ad hoc module)
    using a single module, support batches execute a single command, which corresponds to a shell execute command in bash

  • playbook mode (play mode)
    ansible key management, a complete set of a plurality of task-based functionality through can be understood as a plurality of ad-hoc configuration file

1.5 Ansible communication mechanism

Ansible without any maintenance daemon process to achieve mutual communication, and communication is based on secure ssh secure connection unified industry standard. And because sshP is every linux host system software must be installed, so no need to install the remote host ansible end any additional process, you can achieve agentless (no clients), so as to realize the central idea of ​​going.Ansible non c / s architecture itself is not client-sideIts main features are as follows:

  • No client, just install ssh, python
  • 基于OpenSSL通信,底层基于SSH协议,Ansible默认使用ssh连接的,但是Ansible也支持其他的连接方式,其他的连接方式是需要插件的支持,才可以实现通信。
  • 支持密码和SSH认证,建议使用公私钥方式认证,因为密码认证方式的密码需明文写配置文件,虽然配置文件可加密,但会增加Ansible使用的复杂度.

1.6 常用的自动化运维工具比较

Here Insert Picture Description

二、Ansible相关文件及命令

2.1 Ansible生成的主要文件

  • /etc/ansible/ansible.cfg :配置文件
  • /etc/ansible/hosts :主机库(host inventory)管理被监控的主机
  • /usr/bin/ansible : 主程序
  • /usr/bin/ansible-doc : 文档
  • /usr/bin/ansible-playbook : 剧本

2.2 Ansible 的7个命令

1、 ansible是核心的指令
主要用于执行单条命令,默认跟的是主机和选项部分,默认不指定模块时,使用的是command模块(默认使用的模块可以在ansible.cfg修改):

2、ansible-doc

  • ansible-doc -h 用于查看模块的信息常见的参数-l -s
  • ansible-doc -l 列出已安装的模块
  • ansible-doc -s 模块 : 查查看具体模块的使用方法

3、ansible-galaxy

ansible-galaxy 从站点下载第三方的扩展模块

4、ansible-lint
ansible-lint是对playbook的语法进行检查的工具,也可以用ansible-playbook --syntax-check + 剧本名

5、ansible-playbook
ansible-playbook 读取playbook文件执行相应的动作,执行ansible-playbook的剧本

6、ansible-pull
ansible-pull 适用于数量多的机器配置,远程执行命令的工具。对运维架构能力比较强

7、ansible-vault

ansible-vault 配置文件有敏感信息,设置加密/解密这个配置文件

Published 102 original articles · won praise 21 · views 5327

Guess you like

Origin blog.csdn.net/ranrancc_/article/details/103113625