Class: Chef::Provisioning::ConvergenceStrategy::InstallMsi

Inherits:
PrecreateChefObjects show all
Defined in:
lib/chef/provisioning/convergence_strategy/install_msi.rb

Instance Attribute Summary collapse

Attributes inherited from Chef::Provisioning::ConvergenceStrategy

#config, #convergence_options

Instance Method Summary collapse

Methods inherited from PrecreateChefObjects

#chef_server, #cleanup_convergence

Methods inherited from Chef::Provisioning::ConvergenceStrategy

#cleanup_convergence

Constructor Details

#initialize(convergence_options, config) ⇒ InstallMsi

Returns a new instance of InstallMsi.


9
10
11
12
13
14
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 9

def initialize(convergence_options, config)
  super
  @chef_version ||= convergence_options[:chef_version]
  @prerelease ||= convergence_options[:prerelease]
  @chef_client_timeout = convergence_options.has_key?(:chef_client_timeout) ? convergence_options[:chef_client_timeout] : 120*60 # Default: 2 hours
end

Instance Attribute Details

#chef_versionObject (readonly)

Returns the value of attribute chef_version


16
17
18
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 16

def chef_version
  @chef_version
end

#install_msi_pathObject (readonly)

Returns the value of attribute install_msi_path


19
20
21
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 19

def install_msi_path
  @install_msi_path
end

#install_msi_urlObject (readonly)

Returns the value of attribute install_msi_url


18
19
20
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 18

def install_msi_url
  @install_msi_url
end

#prereleaseObject (readonly)

Returns the value of attribute prerelease


17
18
19
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 17

def prerelease
  @prerelease
end

Instance Method Details

#converge(action_handler, machine) ⇒ Object


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 51

def converge(action_handler, machine)
  super

  action_handler.open_stream(machine.node['name']) do |stdout|
    action_handler.open_stream(machine.node['name']) do |stderr|
      # We just installed chef in this shell so refresh PATH from System.Environment
      command_line = "$env:path = [System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE');"
      command_line << "chef-client"
      command_line << " -l #{config[:log_level].to_s}" if config[:log_level]
      machine.execute(action_handler, command_line,
        :stream_stdout => stdout,
        :stream_stderr => stderr,
        :timeout => @chef_client_timeout)
    end
  end
end

#setup_convergence(action_handler, machine) ⇒ Object


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
47
48
49
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 21

def setup_convergence(action_handler, machine)
  if !convergence_options.has_key?(:client_rb_path) || !convergence_options.has_key?(:client_pem_path)
    system_drive = machine.system_drive
    @convergence_options = Cheffish::MergedConfig.new(convergence_options.to_hash, {
      :client_rb_path => "#{system_drive}\\chef\\client.rb",
      :client_pem_path => "#{system_drive}\\chef\\client.pem",
      :install_script_path => "#{system_drive}\\chef\\\install.ps1"
    })
  end

  opts = {"prerelease" => prerelease}
  if convergence_options[:bootstrap_proxy]
    opts["http_proxy"] = convergence_options[:bootstrap_proxy]
    opts["https_proxy"] = convergence_options[:bootstrap_proxy]
  end
  opts["install_msi_url"] = convergence_options[:install_msi_url] if convergence_options[:install_msi_url]
  super

  install_command = Mixlib::Install::ScriptGenerator.new(chef_version, true, opts).install_command
  machine.write_file(action_handler, convergence_options[:install_script_path], install_command)

  action_handler.open_stream(machine.node['name']) do |stdout|
    action_handler.open_stream(machine.node['name']) do |stderr|
      machine.execute(action_handler, "& \"#{convergence_options[:install_script_path]}\"",
        :stream_stdout => stdout,
        :stream_stderr => stderr)
    end
  end
end