Class: ChefApply::Action::InstallChef
  
  
  
  
  
    - Inherits:
- 
      Base
      
        
          - Object
- Base
- ChefApply::Action::InstallChef
 show all
    - Defined in:
- lib/chef_apply/action/install_chef.rb,
 lib/chef_apply/action/install_chef/minimum_chef_version.rb
 
Defined Under Namespace
  
    
  
    
      Classes: MinimumChefVersion
    
  
  Instance Attribute Summary
  
  Attributes inherited from Base
  #config, #target_host
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods inherited from Base
  #name, #notify, #run
  Constructor Details
  
    
  
  
    #initialize(opts = { check_only: false })  ⇒ InstallChef 
  
  
  
  
    
Returns a new instance of InstallChef.
   
 
  
  
    | 
24
25
26 | # File 'lib/chef_apply/action/install_chef.rb', line 24
def initialize(opts = { check_only: false })
  super
end | 
 
  
 
  
    Instance Method Details
    
      
  
  
    #download_to_workstation(url_path)  ⇒ Object 
  
  
  
  
    | 
115
116
117
118 | # File 'lib/chef_apply/action/install_chef.rb', line 115
def download_to_workstation(url_path)
  require_relative "../file_fetcher"
  ChefApply::FileFetcher.fetch(url_path)
end | 
 
    
      
  
  
    #lookup_artifact  ⇒ Object 
  
  
  
  
    | 
65
66
67
68
69
70
71 | # File 'lib/chef_apply/action/install_chef.rb', line 65
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 | 
 
    
      
  
  
    | 
28
29
30
31
32
33
34 | # File 'lib/chef_apply/action/install_chef.rb', line 28
def perform_action
  if InstallChef::MinimumChefVersion.check!(target_host, config[:check_only]) == :minimum_version_met
    notify(:already_installed)
  else
    perform_local_install
  end
end | 
 
    
      
  
  
    | 
40
41
42
43
44
45
46
47
48
49 | # File 'lib/chef_apply/action/install_chef.rb', line 40
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)
  target_host.install_package(remote_path)
  notify(:install_complete)
end | 
 
    
      
  
  
    | 
51
52
53
54
55
56
57
58
59
60
61
62
63 | # File 'lib/chef_apply/action/install_chef.rb', line 51
def perform_remote_install
                      raise NotImplementedError
end | 
 
    
      
  
  
    #train_to_mixlib(platform)  ⇒ Object 
  
  
  
  
    | 
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 | # File 'lib/chef_apply/action/install_chef.rb', line 77
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 /mac_os_x/
    if platform.release.to_i >= 17
      opts[:platform_version] = "10.13"
    else
      raise NotImplementedError
    end
  when /windows/
    opts[:platform] = "windows"
  when "redhat", "centos"
    opts[:platform] = "el"
  when "suse"
    opts[:platform] = "sles"
  when "solaris"
    opts[:platform] = "solaris2"
  when "aix"
    opts[:platform] = "aix"
  when "amazon"
    opts[:platform] = "el"
    if platform.release.to_i > 2010       opts[:platform_version] = "6"
    else
      opts[:platform_version] = "7"
    end
  end
  opts
end | 
 
    
      
  
  
    #upgrading?  ⇒ Boolean 
  
  
  
  
    | 
36
37
38 | # File 'lib/chef_apply/action/install_chef.rb', line 36
def upgrading?
  @upgrading
end | 
 
    
      
  
  
    #upload_to_target(local_path)  ⇒ Object 
  
  
  
  
    | 
120
121
122
123
124
125 | # File 'lib/chef_apply/action/install_chef.rb', line 120
def upload_to_target(local_path)
  installer_dir = target_host.temp_dir
  remote_path = File.join(installer_dir, File.basename(local_path))
  target_host.upload_file(local_path, remote_path)
  remote_path
end | 
 
    
      
  
  
    #version_to_install  ⇒ Object 
  
  
  
  
    | 
73
74
75 | # File 'lib/chef_apply/action/install_chef.rb', line 73
def version_to_install
  lookup_artifact.version
end |