Class: Chef::Knife::Core::BootstrapContext

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/knife/core/bootstrap_context.rb

Overview

Instances of BootstrapContext are the context objects (i.e., self) for bootstrap templates. For backwards compatability, they must set the following instance variables:

  • @config - a hash of knifeā€™s config values

  • @run_list - the run list for the node to boostrap

Instance Method Summary collapse

Constructor Details

#initialize(config, run_list, chef_config) ⇒ BootstrapContext

Returns a new instance of BootstrapContext.



31
32
33
34
35
# File 'lib/chef/knife/core/bootstrap_context.rb', line 31

def initialize(config, run_list, chef_config)
  @config       = config
  @run_list     = run_list
  @chef_config  = chef_config
end

Instance Method Details

#bootstrap_environmentObject



45
46
47
# File 'lib/chef/knife/core/bootstrap_context.rb', line 45

def bootstrap_environment
  @chef_config[:environment] || '_default'
end

#bootstrap_version_stringObject



37
38
39
40
41
42
43
# File 'lib/chef/knife/core/bootstrap_context.rb', line 37

def bootstrap_version_string
  if @config[:prerelease]
    "--prerelease"
  else
    "--version #{chef_version}"
  end
end

#chef_versionObject



83
84
85
# File 'lib/chef/knife/core/bootstrap_context.rb', line 83

def chef_version
  knife_config[:bootstrap_version] || Chef::VERSION
end

#config_contentObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/chef/knife/core/bootstrap_context.rb', line 53

def config_content
  client_rb = <<-CONFIG
log_level        :info
log_location     STDOUT
chef_server_url  "#{@chef_config[:chef_server_url]}"
validation_client_name "#{@chef_config[:validation_client_name]}"
CONFIG
  if @config[:chef_node_name]
    client_rb << %Q{node_name "#{@config[:chef_node_name]}"\n}
  else
    client_rb << "# Using default node name (fqdn)\n"
  end

  if knife_config[:bootstrap_proxy]
    client_rb << %Q{http_proxy        "#{knife_config[:bootstrap_proxy]}"\n}
    client_rb << %Q{https_proxy       "#{knife_config[:bootstrap_proxy]}"\n}
  end
  client_rb
end

#knife_configObject



79
80
81
# File 'lib/chef/knife/core/bootstrap_context.rb', line 79

def knife_config
  @chef_config.key?(:knife) ? @chef_config[:knife] : {}
end

#start_chefObject



73
74
75
76
77
# File 'lib/chef/knife/core/bootstrap_context.rb', line 73

def start_chef
  s = "/usr/bin/chef-client -j /etc/chef/first-boot.json"
  s << " -E #{bootstrap_environment}" if chef_version.to_f != 0.9 # only use the -E option on Chef 0.10+
  s
end

#validation_keyObject



49
50
51
# File 'lib/chef/knife/core/bootstrap_context.rb', line 49

def validation_key
  IO.read(@chef_config[:validation_key])
end