class Shiplane::ChefHost

Constants

APT_PACKAGES
CHEF_PACKAGE_DOWNLOAD_URL
CHEF_PACKAGE_NAME
COOKBOOKS_FILE_NAME
LOCAL_CHEF_FOLDER_PATH
LOCAL_COOKBOOKS_FILE_PATH
REMOTE_CHEF_FOLDER_PATH
REMOTE_COOKBOOKS_FILE_PATH

Public Instance Methods

configure() click to toggle source
# File lib/capistrano/chef_host.rb, line 60
def configure
  with_context do
    errors = {}
    SSHKit.config.default_env["CHEF_LICENSE"] = "accept"
    SSHKit::Coordinator.new(host).each in: :parallel do |h|
      context_variables = fetch(:shiplane_sshkit_values)

      begin
        execute :sudo, 'chef-solo', '-c', "#{Shiplane::ChefHost::REMOTE_CHEF_FOLDER_PATH}/solo.rb", interaction_handler: context_variables[:interaction_handler]
      rescue => e
        errors["#{h}"] = Shiplane::ChefErrorParser.parse(e)
      end
    end

    unless errors.empty?
      write_message(SSHKit::Logger::ERROR, "#{errors.keys.size} Errors encountered:")
      errors.each do |h, trace|
        write_message SSHKit::Logger::INFO, "~" * 80
        write_message SSHKit::Logger::INFO, green("Server: #{h}")
        trace.each do |line|
          write_message SSHKit::Logger::INFO, line
        end
        write_message SSHKit::Logger::INFO, "~" * 80
      end
    end
  end
end
install() click to toggle source
# File lib/capistrano/chef_host.rb, line 17
def install
  with_context do
    SSHKit::Coordinator.new(host).each in: :parallel do
      context_variables = fetch(:shiplane_sshkit_values)

      install_started = test("[ -f #{File.join(Shiplane::ChefHost::REMOTE_CHEF_FOLDER_PATH, '.install-started')} ]")
      install_finished = test("[ -f #{File.join(Shiplane::ChefHost::REMOTE_CHEF_FOLDER_PATH, '.install')} ]")

      if install_started && !install_finished
        execute :sudo, :dpkg, '--configure', '-a', interaction_handler: context_variables[:interaction_handler]
        # execute :sudo, :dpkg, "--remove", "--force-remove-reinstreq", *Shiplane::ChefHost::APT_PACKAGES - %w(wget build-essential), interaction_handler: context_variables[:interaction_handler]
      end

      unless install_finished
        execute :sudo, :sysctl, "-w", "net.ipv6.conf.all.disable_ipv6=1", interaction_handler: context_variables[:interaction_handler]
        execute :sudo, :sysctl, "-w", "net.ipv6.conf.default.disable_ipv6=1", interaction_handler: context_variables[:interaction_handler]
        execute :sudo, :mkdir, '-m', '2777', '-p', Shiplane::ChefHost::REMOTE_CHEF_FOLDER_PATH, interaction_handler: context_variables[:interaction_handler]
        execute :sudo, :touch, File.join(Shiplane::ChefHost::REMOTE_CHEF_FOLDER_PATH, '.install-started'), interaction_handler: context_variables[:interaction_handler]
        execute :sudo, 'apt-get', 'update', interaction_handler: context_variables[:interaction_handler]
        execute :sudo, 'apt-get', 'install', '-y', *Shiplane::ChefHost::APT_PACKAGES, interaction_handler: context_variables[:interaction_handler]
        execute :wget, Shiplane::ChefHost::CHEF_PACKAGE_DOWNLOAD_URL
        execute :sudo, :dpkg, '-i', Shiplane::ChefHost::CHEF_PACKAGE_NAME, interaction_handler: context_variables[:interaction_handler]
        execute :sudo, :ls, '-al', Shiplane::ChefHost::REMOTE_CHEF_FOLDER_PATH, interaction_handler: context_variables[:interaction_handler]
        execute :sudo, :touch, File.join(Shiplane::ChefHost::REMOTE_CHEF_FOLDER_PATH, '.install'), interaction_handler: context_variables[:interaction_handler]
        execute :sudo, :sysctl, "-w", "net.ipv6.conf.all.disable_ipv6=0", interaction_handler: context_variables[:interaction_handler]
        execute :sudo, :sysctl, "-w", "net.ipv6.conf.default.disable_ipv6=0", interaction_handler: context_variables[:interaction_handler]
      end
    end
  end
end
reinstall() click to toggle source
# File lib/capistrano/chef_host.rb, line 48
def reinstall
  with_context do
    SSHKit::Coordinator.new(host).each in: :parallel do
      context_variables = fetch(:shiplane_sshkit_values)

      if(test("[ -f #{File.join(Shiplane::ChefHost::REMOTE_CHEF_FOLDER_PATH, '.install')} ]"))
        execute :sudo, :rm, File.join(Shiplane::ChefHost::REMOTE_CHEF_FOLDER_PATH, '.install'), interaction_handler: context_variables[:interaction_handler]
      end
    end
  end
end