2014-05-19 21:05:46 +00:00
|
|
|
require_relative "chef_solo"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Chef
|
|
|
|
module Config
|
2015-02-14 21:32:16 +00:00
|
|
|
class ChefZero < BaseRunner
|
|
|
|
# The path on disk where Chef cookbooks are stored.
|
|
|
|
# Default is "cookbooks".
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :cookbooks_path
|
|
|
|
|
|
|
|
# The path where data bags are stored on disk.
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :data_bags_path
|
|
|
|
|
|
|
|
# The path where environments are stored on disk.
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :environments_path
|
|
|
|
|
2015-07-28 16:41:51 +00:00
|
|
|
# The path where nodes are stored on disk.
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :nodes_path
|
|
|
|
|
2015-02-14 21:32:16 +00:00
|
|
|
# The path where roles are stored on disk.
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :roles_path
|
|
|
|
|
|
|
|
# The type of synced folders to use.
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :synced_folder_type
|
2014-05-19 21:05:46 +00:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
|
2015-02-14 21:32:16 +00:00
|
|
|
@cookbooks_path = UNSET_VALUE
|
|
|
|
@data_bags_path = UNSET_VALUE
|
|
|
|
@environments_path = UNSET_VALUE
|
2015-07-28 16:41:51 +00:00
|
|
|
@nodes_path = UNSET_VALUE
|
2015-02-14 21:32:16 +00:00
|
|
|
@roles_path = UNSET_VALUE
|
|
|
|
@synced_folder_type = UNSET_VALUE
|
2014-05-19 21:05:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
|
|
|
super
|
|
|
|
|
2015-02-14 21:32:16 +00:00
|
|
|
@synced_folder_type = nil if @synced_folder_type == UNSET_VALUE
|
|
|
|
|
|
|
|
if @cookbooks_path == UNSET_VALUE
|
|
|
|
@cookbooks_path = []
|
|
|
|
@cookbooks_path << [:host, "cookbooks"] if !@recipe_url
|
|
|
|
@cookbooks_path << [:vm, "cookbooks"]
|
|
|
|
end
|
|
|
|
|
|
|
|
@data_bags_path = [] if @data_bags_path == UNSET_VALUE
|
2015-07-28 16:41:51 +00:00
|
|
|
@nodes_path = [] if @nodes_path == UNSET_VALUE
|
2015-02-14 21:32:16 +00:00
|
|
|
@roles_path = [] if @roles_path == UNSET_VALUE
|
|
|
|
@environments_path = [] if @environments_path == UNSET_VALUE
|
|
|
|
@environments_path = [@environments_path].flatten
|
2014-05-19 21:05:46 +00:00
|
|
|
|
|
|
|
# Make sure the path is an array.
|
2015-02-14 21:32:16 +00:00
|
|
|
@cookbooks_path = prepare_folders_config(@cookbooks_path)
|
|
|
|
@data_bags_path = prepare_folders_config(@data_bags_path)
|
2015-07-28 16:41:51 +00:00
|
|
|
@nodes_path = prepare_folders_config(@nodes_path)
|
2015-02-14 21:32:16 +00:00
|
|
|
@roles_path = prepare_folders_config(@roles_path)
|
|
|
|
@environments_path = prepare_folders_config(@environments_path)
|
|
|
|
|
2014-05-19 21:05:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def validate(machine)
|
2015-02-14 21:32:16 +00:00
|
|
|
errors = validate_base(machine)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
{ "chef zero provisioner" => errors }
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
# This takes any of the configurations that take a path or
|
|
|
|
# array of paths and turns it into the proper format.
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
def prepare_folders_config(config)
|
|
|
|
# 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)
|
|
|
|
path
|
|
|
|
end
|
2014-05-19 21:05:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|