Class: Ridley::UnixTemplateBinding

Inherits:
Object
  • Object
show all
Includes:
BootstrapBinding
Defined in:
lib/ridley/bootstrap_bindings/unix_template_binding.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.

Author:

Instance Attribute Summary collapse

Attributes included from BootstrapBinding

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

Instance Method Summary collapse

Methods included from BootstrapBinding

#first_boot, included, #template, #templates_path, #validation_key

Constructor Details

#initialize(options = {}) ⇒ UnixTemplateBinding

Returns a new instance of UnixTemplateBinding.

Parameters:

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

    a customizable set of options

Options Hash (options):

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

    filepath to the validator used to bootstrap the node (required)

  • :bootstrap_proxy (String) — default: nil

    URL to a proxy server to bootstrap through

  • :encrypted_data_bag_secret (String)

    your organizations encrypted data bag secret

  • :hints (Hash) — default: Hash.new

    a hash of Ohai hints to place on the bootstrapped node

  • :attributes (Hash) — default: Hash.new

    a hash of attributes to use in the first Chef run

  • :run_list (Array) — default: Array.new

    an initial run list to bootstrap with

  • :chef_version (String) — default: nil

    version of Chef to install on the node

  • :environment (String) — default: '_default'

    environment to join the node to

  • :sudo (Boolean) — default: true

    bootstrap with sudo (default: true)

  • :template (String) — default: 'unix_omnibus'

    bootstrap template to use



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ridley/bootstrap_bindings/unix_template_binding.rb', line 35

def initialize(options = {})
  options = self.class.default_options.merge(options)
  options[:template] ||= default_template
  self.class.validate_options(options)

  @template_file             = options[:template]
  @bootstrap_proxy           = options[:bootstrap_proxy]
  @chef_version              = options[:chef_version]
  @sudo                      = options[:sudo]
  @validator_path            = options[:validator_path]
  @encrypted_data_bag_secret = options[:encrypted_data_bag_secret]
  @hints                     = options[:hints]
  @server_url                = options[:server_url]
  @validator_client          = options[:validator_client]
  @node_name                 = options[:node_name]
  @attributes                = options[:attributes]
  @run_list                  = options[:run_list]
  @environment               = options[:environment]
end

Instance Attribute Details

#hintsObject (readonly)

Returns the value of attribute hints.



12
13
14
# File 'lib/ridley/bootstrap_bindings/unix_template_binding.rb', line 12

def hints
  @hints
end

#sudoObject (readonly)

Returns the value of attribute sudo.



11
12
13
# File 'lib/ridley/bootstrap_bindings/unix_template_binding.rb', line 11

def sudo
  @sudo
end

Instance Method Details

#boot_commandString

Returns:

  • (String)


56
57
58
59
60
61
62
63
64
# File 'lib/ridley/bootstrap_bindings/unix_template_binding.rb', line 56

def boot_command
  cmd = template.evaluate(self)

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

  cmd
end

#bootstrap_directoryString

Returns:

  • (String)


94
95
96
# File 'lib/ridley/bootstrap_bindings/unix_template_binding.rb', line 94

def bootstrap_directory
  "/etc/chef"
end

#chef_configString

Returns:

  • (String)


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/ridley/bootstrap_bindings/unix_template_binding.rb', line 67

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)


99
100
101
# File 'lib/ridley/bootstrap_bindings/unix_template_binding.rb', line 99

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

#default_templateString

Returns:

  • (String)


104
105
106
# File 'lib/ridley/bootstrap_bindings/unix_template_binding.rb', line 104

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