Class: Kitchen::Provisioner::ChefBase
- Defined in:
- lib/kitchen/provisioner/chef_base.rb
Overview
Common implementation details for Chef-related provisioners.
Instance Attribute Summary
Attributes included from Configurable
Instance Method Summary collapse
-
#create_sandbox ⇒ Object
Creates a temporary directory on the local workstation into which provisioner related files and directories can be copied or created.
- #doctor(state) ⇒ Object
-
#init_command ⇒ String
Generates a command string which will perform any data initialization or configuration required after the provisioner software is installed but before the sandbox has been transferred to the instance.
-
#initialize(config = {}) ⇒ ChefBase
constructor
Reads the local Chef::Config object (if present).
-
#install_command ⇒ String
Generates a command string which will install and configure the provisioner software on an instance.
Methods inherited from Base
#call, #cleanup_sandbox, kitchen_provisioner_api_version, #prepare_command, #run_command, #sandbox_path
Methods included from Logging
#banner, #debug, #error, #fatal, #info, #warn
Methods included from Configurable
#[], #bourne_shell?, #calculate_path, #config_keys, #diagnose, #diagnose_plugin, #finalize_config!, included, #name, #powershell_shell?, #remote_path_join, #unix_os?, #verify_dependencies, #windows_os?
Constructor Details
#initialize(config = {}) ⇒ ChefBase
Reads the local Chef::Config object (if present). We do this because we want to start bring Chef config and ChefDK tool config closer together. For example, we want to configure proxy settings in 1 location instead of 3 configuration files.
230 231 232 233 234 235 236 237 238 239 |
# File 'lib/kitchen/provisioner/chef_base.rb', line 230 def initialize(config = {}) super(config) if defined?(ChefConfig::WorkstationConfigLoader) ChefConfig::WorkstationConfigLoader.new(config[:config_path]).load end # This exports any proxy config present in the Chef config to # appropriate environment variables, which Test Kitchen respects ChefConfig::Config.export_proxies if defined?(ChefConfig::Config.export_proxies) end |
Instance Method Details
#create_sandbox ⇒ Object
Creates a temporary directory on the local workstation into which provisioner related files and directories can be copied or created. The contents of this directory will be copied over to the instance before invoking the provisioner's run command. After this method completes, it is expected that the contents of the sandbox is complete and ready for copy to the remote instance.
Note: any subclasses would be well advised to call super first when overriding this method, for example:
248 249 250 251 252 |
# File 'lib/kitchen/provisioner/chef_base.rb', line 248 def create_sandbox super Chef::CommonSandbox.new(config, sandbox_path, instance).populate end |
#doctor(state) ⇒ Object
241 242 243 244 245 |
# File 'lib/kitchen/provisioner/chef_base.rb', line 241 def doctor(state) deprecated_config.each do |attr, msg| info("**** #{attr} deprecated\n#{msg}") end end |
#init_command ⇒ String
Generates a command string which will perform any data initialization
or configuration required after the provisioner software is installed
but before the sandbox has been transferred to the instance. If no work
is required, then nil
will be returned.
255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/kitchen/provisioner/chef_base.rb', line 255 def init_command dirs = %w{ cookbooks data data_bags environments roles clients encrypted_data_bag_secret }.sort.map { |dir| remote_path_join(config[:root_path], dir) } vars = if powershell_shell? init_command_vars_for_powershell(dirs) else init_command_vars_for_bourne(dirs) end prefix_command(shell_code_from_file(vars, "chef_base_init_command")) end |
#install_command ⇒ String
Generates a command string which will install and configure the
provisioner software on an instance. If no work is required, then nil
will be returned.
271 272 273 274 275 |
# File 'lib/kitchen/provisioner/chef_base.rb', line 271 def install_command return unless config[:require_chef_omnibus] || config[:product_name] return if config[:product_name] && config[:install_strategy] == "skip" prefix_command(sudo(install_script_contents)) end |