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_user (String)
  • :ssh_password (String)
  • :ssh_keys (Array<String>, String)
  • :ssh_timeout (Float)

    timeout value for SSH bootstrap (default: 1.5)

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

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

  • :bootstrap_proxy (String)

    URL to a proxy server to bootstrap through (default: nil)

  • :encrypted_data_bag_secret_path (String)

    filepath on your host machine to your organizations encrypted data bag secret (default: nil)

  • :hints (Hash)

    a hash of Ohai hints to place on the bootstrapped node (default: Hash.new)

  • :attributes (Hash)

    a hash of attributes to use in the first Chef run (default: Hash.new)

  • :run_list (Array)

    an initial run list to bootstrap with (default: Array.new)

  • :chef_version (String)

    version of Chef to install on the node (default: CHEF_VERSION)

  • :environment (String)

    environment to join the node to (default: ‘_default’)

  • :sudo (Boolean)

    bootstrap with sudo (default: true)

  • :template (String)

    bootstrap template to use (default: omnibus)



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

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)
  }

  @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

#ssh_configHash (readonly)

Returns:

  • (Hash)


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

def ssh_config
  @ssh_config
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:



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ridley/bootstrapper.rb', line 72

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)
  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
    end
  end
ensure
  pool.terminate if pool
end