Class: Ridley::HostCommander

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

Constant Summary collapse

PORT_CHECK_TIMEOUT =
3

Instance Method Summary collapse

Methods included from Logging

logger, #logger, set_logger

Constructor Details

#initializeHostCommander



19
20
21
22
# File 'lib/ridley/host_commander.rb', line 19

def initialize
  @connector_registry   = Celluloid::Registry.new
  @connector_supervisor = ConnectorSupervisor.new_link(@connector_registry)
end

Instance Method Details

#bootstrap(host, options = {}) ⇒ HostConnector::Response

Bootstrap a node

Options Hash (options):

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

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

    • :keys (Array, String) an array of key(s) to authenticate the ssh user with instead of a password

    • :timeout (Float) timeout value for SSH bootstrap (5.0)

    • :sudo (Boolean) run as sudo

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

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

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



63
64
65
# File 'lib/ridley/host_commander.rb', line 63

def bootstrap(host, options = {})
  execute(__method__, host, options)
end

#chef_client(host, options = {}) ⇒ HostConnector::Response

Perform a chef client run on a node

Options Hash (options):

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

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

    • :keys (Array, String) an array of key(s) to authenticate the ssh user with instead of a password

    • :timeout (Float) timeout value for SSH bootstrap (5.0)

    • :sudo (Boolean) run as sudo

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

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

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



84
85
86
# File 'lib/ridley/host_commander.rb', line 84

def chef_client(host, options = {})
  execute(__method__, host, options)
end

#connector_for(host, options = {}) ⇒ HostConnector::SSH, HostConnector::WinRM

Finds and returns the best HostConnector for a given host

Options Hash (options):

  • :ssh (Hash)
    • :port (Fixnum) the ssh port to connect on the node the bootstrap will be performed on (22)

    • :timeout (Float) [5.0] timeout value for testing SSH connection

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



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ridley/host_commander.rb', line 172

def connector_for(host, options = {})
  options = options.reverse_merge(ssh: Hash.new, winrm: Hash.new)
  options[:ssh][:port]   ||= HostConnector::SSH::DEFAULT_PORT
  options[:winrm][:port] ||= HostConnector::WinRM::DEFAULT_PORT

  if connector_port_open?(host, options[:winrm][:port])
    options.delete(:ssh)
    winrm
  elsif connector_port_open?(host, options[:ssh][:port], options[:ssh][:timeout])
    options.delete(:winrm)
    ssh
  else
    raise Errors::HostConnectionError, "No connector ports open on '#{host}'"
  end
end

#put_secret(host, secret, options = {}) ⇒ HostConnector::Response

Write your encrypted data bag secret on a node

Options Hash (options):

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

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

    • :keys (Array, String) an array of key(s) to authenticate the ssh user with instead of a password

    • :timeout (Float) timeout value for SSH bootstrap (5.0)

    • :sudo (Boolean) run as sudo

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

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

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



107
108
109
# File 'lib/ridley/host_commander.rb', line 107

def put_secret(host, secret, options = {})
  execute(__method__, host, secret, options)
end

#ruby_script(host, command_lines, options = {}) ⇒ HostConnector::Response

Execute line(s) of Ruby code on a node using Chef’s embedded Ruby

Options Hash (options):

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

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

    • :keys (Array, String) an array of key(s) to authenticate the ssh user with instead of a password

    • :timeout (Float) timeout value for SSH bootstrap (5.0)

    • :sudo (Boolean) run as sudo

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

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

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



130
131
132
# File 'lib/ridley/host_commander.rb', line 130

def ruby_script(host, command_lines, options = {})
  execute(__method__, host, command_lines, options)
end

#run(host, command, options = {}) ⇒ HostConnector::Response

Execute a shell command on a node

Options Hash (options):

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

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

    • :keys (Array, String) an array of key(s) to authenticate the ssh user with instead of a password

    • :timeout (Float) timeout value for SSH bootstrap (5.0)

    • :sudo (Boolean) run as sudo

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

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

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



42
43
44
# File 'lib/ridley/host_commander.rb', line 42

def run(host, command, options = {})
  execute(__method__, host, command, options)
end

#uninstall_chef(host, options = {}) ⇒ HostConnector::Response

Uninstall Chef from a node

Options Hash (options):

  • :skip_chef (Boolena) — default: false

    skip removal of the Chef package and the contents of the installation directory. Setting this to true will only remove any data and configurations generated by running Chef client.

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

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

    • :keys (Array, String) an array of key(s) to authenticate the ssh user with instead of a password

    • :timeout (Float) timeout value for SSH bootstrap (5.0)

    • :sudo (Boolean) run as sudo (true)

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

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

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



155
156
157
# File 'lib/ridley/host_commander.rb', line 155

def uninstall_chef(host, options = {})
  execute(__method__, host, options)
end