Class: Chef::Provisioning::ConvergenceStrategy::InstallMsi
- Inherits:
-
PrecreateChefObjects
- Object
- Chef::Provisioning::ConvergenceStrategy
- PrecreateChefObjects
- Chef::Provisioning::ConvergenceStrategy::InstallMsi
- Defined in:
- lib/chef/provisioning/convergence_strategy/install_msi.rb
Instance Attribute Summary collapse
-
#chef_version ⇒ Object
readonly
Returns the value of attribute chef_version.
-
#install_msi_path ⇒ Object
readonly
Returns the value of attribute install_msi_path.
-
#install_msi_url ⇒ Object
readonly
Returns the value of attribute install_msi_url.
-
#prerelease ⇒ Object
readonly
Returns the value of attribute prerelease.
Attributes inherited from Chef::Provisioning::ConvergenceStrategy
Instance Method Summary collapse
- #converge(action_handler, machine) ⇒ Object
-
#initialize(convergence_options, config) ⇒ InstallMsi
constructor
A new instance of InstallMsi.
- #setup_convergence(action_handler, machine) ⇒ Object
Methods inherited from PrecreateChefObjects
#chef_server, #cleanup_convergence
Methods inherited from Chef::Provisioning::ConvergenceStrategy
Constructor Details
#initialize(convergence_options, config) ⇒ InstallMsi
Returns a new instance of InstallMsi.
8 9 10 11 12 13 14 15 |
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 8 def initialize(, config) super @chef_version ||= [:chef_version] @prerelease ||= [:prerelease] @install_msi_url = [:install_msi_url] || 'https://www.chef.io/chef/install.msi' @install_msi_path = [:install_msi_path] || "$env:TEMP\\#{File.basename(@install_msi_url)}" @chef_client_timeout = .has_key?(:chef_client_timeout) ? [:chef_client_timeout] : 120*60 # Default: 2 hours end |
Instance Attribute Details
#chef_version ⇒ Object (readonly)
Returns the value of attribute chef_version.
17 18 19 |
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 17 def chef_version @chef_version end |
#install_msi_path ⇒ Object (readonly)
Returns the value of attribute install_msi_path.
20 21 22 |
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 20 def install_msi_path @install_msi_path end |
#install_msi_url ⇒ Object (readonly)
Returns the value of attribute install_msi_url.
19 20 21 |
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 19 def install_msi_url @install_msi_url end |
#prerelease ⇒ Object (readonly)
Returns the value of attribute prerelease.
18 19 20 |
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 18 def prerelease @prerelease end |
Instance Method Details
#converge(action_handler, machine) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 62 def converge(action_handler, machine) super action_handler.open_stream(machine.node['name']) do |stdout| action_handler.open_stream(machine.node['name']) do |stderr| 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
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 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chef/provisioning/convergence_strategy/install_msi.rb', line 22 def setup_convergence(action_handler, machine) if !.has_key?(:client_rb_path) || !.has_key?(:client_pem_path) system_drive = machine.execute_always('$env:SystemDrive').stdout.strip @convergence_options = Cheffish::MergedConfig.new(, { :client_rb_path => "#{system_drive}\\chef\\client.rb", :client_pem_path => "#{system_drive}\\chef\\client.pem" }) end super # Check for existing chef client. version = machine.execute_always('chef-client -v') # Don't do install/upgrade if a chef client exists and # no chef version is defined by user configs or # the chef client's version already matches user config if version.exitstatus == 0 version = version.stdout.strip if !chef_version return elsif version =~ /Chef: #{chef_version}$/ Chef::Log.debug "Already installed chef version #{version}" return elsif version.include?(chef_version) Chef::Log.warn "Installed chef version #{version} contains desired version #{chef_version}. " + "If you see this message on consecutive chef runs tighten your desired version constraint to prevent " + "multiple convergence." end end # Install chef client # TODO ssh verification of install.msi before running arbtrary code would be nice? # TODO find a way to cache this on the host like with the Unix stuff. # Limiter is we don't know how to efficiently upload large files to # the remote machine with WMI. machine.execute(action_handler, "(New-Object System.Net.WebClient).DownloadFile(#{machine.escape(install_msi_url)}, #{machine.escape(install_msi_path)})") machine.execute(action_handler, "msiexec /qn /i #{machine.escape(install_msi_path)}") end |