关于ansbile

注:该脚本中的变量不是标准的,请注意.....

该文档中是2台机器做的实验(都是CensOS7.4.1708)

192.168.1.201

192.168.1.202

vim ~/ansible.sh 

#!/bin/bash

read -p "对端用户名(尽可能为同一个用户): " User

read -p "对端IP(多个以空格隔开): " D_IP

yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum -y install ansible python-pip expect

ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

for i in $D_IP;do

    /usr/bin/expect <<-EOF

    set timeout 10

    spawn ssh-copy-id $User@$i

    expect {

        "\(yes/no\)" { send "yes\r"; exp_continue }

        "*password:" { send "aaaaaa\r" }

        }

    expect eof

EOF

done

 

注:实验中的6个a是所有机器的root对应的密码

 

执行脚本:

sh ~/ansible.sh

 

 

测试:

 

 

 

 

 

猜你喜欢

转载自www.cnblogs.com/smlile-you-me/p/11090161.html
今日推荐