参考:https://blog.csdn.net/m0_66925868/article/details/143895968
环境搭建
#############ubuntu安装ansible#############
# 更新apt
apt update -y
# 安装ansible主控端
apt install -y ansible
#############centos安装ansible#############
# 更新yum
yum update -y
# 安装epel
yum -y install epel-release.noarch
# 安装ansible主控端
apt install -y ansible
#############生成RSA免密公钥#############
ssh-keygen.exe -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub root@xxx.xxx.xxx.xxx:/root
# sshpass -p <password> ssh-copy-id -i ~/.ssh/id_rsa.pub root@xxx.xxx.xxx.xxx
# scp id_rsa.pub root@xxx.xxx.xxx.xxx:/root/.ssh/id_rsa.pub && cat root/.ssh/id_rsa.pub >> root/.ssh/authorized_keys
########################################
配置文件介绍
# ansible配置文件目录
cd /etc/ansible
# ansible配置文件
vim ansible.cfg
# 简单配置示例
[defaults]
inventory = ~/.ansible/hosts # 清单文件路径
host_key_checking = False
# deprecation_warnings = False
interpreter_python = auto_legacy_silent
# 清单文件
vim ~/.ansible/hosts
# 清单文件配置示例
[host_01]
192.168.1.210
[host_02]
192.168.1.210
[group_name:children]
host_01
host_02
使用示例
# 查看所有主机连通性
ansible all -m ping