ansible的介绍与hosts文件(一)

ansible是一个可以在远程主机上批量执行命令或者脚本的命令的工具

ansible底层是使用ssh协议实现的

ssh的端口是22

ping命令走的是网络层,走的协议是ICMP

ansible的安装

  epel源:一个国内的第三方库,里面有好多ios镜像

  阿里巴巴镜像源:https://developer.aliyun.com/mirror/

1
1.安装wget <br>yum install wget -y<br>2.安装epel源<br>wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo<br>3.安装ansible<br>yum install ansible -y

安装完成ansible后,etc文件夹下生成ansible对应的文件与文件夹,分别是(文件:ansible.cfghe hosts),文件夹:roles

1
2
[root@192 ~]# ls /etc/ansible/
ansible.cfg  hosts  roles

ansible的默认文件hosts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[root@192 ~]# cat /etc/ansible/hosts
# This is the default ansible 'hosts' file.  #则这是一个默认文件
#
# It should live in /etc/ansible/hosts   #它必须在/etc/ansible/hosts中才能被执行
#
#   - Comments begin with the '#' character  #  #是注释
#   - Blank lines are ignored       #空白行可以hulve
#   - Groups of hosts are delimited by [header] elements  #hosts的分组用中括号[]
#   - You can enter hostnames or ip addresses   #你可以输入一个主机名或者ip地址
#   - A hostname/ip can be a member of multiple groups  #主机名或者ip可以是一个分组的成员
 
# Ex 1: Ungrouped hosts, specify before any group headers.  #示例1:不被分组的主机,具体说明在任何分组之前,下面示例2之前的是实例
 
## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10
192.168.8.139
192.168.8.140
192.168.8.141
 
# Ex 2: A collection of hosts belonging to the 'webservers' group  #示例2:ansible怎么分组:中括号里面是组名,中括号下面可以写IP地址或者域名
 
## [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:#如果有多台主机遵循一种模式,则可以像下面一样比如192.168.1.[1:100],就是192.168.1.1--192.168.1.100
 
## www[001:006].example.com
 
# Ex 3: A collection of database servers in the 'dbservers' group #示例3:
 
## [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
 
[root@192 ~]#

  

 

posted @   QV  阅读(1196)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
点击右上角即可分享
微信分享提示