首页 > 其他 > 详细

快速布局ansible内网环境

时间:2015-08-07 20:20:54      阅读:401      评论:0      收藏:0      [点我收藏+]

1.ansible的安装

yum -y install ansible

2.然后就是配置/etc/ansible/hosts,里面主要记载着你登录的ip或者别名以及登录时的用户以及密码,根据需求我这里把所有主机分为2类,[web]和[orther]

# cp /etc/ansible/hosts /etc/ansible/hosts-   #操作前备份

# vi web                          #创建web文件,记载主机ip以及密码(以下为例)

1.2.3.4   asdasd

2.4.5.6   sdsdfg

4.5.7.8   asdasd

7.5.3.4   asdafg


# vi ansible_web.sh                   #配置把ip和密码按格式批量输       

echo "[web]" >>/etc/ansible/hosts          入/etc/ansible/hosts脚本

for i in `cat web|awk ‘{print $1}‘`

do

pass=`cat web|grep "$i"|awk ‘{print $2}‘`

echo "$i ansible_ssh_user=root ansible_ssh_pass=$pass >> /etc/ansible/hosts

done


# bash +x ansible_web.sh 

# vi /etc/ansible/hosts                    #查看脚本是否实现成功

db-[99:101]-node.example.com

[web]

1.2.3.4 ansible_ssh_user=root ansible_ssh_pass=asdasd

2.4.5.6 ansible_ssh_user=root ansible_ssh_pass=sdsdfg

4.5.7.8 ansible_ssh_user=root ansible_ssh_pass=asdasd

7.5.3.4 ansible_ssh_user=root ansible_ssh_pass=asdafg #成功


# vi orther                             #创建orther文件记载web以外的主机

1.1.1.1  asdasd                           的ip和root登录密码

1.1.1.2  asdasd

1.1.1.3  asdasa

1.1.1.4  asdfas


# cp ansible_web.sh  ansible_orther.sh         

# sed -i   ‘s/web/orther/g‘ ansible_orther.sh     #配置orther批量输入ip和密码以及

# bash +x ansible_orther.sh                  登录格式到/etc/ansible/hosts


# vi /etc/ansible/hosts                    #验证是否成功键入

4.5.7.8 ansible_ssh_user=root ansible_ssh_pass=asdasd

7.5.3.4 ansible_ssh_user=root ansible_ssh_pass=asdafg

[orther]

1.1.1.1 ansible_ssh_user=root ansible_ssh_pass=asdasd

1.1.1.2 ansible_ssh_user=root ansible_ssh_pass=asdasd

1.1.1.3 ansible_ssh_user=root ansible_ssh_pass=asdasa

1.1.1.4 ansible_ssh_user=root ansible_ssh_pass=asdfas


  nice!很显然键入成功,于是ansible环境已搭好,你可以尽情的批量处理这些主机了!!

本文出自 “创新分享驰骋里外” 博客,请务必保留此出处http://10554846.blog.51cto.com/10544846/1682750

快速布局ansible内网环境

原文:http://10554846.blog.51cto.com/10544846/1682750

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