Class: Shiplane::ChefHost
- Inherits:
-
Host
- Object
- Host
- Shiplane::ChefHost
- Includes:
- Airbrussh::Colors
- Defined in:
- lib/capistrano/chef_host.rb
Constant Summary collapse
- REMOTE_CHEF_FOLDER_PATH =
File.join("/var","chef")
- LOCAL_CHEF_FOLDER_PATH =
File.("../../../lib/chef", __FILE__)
- COOKBOOKS_FILE_NAME =
"cookbooks.tar.gz"- LOCAL_COOKBOOKS_FILE_PATH =
File.("../../../#{COOKBOOKS_FILE_NAME}", __FILE__)
- REMOTE_COOKBOOKS_FILE_PATH =
File.join(REMOTE_CHEF_FOLDER_PATH, COOKBOOKS_FILE_NAME)
- CHEF_PACKAGE_NAME =
config.fetch("bootstrap", {}).fetch("chef-bootstrapper", {}).fetch("package_name")
- CHEF_PACKAGE_DOWNLOAD_URL =
config.fetch("bootstrap", {}).fetch("chef-bootstrapper", {}).fetch("package_url")
- APT_PACKAGES =
%w(build-essential wget)
Instance Method Summary collapse
Instance Method Details
#configure ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# 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? (SSHKit::Logger::ERROR, "#{errors.keys.size} Errors encountered:") errors.each do |h, trace| SSHKit::Logger::INFO, "~" * 80 SSHKit::Logger::INFO, green("Server: #{h}") trace.each do |line| SSHKit::Logger::INFO, line end SSHKit::Logger::INFO, "~" * 80 end end end end |
#install ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# 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 |