Module: KnifeSolo::Bootstraps::InstallCommands

Included in:
Base
Defined in:
lib/knife-solo/bootstraps.rb

Overview

Delegates

Instance Method Summary collapse

Instance Method Details

#bootstrap!Object



49
50
51
52
53
# File 'lib/knife-solo/bootstraps.rb', line 49

def bootstrap!
  run_pre_bootstrap_checks
  send("#{distro[:type]}_install")
  install_ohai_hints
end

#distroObject



55
56
57
# File 'lib/knife-solo/bootstraps.rb', line 55

def distro
  raise "implement distro detection for #{self.class.name}"
end

#gem_installObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/knife-solo/bootstraps.rb', line 95

def gem_install
  ui.msg "Installing rubygems from source..."
  release = "rubygems-1.8.10"
  file = "#{release}.tgz"
  url = "http://production.cf.rubygems.org/rubygems/#{file}"
  http_client_get_url(url, file)
  run_command("tar zxf #{file}")
  run_command("cd #{release} && sudo ruby setup.rb --no-format-executable")
  run_command("sudo rm -rf #{release} #{file}")
  run_command("sudo gem install --no-rdoc --no-ri #{gem_packages.join(' ')}") unless gem_packages.empty?
  run_command("sudo gem install --no-rdoc --no-ri chef #{gem_options}")
end

#gem_optionsObject



108
109
110
111
112
113
114
# File 'lib/knife-solo/bootstraps.rb', line 108

def gem_options
  if prepare.config[:prerelease]
    "--prerelease"
  elsif chef_version
    "--version #{chef_version}"
  end
end

#gem_packagesObject

gems to install before chef



60
61
62
# File 'lib/knife-solo/bootstraps.rb', line 60

def gem_packages
  []
end

#http_client_get_url(url, file) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/knife-solo/bootstraps.rb', line 64

def http_client_get_url(url, file)
  stream_command <<-BASH
    /bin/sh -c " \
      if command -v curl >/dev/null 2>&1; then \
        curl -L -o '#{file}' '#{url}'; \
      else \
        wget -O '#{file}' '#{url}'; \
      fi; \
    "
  BASH
end

#install_ohai_hintsObject



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/knife-solo/bootstraps.rb', line 116

def install_ohai_hints
  hints = Chef::Config[:knife][:hints]
  unless hints.nil? || hints.empty?
    ui.msg "Setting Ohai hints..."
    run_command("sudo mkdir -p /etc/chef/ohai/hints")
    run_command("sudo rm -f /etc/chef/ohai/hints/*")
    hints.each do |name, hash|
      run_command("sudo tee -a /etc/chef/ohai/hints/#{name}.json > /dev/null <<EOF\n#{hash.to_json}\nEOF\n")
    end
  end
end

#omnibus_installObject



76
77
78
79
80
81
82
83
# File 'lib/knife-solo/bootstraps.rb', line 76

def omnibus_install
  url = prepare.config[:omnibus_url] || "https://www.opscode.com/chef/install.sh"
  file = File.basename(url)
  http_client_get_url(url, file)

  install_command = "sudo bash #{file} #{omnibus_options}"
  stream_command(install_command)
end

#omnibus_optionsObject



85
86
87
88
89
90
91
92
93
# File 'lib/knife-solo/bootstraps.rb', line 85

def omnibus_options
  options = prepare.config[:omnibus_options] || ""
  if prepare.config[:prerelease]
    options << " -p"
  elsif chef_version
    options << " -v #{chef_version}"
  end
  options
end