当前位置:网站首页>Ansible installation and use
Ansible installation and use
2022-07-02 04:52:00 【Floating foam*】
brief introduction :ansible It is a new automatic operation and maintenance tool , be based on Python Development , A collection of operations and maintenance tools (puppet、cfengine、chef、func、fabric) The advantages of , Realized batch system configuration 、 Batch program deployment 、 Batch run command and other functions .
This experiment is tested by three hosts , One of them acts as a management machine , The other two managed hosts
List of articles
One 、ansible install
1.1 install epel Extended source
yum install -y epel-release.noarch
1.2 install ansible
yum install -y ansible

see ansinle edition 
After installation , There are many more ansible The command 
Two 、 Configure the host
2.1 To configure hosts file
Add the information of the other two hosts
vi /etc/ansible/hosts

perform ansible command , In fact, in this case, the password is written in clear text in the configuration file , Do not apply
ansible 10.49.33.58 -m ping

The second configuration file is only one ip, To execute the command, enter the password , It is inconvenient to maintain multiple hosts 
ansible 10.49.33.58 -m ping -k
Input password 
The third case , Key management can be generated , No password required , Easy to manage
Production key
ssh-keygen

By default, the generated key is placed in /root/.ssh/
ll /root/.ssh

2.2 Management key
id_rsa It's the private key
id_rsa.pub It's the public key , You need to send the public key to the managed host
Usage mode :
ssh-copy-id [-i [identity_file] ] [[email protected]]machine
-i: Specify the public key file
Local ssh Install the public key file to the corresponding account of the remote host :
ssh-copy-id [email protected]
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]10.49.33.58

After successful execution , We check on the target machine /root/.ssh The directory has been generated , And there is another one named authorized_keys The file of , What is stored in it is the original machine ssh-keygen Generated id_rsa.pub The content of 
Try logging in as prompted 10.49.33.58
ssh [email protected]10.49.33.58
Go straight into , No more passwords 
Empathy , Pass the public key to 10.49.33.59 in
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]10.49.33.59
The relevant operation configuration of public key authentication is completed , Can pass ansible The host connects to these hosts without password , It greatly improves the security
2.3 Managed host grouping
You can also group different hosts , The default configuration file also has prompts 
ansible test -m ping

thus , ordinary ansible Completion of construction management
3、 ... and 、ansible Composition Introduction
3.1 see ansible Directory file
tree /etc/ansible/
/etc/ansible/
├── ansible.cfg # The configuration file
├── hosts # Main warehouse Used to store information about remote hosts that need to be managed
└── roles # The directory where the characters are stored
3.2 Ansible Command parameter details
Ansible The command syntax is as follows :
ansible [-i Host files ] [-f batch ] [ Group name ] [-m Module name ] [-a Module parameters ]
Ansible The detailed parameters are as follows :
-i inventory_file—— Specifies the host file , If you don't specify , The default is /etc/ansible/hosts file , In the host file , Defined Ansible Host to control IP Or domain name , And its users 、 password
-f 10—— Indicates the number of synchronization processes specified to start
-m module—— Express Ansible Module to call
-a —— Specify the parameters of the module , It can be orders and so on
-sudo —— Said the use of ansible get sudo jurisdiction
-k —— Express ansible The use of SSH password
-u username—— To designate Ansible The executing user
-C —— Indicates command test
3.3 ansible Module function view
Ansible There are many modules , View all ansible Module , Use command :
ansible-doc -l

There are so many modules , On the left is the module name , On the right is the description of module functions
Check the function of a module in detail , And check its parameters , Can execute orders :
ansible-doc -s [ Module name ]

3.4 hosts file
hosts Files generally store our managed host information . Host list , Also called Inventory. All managed hosts need to be defined in this file . If you don't want to use the default list, you can use -i Option to specify a custom manifest file , Prevent multiple people from using a host list . If not defined in the host list file , Executing the command will prompt “No hosts matched”
thank you
边栏推荐
- 数学知识(欧拉函数)
- Social media search engine optimization and its importance
- Solution of DM database unable to open graphical interface
- Geotrust OV Multi - Domain Domain SSL Certificate rmb2100 per year contains several Domain names?
- Alibaba cloud polkit pkexec local rights lifting vulnerability
- June book news | 9 new books are listed, with a strong lineup and eyes closed!
- Mysql重点难题(2)汇总
- Realize the function of data uploading
- Several methods of capturing packets under CS framework
- [understand one article] FD_ Use of set
猜你喜欢

Gin framework learning code

Application of intelligent robot in agricultural ecology

Learn what definitelytyped is through the typescript development environment of SAP ui5

Go Chan's underlying principles

Rhcsa --- work on the fourth day

面试会问的 Promise.all()

Learn BeanShell before you dare to say you know JMeter

Let genuine SMS pressure measurement open source code

unable to execute xxx. SH: operation not permitted

Getting started with pytest ----- confitest Application of PY
随机推荐
社交媒体搜索引擎优化及其重要性
Binary tree problem solving (2)
MySQL table insert Chinese change? Solution to the problem of No
Exposure X8 Standard Version picture post filter PS, LR and other software plug-ins
June book news | 9 new books are listed, with a strong lineup and eyes closed!
Why can't you remember when reading? Why can't you remember- My technology learning methodology
Starting from the classification of database, I understand the map database
Common errors of dmrman offline backup
06 decorator mode
Rhcsa --- work on the third day
Several methods of capturing packets under CS framework
汇编语言中的标志位:CF、PF、AF、ZF、SF、TF、IF、DF、OF
AcrelEMS高速公路微电网能效管理平台与智能照明解决方案智慧点亮隧道
洛谷入门3【循环结构】题单题解
培养中小学生对教育机器人的热爱之心
Let正版短信测压开源源码
Cannot activate CONDA virtual environment in vscode
LeetCode-对链表进行插入排序
6月书讯 | 9本新书上市,阵容强大,闭眼入!
解析少儿编程中的动手搭建教程