Class: Kitchen::Provisioner::ChefBase

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/provisioner/chef_base.rb

Overview

Common implementation details for Chef-related provisioners.

Author:

Direct Known Subclasses

ChefSolo, ChefZero

Instance Attribute Summary

Attributes included from Configurable

#instance

Instance Method Summary collapse

Methods inherited from Base

#call, #cleanup_sandbox, #initialize, kitchen_provisioner_api_version, #prepare_command, #run_command, #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::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


97
98
99
100
# File 'lib/kitchen/provisioner/chef_base.rb', line 97

def create_sandbox
  super
  Chef::CommonSandbox.new(config, sandbox_path, instance).populate
end

#default_windows_chef_metadata_urlString

Returns a metadata URL for the Chef Omnitruck API suitable for installing a Windows MSI package.

Returns:

  • (String)

    a metadata URL for the Chef Omnitruck API suitable for installing a Windows MSI package



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/kitchen/provisioner/chef_base.rb', line 104

def 
  version = config[:require_chef_omnibus]
  version = "latest" if version == true
  base = if config[:chef_omnibus_url] =~ %r{/install.sh$}
    "#{File.dirname(config[:chef_omnibus_url])}/"
  else
    "https://www.chef.io/chef/"
  end

  url = "#{base}#{}"
  url << "?p=windows&m=x86_64&pv=2008r2" # same pacakge for all versions
  url << "&v=#{version.to_s.downcase}"
  url
end

#init_commandString

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

Returns:

  • (String)

    a command string



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/kitchen/provisioner/chef_base.rb', line 120

def init_command
  dirs = %w[
    cookbooks data data_bags environments roles clients
    encrypted_data_bag_secret
  ].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

  shell_code_from_file(vars, "chef_base_init_command")
end

#install_commandString

Generates a command string which will install and configure the provisioner software on an instance. If no work is required, then nil will be returned.

Returns:

  • (String)

    a command string



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/kitchen/provisioner/chef_base.rb', line 136

def install_command
  return unless config[:require_chef_omnibus]

  version = config[:require_chef_omnibus].to_s.downcase

  vars = if powershell_shell?
    install_command_vars_for_powershell(version)
  else
    install_command_vars_for_bourne(version)
  end

  shell_code_from_file(vars, "chef_base_install_command")
end