lib/kitchen/lifecycle_hooks.rb
# Execute a specific local command hook.
#
# @param instance [Instance] The instance object to run against.
# @param state_file [StateFile] Instance state file object.
# @param hook [Hash] Hook configration to use.
# @return [void]
Execute a specific local command hook.
Execute a specific local command hook .
def run_local_hook(instance, state_file, hook)
      cmd = hook.delete(:local)
      state = state_file.read
      environment = {
        "KITCHEN_INSTANCE_NAME" => instance.name,
        "KITCHEN_SUITE_NAME" => instance.suite.name,
        "KITCHEN_PLATFORM_NAME" => instance.platform.name,
        "KITCHEN_INSTANCE_HOSTNAME" => state[:hostname].to_s,
      }
      if hook[:environment]
        hook[:environment].each do |k, v|
          environment[k.to_s] = v.to_s
        end
      end
      cwd = if hook[:cwd]
              File.expand_path(hook[:cwd], config[:kitchen_root])
            else
              config[:kitchen_root]
            end
      opts = {}.merge(hook).merge(cwd: cwd, environment: environment)
      run_command(cmd, opts)
    end
def run_local_hook ( instance , state_file , hook ) cmd = hook . delete ( :local ) state = state_file . read environment = { "KITCHEN_INSTANCE_NAME" => instance . name , "KITCHEN_SUITE_NAME" => instance . suite . name , "KITCHEN_PLATFORM_NAME" => instance . platform . name , "KITCHEN_INSTANCE_HOSTNAME" => state [ :hostname ] . to_s , } if hook [ :environment ] hook [ :environment ] . each do | k , v | environment [ k . to_s ] = v . to_s end end cwd = if hook [ :cwd ] File . expand_path ( hook [ :cwd ] , config [ :kitchen_root ] ) else config [ :kitchen_root ] end opts = { } . merge ( hook ) . merge ( cwd : cwd , environment : environment ) run_command ( cmd , opts ) end
Execute a specific local command hook.
Execute a specific local command hook .
# Set up some environment variables with instance info. # If the user specified env vars too, fix them up because symbol keys # make mixlib-shellout sad. # Default the cwd to the kitchen root and resolve a relative input cwd against that. # Build the options for mixlib-shellout.
None
void
instance
The instance object to run against.
The instance object to run against .
state_file
Instance state file object.
Instance state file object .
hook
Hook configration to use.
Hook configration to use .