Class: Ridley::Bootstrapper

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

Overview

Author:

Defined Under Namespace

Classes: Context

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

  • :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_path (String) — default: nil

    filepath on your host machine to 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: Ridley::CHEF_VERSION

    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) — default: 'omnibus'

    bootstrap template to use


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ridley/bootstrapper.rb', line 57

def initialize(hosts, options = {})
  @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

Instance Attribute Details

#contextsArray<Bootstrapper::Context> (readonly)

Returns:


25
26
27
# File 'lib/ridley/bootstrapper.rb', line 25

def contexts
  @contexts
end

#hostsArray<String> (readonly)

Returns:

  • (Array<String>)

22
23
24
# File 'lib/ridley/bootstrapper.rb', line 22

def hosts
  @hosts
end

#optionsHash (readonly)

Returns:

  • (Hash)

28
29
30
# File 'lib/ridley/bootstrapper.rb', line 28

def options
  @options
end

Class Method Details

.default_templateString

Returns:

  • (String)

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

def default_template
  templates_path.join('omnibus.erb').to_s
end

.templates_pathPathname

Returns:

  • (Pathname)

8
9
10
# File 'lib/ridley/bootstrapper.rb', line 8

def templates_path
  Ridley.root.join('bootstrappers')
end

Instance Method Details

#runSSH::ResponseSet

Returns:


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ridley/bootstrapper.rb', line 74

def run
  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

  SSH::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