ansible的介绍与hosts文件(一)
ansible是一个可以在远程主机上批量执行命令或者脚本的命令的工具
ansible底层是使用ssh协议实现的
ssh的端口是22
ping命令走的是网络层,走的协议是ICMP
ansible的安装
epel源:一个国内的第三方库,里面有好多ios镜像
阿里巴巴镜像源:https://developer.aliyun.com/mirror/
1.安装wget
yum install wget -y
2.安装epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
3.安装ansible
yum install ansible -y
安装完成ansible后,etc文件夹下生成ansible对应的文件与文件夹,分别是(文件:ansible.cfghe hosts),文件夹:roles
[root@192 ~]# ls /etc/ansible/ ansible.cfg hosts roles
ansible的默认文件hosts
[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 ~]#