Class: Ridley::BootstrapContext::Unix

Inherits:
Base
  • Object
show all
Defined in:
lib/ridley/bootstrap_context/unix.rb

Overview

Represents a binding that will be evaluated as an ERB template. When bootstrapping nodes, an instance of this class represents the customizable and necessary configurations needed by the Host in order to install and connect to Chef. By default, this class will be used when SSH is the best way to connect to the node.

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes, #bootstrap_proxy, #chef_version, #encrypted_data_bag_secret, #environment, #hints, #node_name, #run_list, #server_url, #template_file, #validator_client, #validator_path

Instance Method Summary collapse

Methods inherited from Base

#bootstrap_command, #first_boot, #template, #templates_path, validate_options, #validation_key

Constructor Details

#initialize(options = {}) ⇒ Unix

Returns a new instance of Unix.

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :sudo (Boolean) — default: true

    bootstrap with sudo (default: true)



12
13
14
15
16
# File 'lib/ridley/bootstrap_context/unix.rb', line 12

def initialize(options = {})
  options = options.reverse_merge(sudo: true)
  @sudo   = options[:sudo]
  super(options)
end

Instance Attribute Details

#sudoObject (readonly)

Returns the value of attribute sudo.



8
9
10
# File 'lib/ridley/bootstrap_context/unix.rb', line 8

def sudo
  @sudo
end

Instance Method Details

#boot_commandString

Returns:

  • (String)


19
20
21
22
23
24
25
26
27
# File 'lib/ridley/bootstrap_context/unix.rb', line 19

def boot_command
  cmd = template.evaluate(self)

  if sudo
    cmd = "sudo #{cmd}"
  end

  cmd
end

#bootstrap_directoryString

Returns:

  • (String)


57
58
59
# File 'lib/ridley/bootstrap_context/unix.rb', line 57

def bootstrap_directory
  "/etc/chef"
end

#chef_configString

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ridley/bootstrap_context/unix.rb', line 30

def chef_config
  body = <<-CONFIG
  log_level        :info
  log_location     STDOUT
  chef_server_url  "#{server_url}"
  validation_client_name "#{validator_client}"
  CONFIG

  if node_name.present?
    body << %Q{node_name "#{node_name}"\n}
  else
    body << "# Using default node name (fqdn)\n"
  end

  if bootstrap_proxy.present?
    body << %Q{http_proxy        "#{bootstrap_proxy}"\n}
    body << %Q{https_proxy       "#{bootstrap_proxy}"\n}
  end

  if encrypted_data_bag_secret.present?
    body << %Q{encrypted_data_bag_secret "#{bootstrap_directory}/encrypted_data_bag_secret"\n}
  end

  body
end

#chef_runString

Returns:

  • (String)


62
63
64
# File 'lib/ridley/bootstrap_context/unix.rb', line 62

def chef_run
  "chef-client -j #{bootstrap_directory}/first-boot.json -E #{environment}"
end

#default_templateString

Returns:

  • (String)


67
68
69
# File 'lib/ridley/bootstrap_context/unix.rb', line 67

def default_template
  templates_path.join('unix_omnibus.erb').to_s
end