Class: Ridley::NodeResource

Inherits:
Resource show all
Includes:
Logging
Defined in:
lib/ridley/resources/node_resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

logger, #logger, set_logger

Methods inherited from Resource

#all, #connection, #create, #delete, #delete_all, #find, #new, representation, represented_by, resource_path, set_resource_path, #update

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)



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ridley/resources/node_resource.rb', line 38

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
end

Instance Attribute Details

#chef_versionObject (readonly)

Returns the value of attribute chef_version.



14
15
16
# File 'lib/ridley/resources/node_resource.rb', line 14

def chef_version
  @chef_version
end

#encrypted_data_bag_secretObject (readonly)

Returns the value of attribute encrypted_data_bag_secret.



11
12
13
# File 'lib/ridley/resources/node_resource.rb', line 11

def encrypted_data_bag_secret
  @encrypted_data_bag_secret
end

#server_urlObject (readonly)

Returns the value of attribute server_url.



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

def server_url
  @server_url
end

#sshObject (readonly)

Returns the value of attribute ssh.



12
13
14
# File 'lib/ridley/resources/node_resource.rb', line 12

def ssh
  @ssh
end

#validator_clientObject (readonly)

Returns the value of attribute validator_client.



10
11
12
# File 'lib/ridley/resources/node_resource.rb', line 10

def validator_client
  @validator_client
end

#validator_pathObject (readonly)

Returns the value of attribute validator_path.



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

def validator_path
  @validator_path
end

#winrmObject (readonly)

Returns the value of attribute winrm.



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

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:



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ridley/resources/node_resource.rb', line 84

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) ⇒ HostConnector::Response

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

Parameters:

  • host (String)

Returns:



104
105
106
# File 'lib/ridley/resources/node_resource.rb', line 104

def chef_run(host)
  host_commander.chef_client(host, ssh: ssh, winrm: winrm)
end

#merge_data(target, options = {}) ⇒ Ridley::NodeObject

Merges the given data with the the data of the target node on the remote

Parameters:

  • target (Ridley::NodeResource, String)

    node or identifier of the node to merge

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

    a customizable set of options

Options Hash (options):

  • :run_list (Array)

    run list items to merge

  • :attributes (Hash)

    attributes of normal precedence to merge

Returns:

Raises:



155
156
157
158
159
160
161
# File 'lib/ridley/resources/node_resource.rb', line 155

def merge_data(target, options = {})
  unless node = find(target)
    abort Errors::ResourceNotFound.new
  end

  update(node.merge_data(options))
end

#put_secret(host) ⇒ HostConnector::Response

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

Parameters:

  • host (String)

Returns:



114
115
116
# File 'lib/ridley/resources/node_resource.rb', line 114

def put_secret(host)
  host_commander.put_secret(host, encrypted_data_bag_secret, ssh: ssh, winrm: winrm)
end

#ruby_script(host, command_lines) ⇒ HostConnector::Response

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

Parameters:

  • host (String)
  • command_lines (Array<String>)

Returns:



125
126
127
# File 'lib/ridley/resources/node_resource.rb', line 125

def ruby_script(host, command_lines)
  host_commander.ruby_script(host, command_lines, ssh: ssh, winrm: winrm)
end

#run(host, command) ⇒ Array<Symbol, 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)

Returns:



136
137
138
# File 'lib/ridley/resources/node_resource.rb', line 136

def run(host, command)
  host_commander.run(host, command, ssh: ssh, winrm: winrm)
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:



184
185
186
187
# File 'lib/ridley/resources/node_resource.rb', line 184

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