class Kitchen::Provisioner::PolicyfileZero
Policyfile + Chef
Zero provisioner.
@author Daniel DeLeo <dan@chef.io>
Public Instance Methods
(see Base#create_sandbox)
# File lib/kitchen/provisioner/policyfile_zero.rb, line 86 def create_sandbox create_sandbox_directory PolicyfileSandbox.new(config, sandbox_path, instance).populate prepare_cookbooks prepare_validation_pem prepare_client_rb end
(see Base#finalize_config!)
# File lib/kitchen/provisioner/policyfile_zero.rb, line 80 def finalize_config!(*args) super banner("Using policyfile mode for chef-client") end
We don't want to load Berkshelf or Librarian; Policyfile is managing dependencies, so these can only cause trouble.
# File lib/kitchen/provisioner/policyfile_zero.rb, line 126 def load_needed_dependencies!; end
(see Base#run_command)
# File lib/kitchen/provisioner/policyfile_zero.rb, line 95 def run_command level = config[:log_level] == :info ? :auto : config[:log_level] cmd = "#{sudo(config[:chef_client_path])} --local-mode" .tap { |str| str.insert(0, "& ") if powershell_shell? } args = [ "--config #{config[:root_path]}/client.rb", "--log_level #{level}", "--force-formatter", "--no-color", ] if config[:chef_zero_port] args << "--chef-zero-port #{config[:chef_zero_port]}" end if config[:log_file] args << "--logfile #{config[:log_file]}" end if config[:named_run_list] args << "--named-run-list #{config[:named_run_list]}" end wrap_shell_code( [cmd, *args].join(" ") .tap { |str| str.insert(0, reload_ps1_path) if windows_os? } ) end
Private Instance Methods
An instance of ChefDK::PolicyfileServices::ExportRepo
, configured with the sandbox path. Calling `#run` on this copies the cookbooks to the sandbox. Calling `#policy_name` returns the policy's name.
@api private
# File lib/kitchen/provisioner/policyfile_zero.rb, line 150 def policy_exporter # Must force this because TK by default copies the current cookbook to the sandbox # See ChefDK::PolicyfileServices::ExportRepo#assert_export_dir_clean! @policy_exporter ||= ChefDK::PolicyfileServices::ExportRepo.new(policyfile: config[:policyfile], export_dir: sandbox_path, force: true) end
Writes a client.rb configuration file to the sandbox directory.
@api private
# File lib/kitchen/provisioner/policyfile_zero.rb, line 172 def prepare_client_rb data = default_config_rb.merge(config[:client_rb]) data["use_policyfile"] = true data["versioned_cookbooks"] = true data["policy_name"] = policy_exporter.policy_name data["policy_group"] = "local" data["policy_document_native_api"] = true info("Preparing client.rb") debug("Creating client.rb from #{data.inspect}") File.open(File.join(sandbox_path, "client.rb"), "wb") do |file| file.write(format_config_file(data)) end end
Copies the policyfile's cookbooks to the sandbox.
@api private
# File lib/kitchen/provisioner/policyfile_zero.rb, line 139 def prepare_cookbooks Kitchen.mutex.synchronize do policy_exporter.run end end
Overrides behavior of parent class so that dna.json isn't created; we don't need it.
@api private
# File lib/kitchen/provisioner/policyfile_zero.rb, line 134 def prepare_json; end
Writes a fake (but valid) validation.pem into the sandbox directory.
@api private
# File lib/kitchen/provisioner/policyfile_zero.rb, line 161 def prepare_validation_pem info("Preparing validation.pem") debug("Using a dummy validation.pem") source = File.join(Kitchen.source_root, %w{support dummy-validation.pem}) FileUtils.cp(source, File.join(sandbox_path, "validation.pem")) end