ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
## 安装 ~~~ yum install -y ansible ~~~ 在centos7上会安装以下依赖 ~~~ PyYAML libtomcrypt libtommath libyaml python-babel python-backports python-backports-ssl_match_hostname python-httplib2 python-jinja2 python-keyczar python-markupsafe python-setuptools python-six python2-crypto python2-ecdsa python2-paramiko python2-pyasn1 sshpass ~~~ ## 认证 ### 生成密钥 ~~~ ssh-keygen -t rsa # 或者,免输入密码和私钥文件路径 ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa ~~~ ### 复制密钥到客户机 ~~~ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.101.175 ~~~ ### 认证测试 登录成功即密钥测试通过 ~~~ ssh node2.test.com ~~~ 或者将主机加入ansible的hosts后,使用ping模块进行测试 ~~~ ansible test -m ping 192.168.101.175 | SUCCESS => { "changed": false, "ping": "pong" } ~~~ ### 查看文档 ~~~ ansible-doc -l 列出所有模块 ansible-doc -s 列出某一模块的帮助 ~~~ ### ansible命令格式 ~~~ ansible <host-pattern> [-m module_name] [-a args] [options] -C, --check # 只是测试将会执行的操作,不进行任何实质性的操作 -f, --forks=NUM # 并发数 -i, --inventory=PATH # 主机列表文件 -T, --timeout=SECONDS # 超时时间 ~~~ >[info] all 代表所有在主机列表中的主机