Created
February 7, 2014 18:10
-
-
Save azet/8868376 to your computer and use it in GitHub Desktop.
expect(1) script to force puppet on EL6 hosts in a subnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect -f | |
# | |
# force puppet on previously unmanaged centos 6 hosts | |
# | |
# author: Aaron <azet@azet.org> Zauner @ 7.2.2014 | |
# depends: expect | |
# license: MIT | |
# | |
set timeout 60 | |
set network "10.60.40" | |
set password "changeme" | |
# return return value of a spawned process | |
proc return_val {id} { | |
set waitval [wait -i $id] | |
set exval [lindex $waitval 3] | |
return $exval | |
} | |
# main loop | |
for {set i 20} {$i < 254} {incr i} { | |
set ip "$network.$i" | |
puts " >> trying $ip." | |
# check if host is pingable i.e. online | |
spawn timeout 2 ping -c 2 $ip | |
if {[return_val $spawn_id] != 0} { | |
continue | |
} | |
# try to connect via SSH | |
spawn ssh $ip -lroot -o ConnectTimeout=5 | |
# ssh authentication procedure | |
expect { | |
"yes/no" { | |
send "yes\r" | |
} | |
"?assword: " { send "$password\r" } | |
"*Connection" { continue } | |
"?ffending" { continue } | |
} | |
expect { | |
"*# " { | |
send "rpm -ivh https://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-7.noarch.rpm\r" | |
expect "*# " | |
send "yum install puppet -y ; chkconfig puppet on ; service puppet start\r" | |
} | |
"?assword: " { continue } | |
"*Connection" { continue } | |
} | |
expect "*# " | |
send "exit\r" | |
expect eof | |
puts " >> done with $ip." | |
} | |
exit 0 | |
#EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment