Class: Ridley::Bootstrapper

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Logging
Defined in:
lib/ridley/bootstrapper.rb,
lib/ridley/bootstrapper/context.rb

Overview

Author:

Defined Under Namespace

Classes: Context

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

logger, #logger, set_logger

Constructor Details

#initialize(hosts, options = {}) ⇒ Bootstrapper

Returns a new instance of Bootstrapper.

Parameters:

  • hosts (Array<#to_s>)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :ssh (Hash)
    • :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

  • :winrm (Hash)
    • :user (String) a user that will login to each node and perform the bootstrap command on (required)

    • :password (String) the password for the user that will perform the bootstrap

    • :port (Fixnum) the winrm port to connect on the node the bootstrap will be performed on (5985)

  • :validator_client (String)
  • :validator_path (String)

    filepath to the validator used to bootstrap the node (required)

  • :bootstrap_proxy (String) — default: nil

    URL to a proxy server to bootstrap through

  • :encrypted_data_bag_secret (String)

    your organizations encrypted data bag secret

  • :hints (Hash) — default: Hash.new

    a hash of Ohai hints to place on the bootstrapped node

  • :attributes (Hash) — default: Hash.new

    a hash of attributes to use in the first Chef run

  • :run_list (Array) — default: Array.new

    an initial run list to bootstrap with

  • :chef_version (String) — default: nil

    version of Chef to install on the node

  • :environment (String) — default: '_default'

    environment to join the node to

  • :sudo (Boolean) — default: true

    bootstrap with sudo (default: true)

  • :template (String)

    bootstrap template to use



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ridley/bootstrapper.rb', line 47

def initialize(hosts, options = {})
  @hosts         = Array(hosts).flatten.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]
end

Instance Attribute Details

#hostsArray<String> (readonly)

Returns:

  • (Array<String>)


11
12
13
# File 'lib/ridley/bootstrapper.rb', line 11

def hosts
  @hosts
end

#optionsHash (readonly)

Returns:

  • (Hash)


14
15
16
# File 'lib/ridley/bootstrapper.rb', line 14

def options
  @options
end

Instance Method Details

#contextsArray<Bootstrapper::Context>

Returns:

Raises:



62
63
64
# File 'lib/ridley/bootstrapper.rb', line 62

def contexts
  @contexts ||= @hosts.collect { |host| Context.create(host, options) }
end

#runHostConnector::ResponseSet

Returns:

Raises:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ridley/bootstrapper.rb', line 69

def run
  workers = Array.new
  futures = contexts.collect do |context|
    log.info { "Running bootstrap command on #{context.host}" }

    workers << worker = context.host_connector::Worker.new(context.host, self.options.freeze)

    worker.future.run(context.template_binding.boot_command)
  end

  HostConnector::ResponseSet.new.tap do |response_set|
    futures.each do |future|
      status, response = future.value
      response_set.add_response(response)
    end
  end
ensure
  workers.map(&:terminate)
end