#! /bin/bash
#安装中科大epel源
sudo yum install -y epel-release
sudo sed -e 's|^metalink=|#metalink=|g' \
-e 's|^#baseurl=https\?://download.fedoraproject.org/pub/epel/|baseurl=https://mirrors.ustc.edu.cn/epel/|g' \
-i.bak \
/etc/yum.repos.d/epel.repo
#直接yum安装ansible
yum install -y ansible
#手撕一个host,以用来管理从机
cd /etc/ansible
mv /etc/ansible/hosts /etc/ansible/hosts.bak
cat >/etc/ansible/hosts <<EOF
[web]
# 别名 ansible_ssh_host=从机ip
web-01 ansible_ssh_host=192.168.175.182
web-02 ansible_ssh_host=192.168.175.183
EOF
#ansible.cfg中
#建议打开log_path = /var/log/ansible.log
#基于密钥对连接
#主机:
#ssh-keygen
#敲三次回车
#复制给从机[root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.7
#[赋值给从机root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.8
ansible自动安装脚本
于 2021-10-13 18:53:22 首次发布