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_key_path
|
||||||
attr_accessor :encrypted_data_bag_secret
|
attr_accessor :encrypted_data_bag_secret
|
||||||
|
|
||||||
def encrypted_data_bag_secret; @encrypted_data_bag_secret || "/tmp/encrypted_data_bag_secret"; end
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
|
||||||
@__default = ["cookbooks", [:vm, "cookbooks"]]
|
@cookbooks_path = UNSET_VALUE
|
||||||
|
@encrypted_data_bag_secret = UNSET_VALUE
|
||||||
|
@nfs = UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
# Provide defaults in such a way that they won't override the instance
|
def finalize!
|
||||||
# variable. This is so merging continues to work properly.
|
if @cookbooks_path == UNSET_VALUE
|
||||||
def cookbooks_path
|
@cookbooks_path = [[:host, "cookbooks"], [:vm, "cookbooks"]]
|
||||||
@cookbooks_path || _default_cookbook_path
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# This stores a reference to the default cookbook path which is used
|
# Make sure all the paths are the proper format
|
||||||
# later. Do not use this publicly. I apologize for not making it
|
@cookbooks_path.map! do |path|
|
||||||
# "protected" but it has to be called by Vagrant internals later.
|
path = [:host, path] if !path.is_a?(Array)
|
||||||
def _default_cookbook_path
|
path
|
||||||
@__default
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def nfs
|
@encrypted_data_bag_secret = "/tmp/encrypted_data_bag_secret" if \
|
||||||
@nfs || false
|
@encrypted_data_bag_secret == UNSET_VALUE
|
||||||
|
@nfs = false if @nfs == UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate(machine)
|
def validate(machine)
|
||||||
|
@ -44,6 +43,16 @@ module VagrantPlugins
|
||||||
errors << I18n.t("vagrant.config.chef.run_list_empty") if \
|
errors << I18n.t("vagrant.config.chef.run_list_empty") if \
|
||||||
!run_list || run_list.empty?
|
!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 }
|
{ "chef solo provisioner" => errors }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -62,10 +62,7 @@ module VagrantPlugins
|
||||||
paths = [paths] if paths.is_a?(String) || paths.first.is_a?(Symbol)
|
paths = [paths] if paths.is_a?(String) || paths.first.is_a?(Symbol)
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
paths.each do |path|
|
paths.each do |type, path|
|
||||||
path = [:host, path] if !path.is_a?(Array)
|
|
||||||
type, path = path
|
|
||||||
|
|
||||||
# Create the local/remote path based on whether this is a host
|
# Create the local/remote path based on whether this is a host
|
||||||
# or VM path.
|
# or VM path.
|
||||||
local_path = nil
|
local_path = nil
|
||||||
|
@ -74,14 +71,6 @@ module VagrantPlugins
|
||||||
# Get the expanded path that the host path points to
|
# Get the expanded path that the host path points to
|
||||||
local_path = File.expand_path(path, @machine.env.root_path)
|
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
|
# Path exists on the host, setup the remote path
|
||||||
remote_path = "#{@config.provisioning_path}/chef-solo-#{get_and_update_counter(:cookbooks_path)}"
|
remote_path = "#{@config.provisioning_path}/chef-solo-#{get_and_update_counter(:cookbooks_path)}"
|
||||||
else
|
else
|
||||||
|
|
|
@ -377,6 +377,8 @@ en:
|
||||||
error_empty: "`%{field}` must be not be empty."
|
error_empty: "`%{field}` must be not be empty."
|
||||||
chef:
|
chef:
|
||||||
cookbooks_path_empty: "Must specify a cookbooks path for chef solo."
|
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."
|
run_list_empty: "Run list must not be empty."
|
||||||
server_url_empty: "Chef server URL must be populated."
|
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."
|
validation_key_path: "Validation key path must be valid path to your chef server validation key."
|
||||||
|
|
Loading…
Reference in New Issue