ansible服务部署安装

本文介绍了如何在Linux环境中安装和配置Ansible,通过YUM安装并检查已安装版本。然后展示了如何编写主机清单文件,并测试管理多台主机,通过`ansible all -a hostname`命令验证连接和管理功能。

一、下载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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值