码迷,mamicode.com
首页 > 其他好文 > 详细

自动化安装ansible脚本

时间:2017-03-17 21:12:32      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:shell 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脚本

标签:shell ansible

原文地址:http://shuai12138.blog.51cto.com/10118203/1907738

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!