lib/ridley/bootstrapper.rb in ridley-0.5.2 vs lib/ridley/bootstrapper.rb in ridley-0.6.0
- old
+ new
@@ -23,77 +23,71 @@
# @return [Array<Bootstrapper::Context>]
attr_reader :contexts
# @return [Hash]
- attr_reader :ssh_config
+ attr_reader :options
# @param [Array<#to_s>] hosts
- # @option options [String] :ssh_user
- # @option options [String] :ssh_password
- # @option options [Array<String>, String] :ssh_keys
- # @option options [Float] :ssh_timeout
- # timeout value for SSH bootstrap (default: 1.5)
+ # @option options [Hash] :ssh
+ # * :user (String) a shell user that will login to each node and perform the bootstrap command on (required)
+ # * :password (String) the password for the shell user that will perform the bootstrap
+ # * :keys (Array, String) an array of keys (or a single key) to authenticate the ssh user with instead of a password
+ # * :timeout (Float) [5.0] timeout value for SSH bootstrap
# @option options [String] :validator_client
# @option options [String] :validator_path
# filepath to the validator used to bootstrap the node (required)
- # @option options [String] :bootstrap_proxy
- # URL to a proxy server to bootstrap through (default: nil)
- # @option options [String] :encrypted_data_bag_secret_path
- # filepath on your host machine to your organizations encrypted data bag secret (default: nil)
- # @option options [Hash] :hints
- # a hash of Ohai hints to place on the bootstrapped node (default: Hash.new)
- # @option options [Hash] :attributes
- # a hash of attributes to use in the first Chef run (default: Hash.new)
- # @option options [Array] :run_list
- # an initial run list to bootstrap with (default: Array.new)
- # @option options [String] :chef_version
- # version of Chef to install on the node (default: {Ridley::CHEF_VERSION})
- # @option options [String] :environment
- # environment to join the node to (default: '_default')
- # @option options [Boolean] :sudo
+ # @option options [String] :bootstrap_proxy (nil)
+ # URL to a proxy server to bootstrap through
+ # @option options [String] :encrypted_data_bag_secret_path (nil)
+ # filepath on your host machine to your organizations encrypted data bag secret
+ # @option options [Hash] :hints (Hash.new)
+ # a hash of Ohai hints to place on the bootstrapped node
+ # @option options [Hash] :attributes (Hash.new)
+ # a hash of attributes to use in the first Chef run
+ # @option options [Array] :run_list (Array.new)
+ # an initial run list to bootstrap with
+ # @option options [String] :chef_version (Ridley::CHEF_VERSION)
+ # version of Chef to install on the node
+ # @option options [String] :environment ('_default')
+ # environment to join the node to
+ # @option options [Boolean] :sudo (true)
# bootstrap with sudo (default: true)
- # @option options [String] :template
- # bootstrap template to use (default: omnibus)
+ # @option options [String] :template ('omnibus')
+ # bootstrap template to use
def initialize(hosts, options = {})
- @hosts = Array(hosts).collect(&:to_s).uniq
- @ssh_config = {
- user: options.fetch(:ssh_user),
- password: options[:ssh_password],
- keys: options[:ssh_keys],
- timeout: (options[:ssh_timeout] || 1.5)
- }
+ @hosts = Array(hosts).collect(&:to_s).uniq
+ @options = options.dup
+ @options[:ssh] ||= Hash.new
+ @options[:ssh] = {
+ timeout: 5.0,
+ sudo: true
+ }.merge(@options[:ssh])
+ @options[:sudo] = @options[:ssh][:sudo]
+
@contexts = @hosts.collect do |host|
Context.new(host, options)
end
end
# @return [SSH::ResponseSet]
def run
- if contexts.length >= 2
- pool = SSH::Worker.pool(size: contexts.length, args: [self.ssh_config])
- else
- pool = SSH::Worker.new(self.ssh_config)
+ workers = Array.new
+ futures = contexts.collect do |context|
+ info "Running bootstrap command on #{context.host}"
+
+ workers << worker = SSH::Worker.new_link(self.options[:ssh].freeze)
+ worker.future.run(context.host, context.boot_command)
end
- responses = contexts.collect do |context|
- pool.future.run(context.host, context.boot_command)
- end.collect(&:value)
-
SSH::ResponseSet.new.tap do |response_set|
- responses.each do |message|
- status, response = message
-
- case status
- when :ok
- response_set.add_ok(response)
- when :error
- response_set.add_error(response)
- end
+ futures.each do |future|
+ status, response = future.value
+ response_set.add_response(response)
end
end
ensure
- pool.terminate if pool
+ workers.map(&:terminate)
end
end
end