Class: Kitchen::Provisioner::ChefZero

Inherits:
ChefBase show all
Defined in:
lib/kitchen/provisioner/chef_zero.rb

Overview

Chef Zero provisioner.

Author:

Instance Attribute Summary

Attributes included from Configurable

#instance

Instance Method Summary collapse

Methods inherited from ChefBase

#init_command, #initialize, #install_command

Methods inherited from Base

#call, #cleanup_sandbox, #init_command, #initialize, #install_command, kitchen_provisioner_api_version, #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

This class inherits a constructor from Kitchen::Provisioner::ChefBase

Instance Method Details

#create_sandboxObject

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:

Examples:

overriding #create_sandbox


class MyProvisioner < Kitchen::Provisioner::Base
  def create_sandbox
    super
    # any further file copies, preparations, etc.
  end
end


52
53
54
55
56
57
# File 'lib/kitchen/provisioner/chef_zero.rb', line 52

def create_sandbox
  super
  prepare_chef_client_zero_rb
  prepare_validation_pem
  prepare_client_rb
end

#prepare_commandString

Generates a command string which will perform any commands or configuration required just before the main provisioner run command but after the sandbox has been transferred to the instance. If no work is required, then nil will be returned.

Returns:

  • (String)

    a command string



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/kitchen/provisioner/chef_zero.rb', line 60

def prepare_command
  return if modern?

  gem_bin = remote_path_join(config[:ruby_bindir], "gem").
    tap { |path| path.concat(".bat") if windows_os? }
  vars = [
    chef_client_zero_env,
    shell_var("gem", sudo(gem_bin))
  ].join("\n").concat("\n")

  prefix_command(shell_code_from_file(vars, "chef_zero_prepare_command_legacy"))
end

#run_commandString

Generates a command string which will invoke the main provisioner command on the prepared instance. If no work is required, then nil will be returned.

Returns:

  • (String)

    a command string



74
75
76
77
78
79
80
81
82
83
# File 'lib/kitchen/provisioner/chef_zero.rb', line 74

def run_command
  cmd = modern? ? local_mode_command : shim_command

  prefix_command(
    wrap_shell_code(
      [cmd, *chef_client_args, last_exit_code].join(" ").
      tap { |str| str.insert(0, reload_ps1_path) if windows_os? }
    )
  )
end