Class: Solid::Chef
- Inherits:
-
Object
- Object
- Solid::Chef
- Defined in:
- lib/solid/chef.rb
Instance Method Summary collapse
-
#initialize(server, user, options = {}) ⇒ Chef
constructor
A new instance of Chef.
- #install ⇒ Object
- #installed? ⇒ Boolean
- #solo(dna, cookbooks) ⇒ Object
Constructor Details
#initialize(server, user, options = {}) ⇒ Chef
Returns a new instance of Chef.
5 6 7 8 9 |
# File 'lib/solid/chef.rb', line 5 def initialize(server, user, = {}) @server = server @user = user @options = .merge(:port => 2222) end |
Instance Method Details
#install ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/solid/chef.rb', line 11 def install unless installed? Net::SSH.start(@server, @user, @options) do |ssh| puts "installing..." puts ssh.exec! sudo_cmd + "apt-get update -y" ssh.exec! "sudo apt-get install ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential git-core xfsprogs -y" ssh.exec! "wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz && tar zxf rubygems-1.3.7.tgz && cd rubygems-1.3.7 && sudo ruby setup.rb && sudo ln -sfv /usr/bin/gem1.8 /usr/bin/gem" ssh.exec! "sudo gem update --system" puts ssh.exec! "sudo gem install chef --no-ri --no-rdoc" end end end |
#installed? ⇒ Boolean
24 25 26 27 28 29 30 31 |
# File 'lib/solid/chef.rb', line 24 def installed? result = false Net::SSH.start(@server, @user, @options) do |ssh| puts "checking if installed" result = ssh.exec!("which chef-solo") end result =~ /chef-solo/ end |
#solo(dna, cookbooks) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/solid/chef.rb', line 33 def solo(dna, cookbooks) puts @options.inspect Net::SSH.start(@server, @user, @options) do |ssh| puts "deploying..." ssh.exec!("echo \"#{dna.to_json.gsub('"','\"')}\" > dna.json") puts ssh.exec!(sudo_cmd + " chef-solo -l debug -j dna.json -r #{cookbooks}") end end |