CentOS7 部署ansible

ansible安装

 


 

1.yum安装:

[root@localhost  ~]# yum -y install epel-release
[root@localhost  ~]# yum -y install ansible

2.编辑/etc/ansible/hosts文件:

[root@localhost ~]# vim /etc/ansible/hosts
[websevers]

192.168.0.37
192.168.0.45
192.168.0.46
192.168.0.47
192.168.0.48
192.168.0.49

3.ssh认证:

yum install -y sshpass
ssh-keygen -f /root/.ssh/id_rsa -P ''
export IP="192.168.1.61 192.168.1.62 192.168.1.63 192.168.1.64 192.168.1.65"            #如做host解析,直接使用hostname
export SSHPASS=123123
for HOST in $IP;do
     sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $HOST
done

或者生成ip文件推送密钥

for i in {99..128};do echo 172.16.51.$i >> iplist.txt;done

vim sshpush.sh

#!/usr/bin/bash
export SSHPASS="123456"
for i in `cat /root/iplist.txt`
do
sshpass -e ssh-copy-id -o StrictHostKeyChecking=no $i
done

 4.示例:

 

 

 

 

posted @ 2022-10-31 13:57  Noleaf  阅读(37)  评论(0编辑  收藏  举报