一键安装ansible

#!/bin/bashweb

#Auther: xuebinbash

#Description: 此脚本用来安装ansiblessh


set -uide


####### 安装软件 ################测试


rpm -ivh  https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpmserver


if [[ $? -eq 0 ]];thenip

    echo "rpm ok"it

elseio

    echo "rpm on"class

    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 "[webservers]" >> /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 "[dbservers]" >> /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' "

相关文章
相关标签/搜索