#!/usr/bin/expect set timeout 10 set username [lindex $argv 0] set password [lindex $argv 1] set hostname [lindex $argv 2] spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $username@$hostname expect { "Are you sure you want to continue connecting (yes/no)?" { send "yes " expect "password:" send "$password " } "password:" { send "$password " } "Now try logging into the machine" { } } expect eof
user="root" passwd="xxxx" for i in `seq 34 41`; do ip="xxx.xxx.xxx.$i" /etc/ansible/inventory/copy-ssh.exp $user $passwd $ip done