Class: Ridley::NodeResource

Inherits:
Object
  • Object
show all
Defined in:
lib/ridley-connectors/resources/node_resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_registry, options = {}) ⇒ NodeResource

Returns a new instance of NodeResource.

Parameters:

  • connection_registry (Celluloid::Registry)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :server_url (String)

    URL to the Chef API

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

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

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

    filepath to the validator used to bootstrap the node

  • :encrypted_data_bag_secret (String)

    your organizations encrypted data bag secret

  • :chef_version (String)

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



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ridley-connectors/resources/node_resource.rb', line 33

def initialize(connection_registry, options = {})
  super(connection_registry)
  @server_url                = options[:server_url]
  @validator_path            = options[:validator_path]
  @validator_client          = options[:validator_client]
  @encrypted_data_bag_secret = options[:encrypted_data_bag_secret]
  @ssh                       = options[:ssh]
  @winrm                     = options[:winrm]
  @chef_version              = options[:chef_version]
  @host_commander            = HostCommander.new_link(options[:connector_pool_size])
end

Instance Attribute Details

#chef_versionObject (readonly)

Returns the value of attribute chef_version.



9
10
11
# File 'lib/ridley-connectors/resources/node_resource.rb', line 9

def chef_version
  @chef_version
end

#encrypted_data_bag_secretObject (readonly)

Returns the value of attribute encrypted_data_bag_secret.



6
7
8
# File 'lib/ridley-connectors/resources/node_resource.rb', line 6

def encrypted_data_bag_secret
  @encrypted_data_bag_secret
end

#server_urlObject (readonly)

Returns the value of attribute server_url.



3
4
5
# File 'lib/ridley-connectors/resources/node_resource.rb', line 3

def server_url
  @server_url
end

#sshObject (readonly)

Returns the value of attribute ssh.



7
8
9
# File 'lib/ridley-connectors/resources/node_resource.rb', line 7

def ssh
  @ssh
end

#validator_clientObject (readonly)

Returns the value of attribute validator_client.



5
6
7
# File 'lib/ridley-connectors/resources/node_resource.rb', line 5

def validator_client
  @validator_client
end

#validator_pathObject (readonly)

Returns the value of attribute validator_path.



4
5
6
# File 'lib/ridley-connectors/resources/node_resource.rb', line 4

def validator_path
  @validator_path
end

#winrmObject (readonly)

Returns the value of attribute winrm.



8
9
10
# File 'lib/ridley-connectors/resources/node_resource.rb', line 8

def winrm
  @winrm
end

Instance Method Details

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

Parameters:

  • host (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 (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)

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

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

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ridley-connectors/resources/node_resource.rb', line 79

def bootstrap(host, options = {})
  options = options.reverse_merge(
    server_url: server_url,
    validator_path: validator_path,
    validator_client: validator_client,
    encrypted_data_bag_secret: encrypted_data_bag_secret,
    ssh: ssh,
    winrm: winrm,
    chef_version: chef_version
  )

  host_commander.bootstrap(host, options)
end

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

Executes a Chef run using the best worker available for the given host.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :connector (String)

    a connectory type to prefer

Returns:



101
102
103
104
105
# File 'lib/ridley-connectors/resources/node_resource.rb', line 101

def chef_run(host, options = {})
  host_commander.chef_client(host, ssh: ssh, winrm: winrm, connector: options[:connector])
rescue Errors::HostConnectionError => ex
  abort(ex)
end

#platform_specific_run(host, commands) ⇒ HostConnector::Response Also known as: execute_platform_specific_command

Executes the given command on a node using a platform specific command.

Examples:

platform_specific_run("host.example.com", linux: "hostname -f", windows: "echo %COMPUTERNAME%")

Parameters:

  • host (String)
  • commands (Hash)

Returns:



156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/ridley-connectors/resources/node_resource.rb', line 156

def platform_specific_run(host, commands)
  case (type = host_commander.connector_for(host, ssh: ssh, winrm: winrm))
  when HostConnector::SSH
    raise Errors::CommandNotProvided.new(:ssh) unless commands[:ssh] and !commands[:ssh].empty?
    run(host, commands[:ssh])
  when HostConnector::WinRM
    raise Errors::CommandNotProvided.new(:winrm) unless commands[:winrm] and !commands[:winrm].empty?
    run(host, commands[:winrm])
  else
    raise RuntimeError, "#{type.class.to_s} is not a supported connector for #{self.class}##{__method__}"
  end
end

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

Puts a secret on the host using the best worker available for the given host.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :connector (String)

    a connectory type to prefer

Returns:



115
116
117
# File 'lib/ridley-connectors/resources/node_resource.rb', line 115

def put_secret(host, options = {})
  host_commander.put_secret(host, encrypted_data_bag_secret, ssh: ssh, winrm: winrm, connector: options[:connector])
end

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

Executes an arbitrary ruby script using the best worker available for the given host.

Parameters:

  • host (String)
  • command_lines (Array<String>)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :connector (String)

    a connectory type to prefer

Returns:



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

def ruby_script(host, command_lines, options = {})
  host_commander.ruby_script(host, command_lines, ssh: ssh, winrm: winrm, connector: options[:connector])
end

#run(host, command, options = {}) ⇒ HostConnector::Response Also known as: execute_command

Executes the given command on a node using the best worker available for the given host.

Parameters:

  • host (String)
  • command (String)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :connector (String)

    a connectory type to prefer

Returns:



141
142
143
# File 'lib/ridley-connectors/resources/node_resource.rb', line 141

def run(host, command, options = {})
  host_commander.run(host, command, ssh: ssh, winrm: winrm, connector: options[:connector])
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)

Returns:



191
192
193
194
# File 'lib/ridley-connectors/resources/node_resource.rb', line 191

def uninstall_chef(host, options = {})
  options = options.reverse_merge(ssh: ssh, winrm: winrm)
  host_commander.uninstall_chef(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:



219
220
221
222
# File 'lib/ridley-connectors/resources/node_resource.rb', line 219

def update_omnibus(host, options = {})
  options = options.reverse_merge(ssh: ssh, winrm: winrm)
  host_commander.update_omnibus(host, options)
end