class Kitchen::Provisioner::ChefInfra
Chef
Zero provisioner.
@author Fletcher Nichol <fnichol@nichol.ca>
Public Instance Methods
(see Base#create_sandbox
)
Kitchen::Provisioner::ChefBase#create_sandbox
# File lib/kitchen/provisioner/chef_infra.rb, line 48 def create_sandbox super prepare_validation_pem prepare_config_rb end
# File lib/kitchen/provisioner/chef_infra.rb, line 54 def run_command cmd = "#{sudo(config[:chef_client_path])} --local-mode".tap { |str| str.insert(0, "& ") if powershell_shell? } chef_cmd(cmd) end
Private Instance Methods
Adds optional flags to a chef-client command, depending on configuration data. Note that this method mutates the incoming Array.
@param args [Array<String>] array of flags @api private rubocop:disable Metrics/CyclomaticComplexity
# File lib/kitchen/provisioner/chef_infra.rb, line 68 def add_optional_chef_client_args!(args) if config[:json_attributes] json = remote_path_join(config[:root_path], "dna.json") args << "--json-attributes #{json}" end args << "--logfile #{config[:log_file]}" if config[:log_file] # these flags are chef-client local mode only and will not work # on older versions of chef-client if config[:chef_zero_host] args << "--chef-zero-host #{config[:chef_zero_host]}" end if config[:chef_zero_port] args << "--chef-zero-port #{config[:chef_zero_port]}" end args << "--profile-ruby" if config[:profile_ruby] if config[:slow_resource_report] if config[:slow_resource_report].is_a?(Integer) args << "--slow-report #{config[:slow_resource_report]}" else args << "--slow-report" end end end
Returns an Array of command line arguments for the chef client.
@return [Array<String>] an array of command line arguments @api private
# File lib/kitchen/provisioner/chef_infra.rb, line 102 def chef_args(client_rb_filename) level = config[:log_level] args = [ "--config #{remote_path_join(config[:root_path], client_rb_filename)}", "--log_level #{level}", "--force-formatter", "--no-color", ] add_optional_chef_client_args!(args) args end
Generates a string of shell environment variables needed for the chef-client-zero.rb shim script to properly function.
@return [String] a shell script string @api private
# File lib/kitchen/provisioner/chef_infra.rb, line 120 def chef_client_zero_env root = config[:root_path] gem_home = gem_path = remote_path_join(root, "chef-client-zero-gems") gem_cache = remote_path_join(gem_home, "cache") [ shell_env_var("CHEF_REPO_PATH", root), shell_env_var("GEM_HOME", gem_home), shell_env_var("GEM_PATH", gem_path), shell_env_var("GEM_CACHE", gem_cache), ].join("\n").concat("\n") end
Writes a fake (but valid) validation.pem into the sandbox directory.
@api private
# File lib/kitchen/provisioner/chef_infra.rb, line 136 def prepare_validation_pem info("Preparing validation.pem") debug("Using a dummy validation.pem") source = File.join(File.dirname(__FILE__), %w{.. .. .. support dummy-validation.pem}) FileUtils.cp(source, File.join(sandbox_path, "validation.pem")) end
Returns the command that will run a backwards compatible shim script that approximates local mode in a modern chef-client run.
@return [String] the command string @api private
# File lib/kitchen/provisioner/chef_infra.rb, line 150 def shim_command ruby = remote_path_join(config[:ruby_bindir], "ruby") .tap { |path| path.concat(".exe") if windows_os? } shim = remote_path_join(config[:root_path], "chef-client-zero.rb") "#{chef_client_zero_env}\n#{sudo(ruby)} #{shim}" end
This provisioner supports policyfiles, so override the default (which is false) @return [true] always returns true @api private
# File lib/kitchen/provisioner/chef_infra.rb, line 162 def supports_policyfile? true end