首页 > 代码库 > 自动化安装ansible脚本

自动化安装ansible脚本

#!/bin/bash

#just prevent you have ssh key

rm -rf /root/.ssh/id_dsa*

ssh-keygen -t dsa -f /root/.ssh/id_dsa -P "" >> /dev/null 2>&1

#all can ssh each other

for ip in $*

do

sshpass -p123456 ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no root@$ip" >> /dev/null 2>&1

#just for you Determine whether distribution of success of ssh

a=$(ssh $ip hostname -I|awk ‘{print $1"|"$2}‘)

if [[ "$ip" =~ $a ]]

then

#install ansible

yum install ansible -y >> /dev/null 2>&1 && \

#judge you ansible install

if [ "`rpm -qa | grep -o ansible`" == "ansible" ]

then

#insert you group of ansible

read -p "pleace insert you ansible group name: " grop

read -p "pleace insert The name of the group members just like one two ...: " arg

cat << EOF >> /etc/ansible/hosts

[$grop]

`echo $arg | tr " " "\n"`

EOF

#judge you can use ansible

ansible $grop -m command -a "hostname" 2>> /var/log/ansible.log

if [ $? -ne 0 ]

then

echo "ERROR:you can not use ansible,pleace see /var/log/ansible.log"

else

echo "congratulations!!you ansible successful! and now you can do you want"

fi

else

echo "you can ssh each other but you can not install ansible plase Check the network"

fi

else

echo "you fenfa falit"

fi

done


本文出自 “我的学习” 博客,请务必保留此出处http://shuai12138.blog.51cto.com/10118203/1907738

自动化安装ansible脚本