码迷,mamicode.com
首页 > 其他好文 > 详细

ansible实践-1

时间:2017-08-22 10:49:13      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:直接   ansi   密码   公钥   bin   ref   github   密钥对   使用   

 
不需要安装客户端,通过sshd去通信
基于模块工作,模块可以由任何语言开发
不仅支持命令行使用模块,也支持编写yaml格式的playbook
支持sudo
有提供UI(浏览器图形化)www.ansible.com/tower  10台主机以内免费
 
Ansible 安装
两台机器 172.7.15.106  172.7.15.111
只需要在106上安装ansible即可
 
yum install -y epel-release
yum install -y ansible
 
Ansible 配置密钥
 
106上生成密钥对
ssh-keygen -t rsa  直接回车即可,不用设置密钥密码
 
把公钥(id_rsa.pub)内容放到对方机器(111)的/root/.ssh/authorized_keys里面
 
111 上 mkdir /root/.ssh
scp .ssh/id_rsa.pub  172.7.15.111:/root/.ssh/authorized_keys
 
本机也要操作
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
关闭selinux
setenforce 0
 
Ansible更改配置文件
 
vi  /etc/ansible/hosts  //增加
[testhost]
127.0.0.1
172.7.15.111
 
说明: testhost为主机组名字,自定义的。 下面两个ip为组内的机器ip。
Ansible 远程执行命令
ansible testhost -m command -a ‘w‘
 
这样就可以批量执行命令了。这里的testhost为主机组名,-m后边是模块名字,-a后面是命令。当然我们也可以直接写一个ip,针对某一台机器来执行命令。
 
ansible 127.0.0.1 -m  command -a ‘hostname‘
 
错误: "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren‘t installed!"
解决: yum install -y libselinux-python
 
还有一个模块就是shell同样也可以实现  (shell支持管道)
ansible testhost -m shell -a ‘w‘

ansible实践-1

标签:直接   ansi   密码   公钥   bin   ref   github   密钥对   使用   

原文地址:http://www.cnblogs.com/weifeng1463/p/7410187.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!