Class: Chef::Knife::Core::BootstrapContext
- 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
- #bootstrap_environment ⇒ Object
- #bootstrap_version_string ⇒ Object
-
#chef_version ⇒ Object
This function is used by older bootstrap templates other than chef-full and potentially by custom templates as well hence it’s logic needs to be preserved for backwards compatibility reasons until we hit Chef 12.
- #config_content ⇒ Object
- #encrypted_data_bag_secret ⇒ Object
- #first_boot ⇒ Object
-
#initialize(config, run_list, chef_config) ⇒ BootstrapContext
constructor
A new instance of BootstrapContext.
- #knife_config ⇒ Object
-
#latest_current_chef_version_string ⇒ Object
chef version string to fetch the latest current version from omnitruck If user is on X.Y.Z bootstrap will use the latest X release X here can be 10 or 11.
- #start_chef ⇒ Object
- #validation_key ⇒ Object
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_environment ⇒ Object
45 46 47 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 45 def bootstrap_environment @chef_config[:environment] || '_default' end |
#bootstrap_version_string ⇒ Object
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_version ⇒ Object
This function is used by older bootstrap templates other than chef-full and potentially by custom templates as well hence it’s logic needs to be preserved for backwards compatibility reasons until we hit Chef 12.
108 109 110 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 108 def chef_version knife_config[:bootstrap_version] || Chef::VERSION end |
#config_content ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 63 def config_content client_rb = <<-CONFIG 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 if knife_config[:bootstrap_no_proxy] client_rb << %Q{no_proxy "#{knife_config[:bootstrap_no_proxy]}"\n} end if encrypted_data_bag_secret client_rb << %Q{encrypted_data_bag_secret "/etc/chef/encrypted_data_bag_secret"\n} end client_rb end |
#encrypted_data_bag_secret ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 53 def encrypted_data_bag_secret knife_config[:secret] || begin if knife_config[:secret_file] && File.exist?(knife_config[:secret_file]) IO.read(File.(knife_config[:secret_file])) elsif @chef_config[:encrypted_data_bag_secret] && File.exist?(@chef_config[:encrypted_data_bag_secret]) IO.read(File.(@chef_config[:encrypted_data_bag_secret])) end end end |
#first_boot ⇒ Object
133 134 135 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 133 def first_boot (@config[:first_boot_attributes] || {}).merge(:run_list => @run_list) end |
#knife_config ⇒ Object
100 101 102 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 100 def knife_config @chef_config.key?(:knife) ? @chef_config[:knife] : {} end |
#latest_current_chef_version_string ⇒ Object
chef version string to fetch the latest current version from omnitruck If user is on X.Y.Z bootstrap will use the latest X release X here can be 10 or 11
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 116 def latest_current_chef_version_string chef_version_string = if knife_config[:bootstrap_version] knife_config[:bootstrap_version] else Chef::VERSION.split(".").first end installer_version_string = ["-v", chef_version_string] # If bootstrapping a pre-release version add -p to the installer string if chef_version_string.split(".").length > 3 installer_version_string << "-p" end installer_version_string.join(" ") end |
#start_chef ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 91 def start_chef # If the user doesn't have a client path configure, let bash use the PATH for what it was designed for client_path = @chef_config[:chef_client_path] || 'chef-client' s = "#{client_path} -j /etc/chef/first-boot.json" s << ' -l debug' if @config[:verbosity] and @config[:verbosity] >= 2 s << " -E #{bootstrap_environment}" if chef_version.to_f != 0.9 # only use the -E option on Chef 0.10+ s end |