当前位置:网站首页>Ansible first knowledge of learning one
Ansible first knowledge of learning one
2022-07-23 13:57:00 【51CTO】
One 、Ansible What is it?
Only below Ansible A brief introduction to the main functions of , For details, please refer to the official website
Ansible It is an automatic operation and maintenance tool , Batch system configuration can be realized 、 Program deployment 、 Run commands and other configuration management and application deployment functions
Ansible Is based on Paramiko Developed , And based on modular work , It does not have the ability to deploy in bulk , It just provides a framework . What really has a batch deployment is Ansible Relevant modules running
Ansible There is no need to install any Agent End , Because it's based on SSH To communicate with the remote host
Two 、Ansible Architecture components

Ansible Basic architecture :
- The core engine : namely Ansible, As a whole Ansible At the heart of
- Core module (core modules): yes Ansible Built in modules , Use these modules to distribute resources to managed hosts , Make it perform specific tasks or match specific states
- Custom module (custom modules): If the core module cannot complete a certain function , You can add custom modules
- plug-in unit (plugins): Supplement for completing module functions , Including connection plug-ins 、 Email plug-ins, etc
- Connect plug-ins (Connection plugins): Responsible for communication with the managed host , In addition to support the use of SSH Outside the connection , It also supports other connection methods
- Host list (host inventory): Definition Ansible Managed hosts , The default is in hosts Define nodes in the configuration file , It also supports custom dynamic host list and specified configuration file path
- Script (playbook): Definition Ansible The configuration file for the task , Multiple tasks can be defined in one script , Script execution supports multiple tasks , Multiple tasks can be run by the control host , Manage multiple remote hosts at the same time
3、 ... and 、Ansible Related terms
The control node (Control node): Refers to the installation of Ansible The host , Also called Ansible Server side 、 Manager
- Ansible The control node is mainly used to publish running tasks , Execute control commands
- Ansible All programs are installed on the control node , The control node needs to be installed Python and Ansible Various dependent libraries required
Controlled nodes (Managed nodes): Also called client , I just want to use Ansible The client server that the server performs the task
Host list (Inventory): List of controlled nodes , Is the list of all hosts to be managed .
- Host manifest file (hosts): By default, the list of lists is saved in host In file , have access to IP Address or host name to represent the specific management host and authentication information , And can be grouped according to the users of the host ; The path of the file is :/etc/ansible/hosts (YUM In the case of installation )
- Default use hosts File definition host list , The list of hosts obtained in this way is called static acquisition ,Ansible It also supports the way of dynamically obtaining the host list ( I'll give you more details later )
- How to dynamically obtain the host list , Support the use of single or multiple Inventory , And supports a variety of file formats ( Yaml 、Py etc. ) ( I'll give you more details later )
modular (Modules): The module is Ansible A block of code that performs a specific task .Ansible Now it comes with by default 450 Multiple modules ,Ansible Galaxy The public repository contains approximately 1600 A module .
Mission (Task): Is in Ansible Operations performed on the client . have access to ad-hoc A single line command executes a task .
Script (Playbook): It's using YAML A list of repeatable tasks written in markup language ,Playbook The task is more convenient .
role (roles): The role is Ansible 1.2 New features introduced in the , For hierarchy 、 Organize... Structurally Playbook.Roles It can automatically load variable files according to the hierarchical structure 、tasks as well as handlers etc. .
Four 、Ansible Requirements for nodes
1、 Requirements for management host
- Python2 Version requires 2.6 perhaps 2.7,Python3 The version of requires a version higher than 3.5 ( At present, most of them are Centos7,Python The default is 2.7 Version of , It is required by the symbol )
- Windows The host cannot be used as a management host
2、 Requirements for the host of the node
Corresponding Python Version requirements for , The requirements of the management node above are the same
We use SSH Protocol and node communication , The default is to use Sftp The way , If Sftp Unavailable , You can configure files in ansible.cfg Is configured as Scp The way
5、 ... and 、Ansible install
1、 Installation instructions
- Ansible There are many ways to install , The main installation methods are — YUM install 、PIP install 、 Source code installation 、Apt-Get Way, etc , There are two common installation methods — YUM install 、PIP install , It is recommended YUM install
- YUM The installation will /etc Next, make a ansible Catalog ( It includes two files — ansible.cfg and hosts , A directory roles )
- PIP Relevant directories and files will not be produced in the system during installation , Go to the official website to download ansible.cfg file , And create hosts Document and roles Catalog , Use... After creation Ansible When , These directories and files will be automatically recognized
2、 Examples of common installation methods
6、 ... and 、Ansible Related command tools
| command | Function description |
|---|---|
| /usr/bin/ansible | The main program , Command execution tools |
| /usr/bin/ansible-docusr/bin/ansible | The main program , The command execution tool views the configuration document , Module function view tool |
| /usr/bin/ansible-playbook | Custom automated tasks , Script tools |
| /usr/bin/ansible-pull | A tool for remotely executing commands |
| /usr/bin/ansible-vault | File encryption tools |
| /usr/bin/ansible-console | be based on Console Tools that interact with the user interface |
| /usr/bin/ansible-galaxy | download / Upload excellent code or Roles The official website platform of the module |
7、 ... and 、Ansible Inventory Built in parameters
| Parameters | purpose |
|---|---|
| ansible_ssh_hosts | Definition hosts ssh Address |
| ansible_ssh_port | Definition hosts ssh port |
| ansible_ssh_user | Definition hosts ssh user |
| ansible_ssh_pass | Definition hosts ssh Authentication password |
| ansible_sudo | Definition hosts sudo user |
| ansible_sudo_pass | Definition hosts sudo password |
| ansible_sudo_exe | Definition hosts sudo route |
| ansible_connection | Definition hosts How to connect |
| ansible_ssh_shell_type | Definition hosts shell type |
| ansible_ssh_private_key_file | Definition hosts Private key |
| ansible_python_interpreter | Definition hosts Task execution python The path of |
| ansible_*_interpreter | Definition hosts The path of other language parsing |
8、 ... and 、Ansible Related directories and files
Directories generated after installation ( YUM install ), as follows
- Profile directory :/etc/ansible
- Directory of execution files :/usr/bin
- Lib The library depends on the directory :/usr/lib/python-$version/site-packages/ansible/
- Help Document directory :/usr/share/doc/ansible-$version/
- Man Document directory :/usr/share/man/man1/
Files generated after installation ( YUM install ), as follows
- Ansible Master profile :/etc/ansible/ansible.cfg
- Ansible Default host manifest file :/etc/ansible/hosts
Nine 、Ansible Profile description
1、 Priority of configuration file
From top to bottom , Priority decrement
2、 Master profile
3、 Host manifest configuration file
Ten 、Ansible First experience
1、Ansible The executive order of
Ansible Provide two commands to complete the task
- ad-hoc command , Can solve some simple tasks
- Ansible playbook, Solve more complex tasks
I'm learning Ansible At the beginning of the , Let's learn first ad-hoc command , As long as it is ansible command
2、 To configure SSH mutual trust
- In fact, this is not really SSH mutual trust , It's just Ansible One way mutual trust from the manager to the managed node
- real SSH Mutual trust means that two nodes can log in without secret , There is no need for the managed node to login to Ansible Manager
3、 edit hosts file
4、Ansible Examples of use
边栏推荐
- C#:readonly与const
- LeetCode_ 491_ Longest increasing subsequence
- 养老机构智能视频监控解决方案,用新技术助力养老院智慧监管
- 2022-07-22 review linked list operation and some problems
- LeetCode_ 51_ Queen n
- 2022 summer vacation software innovation laboratory training project practice 1
- MGRE实验
- MGRE环境下的OSPF实验:
- 数据库系统原理与应用教程(041)—— MySQL 查询(三):设置查询条件
- Matlab: convert PNG pictures into txt files
猜你喜欢

OSPF detailed explanation (LSA) (2)

Convergence of abnormal integral

FPGA:ov7725摄像头通过VGA/HDMI显示RGB565格式的图像

RIP实验

C #: in, out, ref keywords

Google Earth engine -- a small bug in gee. Images of transcontinental boundaries cannot be obtained

Événements courants de la souris et du clavier

ERP生产作业控制

常用的鼠标事件和键盘事件

CenterNet目标检测模型及CenterFusion融合目标检测模型
随机推荐
Is it risky and safe to open an account?
prometheus+node-exporter+grafana 监控服务器系统资源
数据库系统原理与应用教程(041)—— MySQL 查询(三):设置查询条件
图像处理2:均值滤波
LeetCode_ 2342_ Maximum sum of digits and equal pairs
Redis常用命令
ERP生产作业控制
Matlab: convert PNG pictures into txt files
做测试如何应对新的开发模式?
-20: +usecgroupmemorylimitforheap failed to create virtual machine problem
OSPF detailed explanation (LSA) (2)
APP常用跨端技术栈深入分析
类和对象(上)
数据库系统原理与应用教程(052)—— MySQL 的数据完整性(十四):交叉表查询(行列转换)
Image processing 7: test files
C#:in、out、ref关键字
script之type=module
企业科技展厅制作需要考虑这五点
静态综合实验(HCIA)
How to ensure the reliable transmission of messages? What if the message is lost