所有步骤均在ansible server主机上执行。
安装ansible
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum install ansible -y
cansible 到workder节点免密登录
生成公钥
ssh-keygen -t rsa
公钥拷贝到woker节点 *2
ssh-copy-id [email protected]
或者用脚本
yum install expect -y
#cat list
20.20.45.177 20.20.41.213
#cat copy_ssh_key.sh
#!/bin/bash while read line do user="root" ip=`echo $line | cut -d " " -f 1` passwd="1" echo ip: $ip echo pw: $passwd expect <<EOF set timeout 2s spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $user@$ip expect { "yes/no" { send "yes\n"; exp_continue } "password" { send "$passwd\n" } } expect "password" { send "$passwd\n" } EOF done < list
设置inventory
cat /etc/ansible/hosts
[client01] 20.20.45.177 [client02] 20.20.41.213
测试,(不能在项目目录下测试)
标签:入门,45.177,20.20,ip,echo,repo,ansible,测试 From: https://www.cnblogs.com/xiangyu5945/p/18134599