Class: Ridley::HostCommander

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

Constant Summary collapse

DEFAULT_WINDOWS_CONNECTOR =
"winrm"
DEFAULT_LINUX_CONNECTOR =
"ssh"
VALID_CONNECTORS =
[ DEFAULT_WINDOWS_CONNECTOR, DEFAULT_LINUX_CONNECTOR ]

Instance Method Summary collapse

Constructor Details

#initialize(connector_pool_size = nil) ⇒ HostCommander

Returns a new instance of HostCommander.



33
34
35
36
37
# File 'lib/ridley-connectors/host_commander.rb', line 33

def initialize(connector_pool_size=nil)
  connector_pool_size ||= 1
  @connector_registry   = Celluloid::Registry.new
  @connector_supervisor = ConnectorSupervisor.new_link(@connector_registry, connector_pool_size)
end

Instance Method Details

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

Bootstrap a node

Parameters:

  • host (String)

    the host to perform the action on

  • 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

    • :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)

Returns:



80
81
82
# File 'lib/ridley-connectors/host_commander.rb', line 80

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

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

Perform a chef client run on a node

Parameters:

  • host (String)

    the host to perform the action on

  • 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

    • :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)

  • :connector (String)

    a connector type to prefer

Returns:



103
104
105
# File 'lib/ridley-connectors/host_commander.rb', line 103

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

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

Finds and returns the best HostConnector for a given host

Parameters:

  • host (String)

    the host to attempt to connect to

  • block (Proc)

    an optional block that is yielded the best HostConnector

  • options (Hash) (defaults to: {})

    a customizable set of options

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

    • :gateway (String) user@host:port

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

  • :connector (String)

    a connector type to prefer

Returns:



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/ridley-connectors/host_commander.rb', line 227

def connector_for(host, options = {})
  connector = options[:connector].to_s

  if !VALID_CONNECTORS.include?(connector)
    log.debug { "Connector '#{connector}' is not one of #{VALID_CONNECTORS}. Determining connector..." }
    connector = nil
  end

  if (connector == DEFAULT_WINDOWS_CONNECTOR || connector.nil?) && winrm.connector_port_open?(host, options)
    winrm
  elsif (connector == DEFAULT_LINUX_CONNECTOR || connector.nil?) && ssh.connector_port_open?(host, options)
    ssh
  else
    nil
  end
end

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

Write your encrypted data bag secret on a node

Parameters:

  • host (String)

    the host to perform the action on

  • secret (String)

    your organization’s encrypted data bag secret

  • 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

    • :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)

  • :connector (String)

    a connector type to prefer

Returns:



128
129
130
# File 'lib/ridley-connectors/host_commander.rb', line 128

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

Parameters:

  • host (String)

    the host to perform the action on

  • command_lines (Array<String>)

    An Array of lines of the command to be executed

  • 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

    • :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)

  • :connector (String)

    a connector type to prefer

Returns:



153
154
155
# File 'lib/ridley-connectors/host_commander.rb', line 153

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

Parameters:

  • host (String)

    the host to perform the action on

  • command (String)
  • 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

    • :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)

  • :connector (String)

    a connector type to prefer

Returns:



59
60
61
# File 'lib/ridley-connectors/host_commander.rb', line 59

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

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

Uninstall Chef from a node

Parameters:

  • host (String)

    the host to perform the action on

  • options (Hash) (defaults to: {})

    a customizable set of options

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)

  • :connector (String)

    a connector type to prefer

Returns:



180
181
182
# File 'lib/ridley-connectors/host_commander.rb', line 180

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

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

Update a node’s Omnibus installation of Chef

Parameters:

  • host (String)

    the host to perform the action on

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :chef_version (String)

    the version of Chef to install on the node

  • :prerelease (Boolean)

    install a prerelease version of Chef

  • :direct_url (String)

    a url pointing directly to a Chef package to install

  • :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)

Returns:



207
208
209
# File 'lib/ridley-connectors/host_commander.rb', line 207

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