Class: Zest::BootstrapGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/knife-instance/bootstrap_generator.rb

Constant Summary collapse

CONFIG_FILE_TEMPLATE =
File.expand_path 'templates/boot.sh.erb', File.dirname(__FILE__)

Instance Method Summary collapse

Constructor Details

#initialize(validation_key_file, validation_client_name, chef_server_url, environment, run_list, hostname, color, base_domain, encrypted_databag_secret_file) ⇒ BootstrapGenerator

Returns a new instance of BootstrapGenerator.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/knife-instance/bootstrap_generator.rb', line 6

def initialize(validation_key_file, validation_client_name, chef_server_url, environment, run_list, hostname, color, base_domain, encrypted_databag_secret_file)
  @validation_client_name = validation_client_name
  @validation_key_file = validation_key_file
  @chef_server_url = chef_server_url
  @environment = environment
  @run_list = run_list
  @hostname = hostname
  @color = color
  @base_domain = base_domain
  @encrypted_databag_secret_file = encrypted_databag_secret_file
end

Instance Method Details

#config_contentObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/knife-instance/bootstrap_generator.rb', line 40

def config_content
  <<-CONFIG
  require 'syslog-logger'
  Logger::Syslog.class_eval do
attr_accessor :sync, :formatter
  end

  log_level              :info
  log_location           Logger::Syslog.new("chef-client")
  chef_server_url        "#{@chef_server_url}"
  validation_client_name "#{@validation_client_name}"
  node_name              "#{@hostname}"
  CONFIG
end

#encrypted_data_bag_secretObject



31
32
33
# File 'lib/knife-instance/bootstrap_generator.rb', line 31

def encrypted_data_bag_secret
  File.read @encrypted_databag_secret_file
end

#first_bootObject



18
19
20
21
22
23
24
25
# File 'lib/knife-instance/bootstrap_generator.rb', line 18

def first_boot
  {
    "run_list"          => @run_list,
    "assigned_hostname" => @hostname,
    "rails"             => {"cluster" => {"color" => @color}},
    "base_domain"       => @base_domain
  }.to_json
end

#generateObject



35
36
37
38
# File 'lib/knife-instance/bootstrap_generator.rb', line 35

def generate
  template = File.read(CONFIG_FILE_TEMPLATE)
  Erubis::Eruby.new(template).evaluate(self)
end

#start_chefObject



55
56
57
# File 'lib/knife-instance/bootstrap_generator.rb', line 55

def start_chef
  "/usr/bin/chef-client -j /etc/chef/first-boot.json -E #{@environment}"
end

#validation_keyObject



27
28
29
# File 'lib/knife-instance/bootstrap_generator.rb', line 27

def validation_key
  File.read(@validation_key_file)
end