首页 > 其他 > 详细

ansible安装配置(一)

时间:2017-03-21 13:16:03      阅读:179      评论:0      收藏:0      [点我收藏+]

要求:linux CentOS release 6.8 (Final)

两台机器:192.168.1.2 192.168.1.3

1.只在192.168.1.2 安装

yum install epel-release

yum install ansible


2.在192.168.1.2上生成密钥对

ssh-keygen -t rsa  不设置密码 回车

cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys


cat /root/.ssh/id_rsa.pub 复制内容到192.168.1.3


vi /root/.ssh/authorized_keys

把id_rsa.pub内容复制到这里


两台

chmod 600 /root/.ssh/authorized_keys

关闭selinux


3.在192.168.1.2 vim /etc/ansible/hosts 

[ahost]

127.0.0.1

192.168.1.3


4.执行远程命令

ansible testhost -m command -a ‘w‘   ->指定工作组

-m 模块名

-a 命令


ansible testhost -m shell -a ‘w‘  ->可以指定管道

eg:

ansible testhost -m shell -a ‘ps -aux | grep ssh‘


ansible 127.0.0.1 -m command -a ‘hostname‘ ->指定单个机器


5.为了防止报错,建议安装

yum install -y libselinux-python


6.文件拷贝

ansible testhost -m copy -a "src=/etc/ansible dest=/tmp/ansibletest owner=root group=root mode=0644"


ansible testhost -m copy -a "src=/etc/passwd dest=/tmp/passwd"

ansible安装配置(一)

原文:http://rockycai.blog.51cto.com/8871643/1908706

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!