构建ansible学习环境

1.设置主机名

命名命令:hostnamectl set-hostname xx

设置4台主机

                        servera        serverb        serverc        serverd

2.配置扩展源

1)cd /etc/yum.reops.d/

2)vim local.repo

[biaoshi]
 name=miaoshu
 baseurl=/mnt/BaseOS
 enable=1
 gpgcheck=0
 [biaoshi2]
 name=miaoshu2
 baseurl=/mnt/AppStream
 enable=1
 gpgcheck=0
 

mount /dev/sr0  /mnt
 

3.域名映射

在servera上设置

vim /etc/hosts

192.168.233.132     servera
192.168.233.139     serverb
192.168.233.140     serverc
192.168.233.141     serverd
 

4.servera以root配置到所有机器免密互信

[root@servera ~]# ssh-keygen  -f  ~/.ssh/id_rsa  -P  ' '  -q
[root@servera ~]# ls  ~/.ssh
id_rsa  id_rsa.pub
 

分发到所有节点:

[root@servera ~]# for i in server{a..d}
> do
> ssh-copy-id $i
> done
 

验证:

[root@servera ~]# for i in server{a..d}; do ssh $i hostname; done
servera
serverb
serverc
serverd
 

5.servera安装ansible

[root@servera ~]# yum install ansible -y
 

6.创建配置文件和清单文件

[root@servera ~]# mkdir ansible
[root@servera ~]# cd ansible
[root@servera ansible]# cp /etc/ansible/ansible.cfg  .
[root@servera ansible]# vim inventory 

[dev]
servera
  
 [test]
 serverb

 [balancers]
 serverb


 [prod]
 serverc
 serverd
 
 [webservers:children]
 prod
 

[root@servera ansible]# ansible all -m ping
 

你可能感兴趣的:(ansible,学习)