Class: Chef::Knife::Core::BootstrapContext
- Inherits:
-
Object
- Object
- 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 compatibility, 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
Direct Known Subclasses
Instance Attribute Summary collapse
-
#chef_config ⇒ Object
Returns the value of attribute chef_config.
-
#client_pem ⇒ Object
Returns the value of attribute client_pem.
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #bootstrap_environment ⇒ Object
- #client_d ⇒ Object
- #config_content ⇒ Object
- #encrypted_data_bag_secret ⇒ Object
- #first_boot ⇒ Object
- #get_log_location ⇒ Object
-
#initialize(config, run_list, chef_config, secret = nil) ⇒ BootstrapContext
constructor
A new instance of BootstrapContext.
- #start_chef ⇒ Object
-
#trusted_certs ⇒ Object
Contains commands and content, see trusted_certs_content.
- #validation_key ⇒ Object
-
#version_to_install ⇒ String
Returns the version of Chef to install (as recognized by the Omnitruck API).
Constructor Details
#initialize(config, run_list, chef_config, secret = nil) ⇒ BootstrapContext
Returns a new instance of BootstrapContext.
39 40 41 42 43 44 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 39 def initialize(config, run_list, chef_config, secret = nil) @config = config @run_list = run_list @chef_config = chef_config @secret = secret end |
Instance Attribute Details
#chef_config ⇒ Object
Returns the value of attribute chef_config.
37 38 39 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 37 def chef_config @chef_config end |
#client_pem ⇒ Object
Returns the value of attribute client_pem.
35 36 37 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 35 def client_pem @client_pem end |
#config ⇒ Object
Returns the value of attribute config.
36 37 38 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 36 def config @config end |
Instance Method Details
#bootstrap_environment ⇒ Object
46 47 48 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 46 def bootstrap_environment config[:environment] end |
#client_d ⇒ Object
59 60 61 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 59 def client_d @client_d ||= client_d_content end |
#config_content ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 91 def config_content client_rb = " chef_server_url \"\#{chef_config[:chef_server_url]}\"\n validation_client_name \"\#{chef_config[:validation_client_name]}\"\n CONFIG\n\n unless chef_config[:chef_license].nil?\n client_rb << \"chef_license \\\"\#{chef_config[:chef_license]}\\\"\\n\"\n end\n\n unless chef_config[:config_log_level].nil? || chef_config[:config_log_level].empty?\n client_rb << %Q{log_level :\#{chef_config[:config_log_level]}\\n}\n end\n\n client_rb << \"log_location \#{get_log_location}\\n\"\n\n if config[:chef_node_name]\n client_rb << %Q{node_name \"\#{config[:chef_node_name]}\"\\n}\n else\n client_rb << \"# Using default node name (fqdn)\\n\"\n end\n\n # We configure :verify_api_cert only when it's overridden on the CLI\n # or when specified in the knife config.\n if !config[:node_verify_api_cert].nil? || config.key?(:verify_api_cert)\n value = config[:node_verify_api_cert].nil? ? config[:verify_api_cert] : config[:node_verify_api_cert]\n client_rb << %Q{verify_api_cert \#{value}\\n}\n end\n\n # We configure :ssl_verify_mode only when it's overridden on the CLI\n # or when specified in the knife config.\n if config[:node_ssl_verify_mode] || config.key?(:ssl_verify_mode)\n value = case config[:node_ssl_verify_mode]\n when \"peer\"\n :verify_peer\n when \"none\"\n :verify_none\n when nil\n config[:ssl_verify_mode]\n else\n nil\n end\n\n if value\n client_rb << %Q{ssl_verify_mode :\#{value}\\n}\n end\n end\n\n if config[:ssl_verify_mode]\n client_rb << %Q{ssl_verify_mode :\#{config[:ssl_verify_mode]}\\n}\n end\n\n if config[:bootstrap_proxy]\n client_rb << %Q{http_proxy \"\#{config[:bootstrap_proxy]}\"\\n}\n client_rb << %Q{https_proxy \"\#{config[:bootstrap_proxy]}\"\\n}\n end\n\n if config[:bootstrap_proxy_user]\n client_rb << %Q{http_proxy_user \"\#{config[:bootstrap_proxy_user]}\"\\n}\n client_rb << %Q{https_proxy_user \"\#{config[:bootstrap_proxy_user]}\"\\n}\n end\n\n if config[:bootstrap_proxy_pass]\n client_rb << %Q{http_proxy_pass \"\#{config[:bootstrap_proxy_pass]}\"\\n}\n client_rb << %Q{https_proxy_pass \"\#{config[:bootstrap_proxy_pass]}\"\\n}\n end\n\n if config[:bootstrap_no_proxy]\n client_rb << %Q{no_proxy \"\#{config[:bootstrap_no_proxy]}\"\\n}\n end\n\n if encrypted_data_bag_secret\n client_rb << %Q{encrypted_data_bag_secret \"/etc/chef/encrypted_data_bag_secret\"\\n}\n end\n\n unless trusted_certs.empty?\n client_rb << %Q{trusted_certs_dir \"/etc/chef/trusted_certs\"\\n}\n end\n\n if chef_config[:fips]\n client_rb << \"fips true\\n\"\n end\n\n unless chef_config[:file_cache_path].nil?\n client_rb << \"file_cache_path \\\"\#{chef_config[:file_cache_path]}\\\"\\n\"\n end\n\n unless chef_config[:file_backup_path].nil?\n client_rb << \"file_backup_path \\\"\#{chef_config[:file_backup_path]}\\\"\\n\"\n end\n\n client_rb\nend\n" |
#encrypted_data_bag_secret ⇒ Object
63 64 65 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 63 def encrypted_data_bag_secret @secret end |
#first_boot ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 213 def first_boot (config[:first_boot_attributes] = Mash.new(config[:first_boot_attributes]) || Mash.new).tap do |attributes| if config[:policy_name] && config[:policy_group] attributes[:policy_name] = config[:policy_name] attributes[:policy_group] = config[:policy_group] else attributes[:run_list] = @run_list end attributes.delete(:run_list) if attributes[:policy_name] && !attributes[:policy_name].empty? attributes.merge!(tags: config[:tags]) if config[:tags] && !config[:tags].empty? end end |
#get_log_location ⇒ Object
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 73 def get_log_location if !(chef_config[:config_log_location].class == IO ) && (chef_config[:config_log_location].nil? || chef_config[:config_log_location].to_s.empty?) "STDOUT" elsif chef_config[:config_log_location].equal?(:win_evt) raise "The value :win_evt is not supported for config_log_location on Linux Platforms \n" elsif chef_config[:config_log_location].equal?(:syslog) ":syslog" elsif chef_config[:config_log_location].equal?(STDOUT) "STDOUT" elsif chef_config[:config_log_location].equal?(STDERR) "STDERR" elsif chef_config[:config_log_location] %Q{"#{chef_config[:config_log_location]}"} else "STDOUT" end end |
#start_chef ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 185 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::Dist::CLIENT}" s = "#{client_path} -j /etc/chef/first-boot.json" if config[:verbosity] && config[:verbosity] >= 3 s << " -l trace" elsif config[:verbosity] && config[:verbosity] >= 2 s << " -l debug" end s << " -E #{bootstrap_environment}" unless bootstrap_environment.nil? s << " --no-color" unless config[:color] s end |
#trusted_certs ⇒ Object
Rename to trusted_certs_script
Contains commands and content, see trusted_certs_content
69 70 71 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 69 def trusted_certs @trusted_certs ||= trusted_certs_content end |
#validation_key ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 50 def validation_key if chef_config[:validation_key] && File.exist?(File.(chef_config[:validation_key])) IO.read(File.(chef_config[:validation_key])) else false end end |
#version_to_install ⇒ String
Returns the version of Chef to install (as recognized by the Omnitruck API)
203 204 205 206 207 208 209 210 211 |
# File 'lib/chef/knife/core/bootstrap_context.rb', line 203 def version_to_install return config[:bootstrap_version] if config[:bootstrap_version] if config[:channel] == "stable" Chef::VERSION.split(".").first else "latest" end end |