From af9177550a97511bd5cf1403ec1e02da0ca7626b Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 30 Oct 2014 12:00:45 -0400 Subject: [PATCH] Properly handle empty/nil values in Chef Solo config --- plugins/provisioners/chef/config/chef_solo.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/provisioners/chef/config/chef_solo.rb b/plugins/provisioners/chef/config/chef_solo.rb index e8e5c8e04..524596962 100644 --- a/plugins/provisioners/chef/config/chef_solo.rb +++ b/plugins/provisioners/chef/config/chef_solo.rb @@ -65,10 +65,14 @@ module VagrantPlugins def validate(machine) errors = _detected_errors errors.concat(validate_base(machine)) - errors << I18n.t("vagrant.config.chef.cookbooks_path_empty") if \ - !cookbooks_path || [cookbooks_path].flatten.empty? - errors << I18n.t("vagrant.config.chef.environment_path_required") if \ - environment && environments_path.empty? + + if [cookbooks_path].flatten.compact.empty? + errors << I18n.t("vagrant.config.chef.cookbooks_path_empty") + end + + if environment && environments_path.empty? + errors << I18n.t("vagrant.config.chef.environment_path_required") + end environments_path.each do |type, raw_path| next if type != :host @@ -76,7 +80,8 @@ module VagrantPlugins path = Pathname.new(raw_path).expand_path(machine.env.root_path) if !path.directory? errors << I18n.t("vagrant.config.chef.environment_path_missing", - path: raw_path.to_s) + path: raw_path.to_s + ) end end @@ -93,6 +98,8 @@ module VagrantPlugins # Make sure the path is an array config = [config] if !config.is_a?(Array) || config.first.is_a?(Symbol) + return [] if config.flatten.compact.empty? + # Make sure all the paths are in the proper format config.map do |path| path = [:host, path] if !path.is_a?(Array)