class Kitchen::Provisioner::ChefInfra
@author Fletcher Nichol <fnichol@nichol.ca>
for enterprise Chef features.
or kitchen-cinc if they are installed, providing a seamless upgrade path
This provisioner will automatically detect and use kitchen-chef-enterprise
Chef Infra provisioner with enterprise gem delegation support.
def self.new(config = {})
-
(ChefInfra)- provisioner instance
Parameters:
-
config(Hash) -- configuration hash
def self.new(config = {}) enterprise_gem = ChefBase.enterprise_gem_available? if enterprise_gem begin # Store reference to our class before requiring enterprise gem omnibus_chef_class = self # Require the enterprise gem's provisioner require "#{enterprise_gem}/provisioner/chef_infra" # Check if a different class was loaded enterprise_class = Kitchen::Provisioner.const_get(:ChefInfra) if enterprise_class != omnibus_chef_class # Log that we're delegating to enterprise implementation if config[:instance] && config[:instance].respond_to?(:logger) config[:instance].logger.info("Using #{enterprise_gem} implementation of ChefInfra provisioner") end # Return enterprise implementation return enterprise_class.allocate.tap do |instance| instance.send(:initialize, config) end end rescue LoadError, NameError => e # Enterprise gem didn't provide this provisioner, fall through to ours if config[:instance] && config[:instance].respond_to?(:logger) config[:instance].logger.debug("Could not load enterprise provisioner, using kitchen-omnibus-chef: #{e.message}") end end end # Use standard omnibus-chef implementation allocate.tap do |instance| instance.send(:initialize, config) end end
def add_optional_chef_client_args!(args)
- Api: - private
Parameters:
-
args(Array) -- array of flags
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
def chef_args(client_rb_filename)
- Api: - private
Returns:
-
(Array- an array of command line arguments)
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
def chef_client_zero_env
- Api: - private
Returns:
-
(String)- a shell script string
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
def create_sandbox
def create_sandbox super prepare_validation_pem prepare_config_rb end
def prepare_validation_pem
- Api: - private
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
def run_command
def run_command cmd = "#{sudo(config[:chef_client_path])} --local-mode".tap { |str| str.insert(0, "& ") if powershell_shell? } chef_cmd(cmd) end
def shim_command
- Api: - private
Returns:
-
(String)- the command string
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
def supports_policyfile?
- Api: - private
Returns:
-
(true)- always returns true
def supports_policyfile? true end