maxc1017 发表于 2018-7-30 11:24:49

快速布局ansible内网环境

  1.ansible的安装
  yum -y install ansible
  2.然后就是配置/etc/ansible/hosts,里面主要记载着你登录的ip或者别名以及登录时的用户以及密码,根据需求我这里把所有主机分为2类,和
  # 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 "" >>/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--node.example.com
  
  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.1asdasd                           的ip和root登录密码
  1.1.1.2asdasd
  1.1.1.3asdasa
  1.1.1.4asdfas
  # cp ansible_web.shansible_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
  
  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环境已搭好,你可以尽情的批量处理这些主机了!!
页: [1]
查看完整版本: 快速布局ansible内网环境