Kurobeats

ansible

Apr 16th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.76 KB | None | 0 0
  1. #!/usr/bin/expect
  2. # Just need hosts.txt and replace $password with your password of an ansible user account
  3. # Also id_rsa.pub for your private key you want to use.
  4. set timeout 3
  5. set rootdir /home/ansible
  6. set hostz [file join $rootdir hosts.txt]
  7. set fh [open $hostz r]
  8.  
  9. while {[gets $fh hosty] != -1} {
  10.     spawn scp .ssh/id_rsa.pub ansible@$hosty:
  11.     expect {
  12.     "Are you sure you want to continue connecting (yes/no)?" { send "yes\r"; exp_continue }
  13.     password:                                                {send $password\r; exp_continue}
  14.     }
  15.     spawn ssh ansible@$hosty mkdir /home/ansible/.ssh && mv id_rsa.pub .ssh/authorized_keys
  16.     expect {
  17.     password:                                                {send $password\r; exp_continue}
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment