Be more sane about cookbook_paths default in Chef
This commit is contained in:
parent
a09c72d84e
commit
1af3255559
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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."
|
||||
|
|
Loading…
Reference in New Issue