yum list |grep ansible # 可以看到自带源里就有2.4版本的ansible
yum install -y ansible # 安装ansible
ssh-keygen -t rsa
# 一直回车,生成密钥对
ssh-copy-id root@192.168.127.129 # 将公钥上传至客户端
# /etc/ansible/hosts
[test] # 主机分组
192.168.127.129 # 已经做过密钥认证的主机地址,或主机名
# ansible_ssh_host 连接目标主机的地址
# ansible_ssh_port 连接目标主机的端口,默认 22 时无需指定
# ansible_ssh_user 连接目标主机默认用户
# ansible_ssh_pass 连接目标主机默认用户密码
# ansible_ssh_connection 目标主机连接类型,可以是 local 、ssh 或 paramiko
# ansible_ssh_private_key_file 连接目标主机的 ssh 私钥
# ansible_*_interpreter 指定采用非 Python 的其他脚本语言,如 Ruby 、Perl 或其他类似 ansible_python_interpreter 解释器
[root@localhost ~]# ansible test -m ping
192.168.127.129 | SUCCESS => {
"changed": false,
"ping": "pong"
}
# -i 指定 hosts 文件位置
# -u username 指定 SSH 连接的用户名
# -k 指定远程用户密码
# -f 指定并发数
# -s 如需要 root 权限执行时使用 ( 连接用户不是 root 时 )
# -K -s 时,-K 输入 root 密码