From 1af32555595a8c762b794e053d53441216e8085d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 5 Feb 2013 22:00:03 -0800 Subject: [PATCH] Be more sane about cookbook_paths default in Chef --- plugins/provisioners/chef/config/chef_solo.rb | 41 +++++++++++-------- .../chef/provisioner/chef_solo.rb | 13 +----- templates/locales/en.yml | 2 + 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/plugins/provisioners/chef/config/chef_solo.rb b/plugins/provisioners/chef/config/chef_solo.rb index 552af423b..54e6e800f 100644 --- a/plugins/provisioners/chef/config/chef_solo.rb +++ b/plugins/provisioners/chef/config/chef_solo.rb @@ -12,29 +12,28 @@ module VagrantPlugins attr_accessor :encrypted_data_bag_secret_key_path attr_accessor :encrypted_data_bag_secret - def encrypted_data_bag_secret; @encrypted_data_bag_secret || "/tmp/encrypted_data_bag_secret"; end - def initialize super - @__default = ["cookbooks", [:vm, "cookbooks"]] + @cookbooks_path = UNSET_VALUE + @encrypted_data_bag_secret = UNSET_VALUE + @nfs = UNSET_VALUE end - # Provide defaults in such a way that they won't override the instance - # variable. This is so merging continues to work properly. - def cookbooks_path - @cookbooks_path || _default_cookbook_path - end + def finalize! + if @cookbooks_path == UNSET_VALUE + @cookbooks_path = [[:host, "cookbooks"], [:vm, "cookbooks"]] + end - # This stores a reference to the default cookbook path which is used - # later. Do not use this publicly. I apologize for not making it - # "protected" but it has to be called by Vagrant internals later. - def _default_cookbook_path - @__default - end + # Make sure all the paths are the proper format + @cookbooks_path.map! do |path| + path = [:host, path] if !path.is_a?(Array) + path + end - def nfs - @nfs || false + @encrypted_data_bag_secret = "/tmp/encrypted_data_bag_secret" if \ + @encrypted_data_bag_secret == UNSET_VALUE + @nfs = false if @nfs == UNSET_VALUE end def validate(machine) @@ -44,6 +43,16 @@ module VagrantPlugins errors << I18n.t("vagrant.config.chef.run_list_empty") if \ !run_list || run_list.empty? + @cookbooks_path.each do |type, path| + next if type != :host + expanded_path = File.expand_path(path, machine.env.root_path) + + if !File.exist?(expanded_path) + errors << I18n.t("vagrant.config.chef.cookbooks_path_missing", + :path => expanded_path) + end + end + { "chef solo provisioner" => errors } end end diff --git a/plugins/provisioners/chef/provisioner/chef_solo.rb b/plugins/provisioners/chef/provisioner/chef_solo.rb index ccb9a52d2..d08b6e46d 100644 --- a/plugins/provisioners/chef/provisioner/chef_solo.rb +++ b/plugins/provisioners/chef/provisioner/chef_solo.rb @@ -62,10 +62,7 @@ module VagrantPlugins paths = [paths] if paths.is_a?(String) || paths.first.is_a?(Symbol) results = [] - paths.each do |path| - path = [:host, path] if !path.is_a?(Array) - type, path = path - + paths.each do |type, path| # Create the local/remote path based on whether this is a host # or VM path. local_path = nil @@ -74,14 +71,6 @@ module VagrantPlugins # Get the expanded path that the host path points to local_path = File.expand_path(path, @machine.env.root_path) - # Super hacky but if we're expanded the default cookbook paths, - # and one of the host paths doesn't exist, then just ignore it, - # because that is fine. - if paths.equal?(@config._default_cookbook_path) && !File.directory?(local_path) - @logger.info("'cookbooks' folder doesn't exist on defaults. Ignoring.") - next - end - # Path exists on the host, setup the remote path remote_path = "#{@config.provisioning_path}/chef-solo-#{get_and_update_counter(:cookbooks_path)}" else diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 268c1c295..8c0263c7e 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -377,6 +377,8 @@ en: error_empty: "`%{field}` must be not be empty." chef: cookbooks_path_empty: "Must specify a cookbooks path for chef solo." + cookbooks_path_missing: |- + Cookbook path doesn't exist: %{path} run_list_empty: "Run list must not be empty." server_url_empty: "Chef server URL must be populated." validation_key_path: "Validation key path must be valid path to your chef server validation key."