环境centos7.0:默认安装python2.6
[root@10-15-195-231 ~]# rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
[root@10-15-195-231 ~]#yum install ansible
[root@10-15-195-231 ~]# ansible --version
ansible 2.2.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
如有报错请查看报错内容,如缺少cryptography
[root@10-15-195-231 ~]# pip install cryptography
[root@10-15-195-231 ~]#ssh-keygen
创建公钥一路回车即可,将.ssh/id_rsa_pub放至测试机的/root/.ssh/authorized_keys 中实现密钥登录
[root@10-15-195-231 ~]# cd /etc/ansible/
[root@10-15-195-231 ansible]# ls
ansible.cfg hosts roles
在hosts里配置测试服务器,还可以设子组,还可以自动添加一串相数字或字母临的服务器;hosts可以有多个如ansible -i hosts -m ping表示PING当前目录HOSTS里的机器
[1:3].linuxtoy.org # 等价于
1.linuxtoy.org、2.linuxtoy.org、3.linuxtoy.org
[a:c].linuxtoy.org # 等价于
a.linuxtoy.org、b.linuxtoy.org、c.linuxtoy.org
[root@10-15-195-231 ansible]# cat hosts
[nginx]
10.15.100.55
[test-server]
10.15.66.32
[vps:children]
test-server
nginx
做PING测试
[root@10-15-195-231 ansible]# ansible -m ping all
10.15.66.32 | SUCCESS => {
"changed": false, "ping": "pong"}
继续阅读与本文标签相同的文章
-
受用一生的高效 PyCharm 使用技巧(四)
2026-05-19栏目: 教程
-
Springboot 之创建自定义starter
2026-05-19栏目: 教程
-
黑客们会用到哪些Python技术?
2026-05-19栏目: 教程
-
菜鸟如何在阿里云快速建站(pc站+手机站+公众号+小程序)
2026-05-19栏目: 教程
-
ansible--copy与fetch模块
2026-05-19栏目: 教程
