Skip to content

Instantly share code, notes, and snippets.

@fearoffish
Created March 2, 2012 15:57
Show Gist options
  • Save fearoffish/1959301 to your computer and use it in GitHub Desktop.
Save fearoffish/1959301 to your computer and use it in GitHub Desktop.
require 'net/ssh'
class Host
def initialize(host, user, options={})
@ssh = Net::SSH.start(host, user, options)
end
def close
@ssh.close
end
def run_chef(chef_command="sudo chef-client")
@ssh.exec! chef_command
end
def installed_packages
@packages ||= @ssh.exec! 'dpkg --get-selections'
@packages.split("\n").collect {|pkg| pkg.split(" ")[0] }
end
def users
@users ||= @ssh.exec! 'cat /etc/passwd'
@users.split("\n").collect {|u| u.split(":")[0] }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment