一鍵安裝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' "

相關文章
相關標籤/搜索