Class: ChefApply::Action::InstallChef::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/chef_apply/action/install_chef/base.rb

Direct Known Subclasses

Linux, Windows

Constant Summary collapse

MIN_14_VERSION =
Gem::Version.new("14.1.1")
MIN_13_VERSION =
Gem::Version.new("13.10.0")

Constants inherited from Base

Base::PATH_MAPPING

Instance Attribute Summary

Attributes inherited from Base

#config, #target_host

Instance Method Summary collapse

Methods inherited from Base

#escape_windows_path, #initialize, #notify, #run, #run_chef

Constructor Details

This class inherits a constructor from ChefApply::Action::Base

Instance Method Details

#check_minimum_chef_version!(target) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/chef_apply/action/install_chef/base.rb', line 110

def check_minimum_chef_version!(target)
  begin
    installed_version = target.installed_chef_version
  rescue ChefApply::TargetHost::ChefNotInstalled
    if config[:check_only]
      raise ClientNotInstalled.new()
    end
    return :client_not_installed
  end

  case
    when installed_version >= Gem::Version.new("14.0.0") && installed_version < MIN_14_VERSION
      raise Client14Outdated.new(installed_version, MIN_14_VERSION)
    when installed_version >= Gem::Version.new("13.0.0") && installed_version < MIN_13_VERSION
      raise Client13Outdated.new(installed_version, MIN_13_VERSION, MIN_14_VERSION)
    when installed_version < Gem::Version.new("13.0.0")
      # If they have Chef < 13.0.0 installed we want to show them the easiest upgrade path -
      # Chef 13 first and then Chef 14 since most customers cannot make the leap directly
      # to 14.
      raise Client13Outdated.new(installed_version, MIN_13_VERSION, MIN_14_VERSION)
  end

  :minimum_version_met
end

#download_to_workstation(url_path) ⇒ Object



98
99
100
101
# File 'lib/chef_apply/action/install_chef/base.rb', line 98

def download_to_workstation(url_path)
  require "chef_apply/file_fetcher"
  ChefApply::FileFetcher.fetch(url_path)
end

#install_chef_to_target(remote_path) ⇒ Object

Raises:

  • (NotImplementedError)


139
140
141
# File 'lib/chef_apply/action/install_chef/base.rb', line 139

def install_chef_to_target(remote_path)
  raise NotImplementedError
end

#lookup_artifactObject



59
60
61
62
63
64
# File 'lib/chef_apply/action/install_chef/base.rb', line 59

def lookup_artifact
  return @artifact_info if @artifact_info
  require "mixlib/install"
  c = train_to_mixlib(target_host.platform)
  Mixlib::Install.new(c).artifact_info
end

#nameObject



34
35
36
37
38
# File 'lib/chef_apply/action/install_chef/base.rb', line 34

def name
  # We have subclasses - so this'll take the qualified name
  # eg InstallChef::Windows, etc
  self.class.name.split("::")[-2..-1].join("::")
end

#perform_actionObject



26
27
28
29
30
31
32
# File 'lib/chef_apply/action/install_chef/base.rb', line 26

def perform_action
  if check_minimum_chef_version!(target_host) == :minimum_version_met
    notify(:already_installed)
  else
    perform_local_install
  end
end

#perform_local_installObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/chef_apply/action/install_chef/base.rb', line 44

def perform_local_install
  package = lookup_artifact()
  notify(:downloading)
  local_path = download_to_workstation(package.url)
  notify(:uploading)
  remote_path = upload_to_target(local_path)
  notify(:installing)
  install_chef_to_target(remote_path)
  notify(:install_complete)
end

#perform_remote_installObject

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/chef_apply/action/install_chef/base.rb', line 55

def perform_remote_install
  raise NotImplementedError
end

#setup_remote_temp_pathObject

Raises:

  • (NotImplementedError)


135
136
137
# File 'lib/chef_apply/action/install_chef/base.rb', line 135

def setup_remote_temp_path
  raise NotImplementedError
end

#train_to_mixlib(platform) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/chef_apply/action/install_chef/base.rb', line 70

def train_to_mixlib(platform)
  opts = {
    platform_version: platform.release,
    platform: platform.name,
    architecture: platform.arch,
    product_name: "chef",
    product_version: :latest,
    channel: :stable,
    platform_version_compatibility_mode: true
  }
  case platform.name
  when /windows/
    opts[:platform] = "windows"
  when "redhat", "centos"
    opts[:platform] = "el"
  when "suse"
    opts[:platform] = "sles"
  when "amazon"
    opts[:platform] = "el"
    if platform.release.to_i > 2010 # legacy Amazon version 1
      opts[:platform_version] = "6"
    else
      opts[:platform_version] = "7"
    end
  end
  opts
end

#upgrading?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/chef_apply/action/install_chef/base.rb', line 40

def upgrading?
  @upgrading
end

#upload_to_target(local_path) ⇒ Object



103
104
105
106
107
108
# File 'lib/chef_apply/action/install_chef/base.rb', line 103

def upload_to_target(local_path)
  installer_dir = setup_remote_temp_path()
  remote_path = File.join(installer_dir, File.basename(local_path))
  target_host.upload_file(local_path, remote_path)
  remote_path
end

#version_to_installObject



66
67
68
# File 'lib/chef_apply/action/install_chef/base.rb', line 66

def version_to_install
  lookup_artifact.version
end