实验题目
有三台centos7 使用ansible批量安装httpd ,并且不同主机显示的网页根据主机名动态变化,比如:主机node1,网页显示welcome node1
ip:172.29.9.5 (ansible server)
ip: 172.29.9.6/17 (被管理的服务器)
实验步骤:
root@centos8 ~]#vim /etc/ssh/ssh_config
#修改下面一行
StrictHostKeyChecking no
- 配置ssh基于key的免密登录脚本
vi ssh_key.sh
#!/bin/bash
user=`whoami`
if [ $user != 'root' ];then
echo 'you id is not root!'
exit 2
fi
IPLIST="
172.29.9.6
172.29.9.17" #发送公钥到authorized_keyr的服务器ip列表
rpm -q sshpass &>/dev/null || yum -y install sshpass # 安装sshpass
[ -f /root/.ssh/id_rsa ] || ssh-keygen -f /root/.ssh/id_rsa -P '' #生成密钥对
export SSHPASS='123' #把root密码设置为环境变量,可以用sshpass -e 指定密码了
#下面用ssh-copy-id 把公钥拷贝到目标机器的 authorized_key文件中