86565656 发表于 2018-7-29 14:28:25

一键安装ansible

  #!/bin/bash
  #Auther: xuebin
  #Description: 此脚本用来安装ansible
  set -u
  ####### 安装软件 ################
  rpm -ivhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
  if [[ $? -eq 0 ]];then
  echo "rpm ok"
  else
  echo "rpm on"
  read -p "查看是否安装成功,安装成功请按Y继续: " : Y
  fi
  yum -y install ansible
  if [[ $? -eq 0 ]];then
  echo "--------ansible ok---------"
  else
  echo "--------ansible off--------"
  exit 0
  fi
  ######### 默认安装 ########
  read -p "这里需要按几下回车键,请注意"
  ssh-keygen -t rsa
  sleep 2
  ######### 检查文件 ##################
  cd /etc/ansible/
  if ` -e hosts `;then
  echo " hosts yes "
  else
  echo " hosts no "
  read -p "文件缺失,请检查"
  fi
  ########## 写入配置文件 ######################
  echo "" >> /etc/ansible/hosts
  /sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:">> /etc/ansible/hosts
  echo "" >> /etc/ansible/hosts
  /sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:">> /etc/ansible/hosts
  ##### 远程主机#########
  read -p "输入本机远程端口:" port
  echo "请根据提示信息,输入yes和密码"
  ssh-copy-id -i /root/.ssh/id_rsa.pub "-p ${port} root@127.0.0.1"
  sleep 2
  ########## 测试 ######
  ansible all -a 'who'
  echo "输出结果绿色成功,红色失败"
  echo "失败请尝试该命令 ansible all -a 'who' "

oriental123 发表于 2018-7-29 17:27:11

111111111
页: [1]
查看完整版本: 一键安装ansible