class Kitchen::Provisioner::ChefApply

@author SAWANOBORI Yukihiko <sawanoboriyu@higanworks.com>
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 Apply provisioner with enterprise gem delegation support.

def self.new(config = {})

Returns:
  • (ChefApply) - provisioner instance

Parameters:
  • config (Hash) -- configuration hash
def self.new(config = {})
  enterprise_gem = ChefBase.enterprise_gem_available?
  if enterprise_gem
    begin
      omnibus_chef_class = self
      require "#{enterprise_gem}/provisioner/chef_apply"
      enterprise_class = Kitchen::Provisioner.const_get(:ChefApply)
      if enterprise_class != omnibus_chef_class
        if config[:instance] && config[:instance].respond_to?(:logger)
          config[:instance].logger.info("Using #{enterprise_gem} implementation of ChefApply provisioner")
        end
        return enterprise_class.allocate.tap { |instance| instance.send(:initialize, config) }
      end
    rescue LoadError, NameError => e
      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
  allocate.tap { |instance| instance.send(:initialize, config) }
end

def create_sandbox

(see ChefBase#create_sandbox)
def create_sandbox
  @sandbox_path = Dir.mktmpdir("#{instance.name}-sandbox-")
  File.chmod(0755, sandbox_path)
  info("Preparing files for transfer")
  debug("Creating local sandbox in #{sandbox_path}")
  prepare_json
  prepare(:apply)
end

def init_command

(see ChefBase#init_command)
def init_command
  dirs = %w{
    apply
  }.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

def run_command

(see ChefSolo#run_command)
def run_command
  level = config[:log_level]
  lines = []
  config[:run_list].map do |recipe|
    cmd = sudo(config[:chef_apply_path]).dup
      .tap { |str| str.insert(0, "& ") if powershell_shell? }
    args = [
      "apply/#{recipe}.rb",
      "--log_level #{level}",
      "--no-color",
    ]
    args << "--logfile #{config[:log_file]}" if config[:log_file]
    args << "--chef-license #{config[:chef_license]}" if config[:chef_license]
    lines << wrap_shell_code(
      [cmd, *args].join(" ")
      .tap { |str| str.insert(0, reload_ps1_path) if windows_os? }
    )
  end
  prefix_command(lines.join("\n"))
end