Last active
November 16, 2018 21:43
-
-
Save jjam3774/6148710 to your computer and use it in GitHub Desktop.
A script that will deploy changes to multiple servers. This is just a brief example of what can be done if you need to make quick changes on multiple servers when time is hitting close to the deadline.
This file contains hidden or 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/ruby | |
require 'rubygems' | |
require 'net/ssh' | |
class Remote | |
attr_accessor :hostfile, :user, :pass, :commands | |
def initialize(hostfile,user, pass, commands) | |
@hostfile = hostfile | |
@user = user | |
@pass = pass | |
@commands = commands | |
end | |
######################## | |
# Main part of script | |
######################## | |
def execute | |
File.open(@hostfile).each { | |
|i| | |
puts("*"*20) | |
puts("Logging on to #{i}") | |
puts("*"*20) | |
Net::SSH.start( i.chomp, @user, :password => @pass ) do|ssh| | |
result = ssh.exec!(@commands) | |
puts result | |
end | |
puts ("-"*20) | |
} | |
end | |
end | |
hostfile = open('hosts') | |
user = 'root' | |
pass = 'password' | |
commands = <<-eos | |
echo "##############################" | |
echo "HOSTNAME" | |
echo "##############################" | |
hostname | |
[ $? == "0" ] && echo "Status Okay" || echo "Command did not execute.." | |
echo "##############################" | |
echo "UPTIME" | |
[ $? == "0" ] && echo "Status Okay" || echo "Command did not execute.." | |
echo "##############################" | |
echo 'BIOS' | |
echo "##############################" | |
dmidecode -t bios | |
[ $? == "0" ] && echo "Status Okay" || echo "Command did not execute.." | |
set apple fruit steak | |
echo $1 $2 $3 | |
[ "${1}" == "apple" ] && { | |
echo "#############################" | |
echo "Mounted File Systems" | |
echo "#############################" | |
} | |
eos | |
change = Remote.new(hostfile,user, pass, commands) | |
change.execute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment