Class: Chef::Provisioning::ConvergenceStrategy::InstallCached
- Inherits:
-
PrecreateChefObjects
- Object
- Chef::Provisioning::ConvergenceStrategy
- PrecreateChefObjects
- Chef::Provisioning::ConvergenceStrategy::InstallCached
- Defined in:
- lib/chef/provisioning/convergence_strategy/install_cached.rb
Instance Attribute Summary collapse
-
#chef_version ⇒ Object
readonly
Returns the value of attribute chef_version.
-
#client_pem_path ⇒ Object
readonly
Returns the value of attribute client_pem_path.
-
#client_rb_path ⇒ Object
readonly
Returns the value of attribute client_rb_path.
-
#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) ⇒ InstallCached
constructor
convergence_options is a hash of setup convergence_options, including: - :chef_server - :allow_overwrite_keys - :source_key, :source_key_path, :source_key_pass_phrase - :private_key_options - :ohai_hints - :public_key_path, :public_key_format - :admin, :validator - :chef_client_timeout - :client_rb_path, :client_pem_path - :chef_version, :prerelease, :package_cache_path.
- #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) ⇒ InstallCached
convergence_options is a hash of setup convergence_options, including:
-
:chef_server
-
:allow_overwrite_keys
-
:source_key, :source_key_path, :source_key_pass_phrase
-
:private_key_options
-
:ohai_hints
-
:public_key_path, :public_key_format
-
:admin, :validator
-
:chef_client_timeout
-
:client_rb_path, :client_pem_path
-
:chef_version, :prerelease, :package_cache_path
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 23 def initialize(, config) = Cheffish::MergedConfig.new(, { :client_rb_path => '/etc/chef/client.rb', :client_pem_path => '/etc/chef/client.pem' }) super(, config) @chef_version ||= [:chef_version] @prerelease ||= [:prerelease] @package_cache_path ||= [:package_cache_path] || "#{ENV['HOME']}/.chef/package_cache" @package_cache = {} @tmp_dir = '/tmp' @chef_client_timeout = .has_key?(:chef_client_timeout) ? [:chef_client_timeout] : 120*60 # Default: 2 hours FileUtils.mkdir_p(@package_cache_path) @package_cache_lock = Mutex.new end |
Instance Attribute Details
#chef_version ⇒ Object (readonly)
Returns the value of attribute chef_version.
41 42 43 |
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 41 def chef_version @chef_version end |
#client_pem_path ⇒ Object (readonly)
Returns the value of attribute client_pem_path.
40 41 42 |
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 40 def client_pem_path @client_pem_path end |
#client_rb_path ⇒ Object (readonly)
Returns the value of attribute client_rb_path.
39 40 41 |
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 39 def client_rb_path @client_rb_path end |
#prerelease ⇒ Object (readonly)
Returns the value of attribute prerelease.
42 43 44 |
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 42 def prerelease @prerelease end |
Instance Method Details
#converge(action_handler, machine) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 75 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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/chef/provisioning/convergence_strategy/install_cached.rb', line 44 def setup_convergence(action_handler, machine) 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 platform, platform_version, machine_architecture = machine.detect_os(action_handler) package_file = download_package_for_platform(action_handler, machine, platform, platform_version, machine_architecture) remote_package_file = "#{@tmp_dir}/#{File.basename(package_file)}" machine.upload_file(action_handler, package_file, remote_package_file) install_package(action_handler, machine, remote_package_file) end |