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, #install_command

Methods inherited from Base

#cleanup_sandbox, #finalize_config!, #init_command, #initialize, #install_command, #name, #sandbox_path

Methods included from Logging

#banner, #debug, #error, #fatal, #info, #warn

Methods included from Configurable

#[], #calculate_path, #config_keys, #diagnose, #finalize_config!, included

Constructor Details

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

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


41
42
43
44
45
46
# File 'lib/kitchen/provisioner/chef_zero.rb', line 41

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kitchen/provisioner/chef_zero.rb', line 49

def prepare_command
  return if modern?

  ruby_bin = Pathname.new(config[:ruby_bindir])

  # we are installing latest chef in order to get chef-zero and
  # Chef::ChefFS only. The version of Chef that gets run will be
  # the installed omnibus package. Yep, this is funky :)
  cmd = <<-PREPARE.gsub(/^ {10}/, "")
    #{chef_client_zero_env(:export)}
    if ! #{sudo(ruby_bin.join("gem"))} list chef-zero -i >/dev/null; then
      echo ">>>>>> Attempting to use chef-zero with old version of Chef"
      echo "-----> Installing chef zero dependencies"
      #{sudo(ruby_bin.join("gem"))} install chef --no-ri --no-rdoc --conservative
    fi
  PREPARE

  Util.wrap_command(cmd)
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



70
71
72
73
74
# File 'lib/kitchen/provisioner/chef_zero.rb', line 70

def run_command
  cmd = modern? ? local_mode_command : shim_command

  Util.wrap_command([cmd, *chef_client_args].join(" "))
end