ansible服务部署安装

一、下载ansible软件包
ps:需要依赖epel源,提前设置好

[root@ m01 ~]# yum install -y ansible
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                          | 3.6 kB     00:00     
epel                                          | 4.7 kB     00:00     
extras                                        | 2.9 kB     00:00     
updates                                       | 2.9 kB     00:00     
(1/2): epel/x86_64/updateinfo                   | 1.0 MB   00:20     
(2/2): epel/x86_64/primary_db                   | 6.9 MB   00:59     
Package ansible-2.9.18-1.el7.noarch already installed and latest version
本机已经提前安装好。
 [root@ m01 ~]# cat /etc/ansible/ansible.cfg
 ansible服务配置文件

主机清单文件,定义可以管理的主机

[root@ m01 ~]# cat /etc/ansible/hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers.

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group

## [webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110

# If you have multiple hosts following a pattern you can specify
# them like this:

## www[001:006].example.com

# Ex 3: A collection of database servers in the 'dbservers' group

## [dbservers]
## 
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57

# Here's another example of host ranges, this time there are no
# leading 0s:

## db-[99:101]-node.example.com
#定义可以管理主机的信息
172.168.3.31
172.168.3.41
172.168.3.7
=========================================
 /etc/ansible/roles
 角色目录

二、编写主机清单文件

[root@ m01 ~]# echo "#定义可以管理的主机信息/n172.168.3.41/n172.168.3.31/n172.168.7" >> /etc/ansible/hosts

三、测试是否可以管理多个主机

[root@ m01 ~]# ansible all -a "hostname"
172.168.3.41 | CHANGED | rc=0 >>
backup
172.168.3.31 | CHANGED | rc=0 >>
nfs01

上一篇:github访问速度慢怎么解决


下一篇:修改hosts文件,提高访问github的速度(github外网的登录问题)