2015-11-23 23:14:32 +00:00
|
|
|
require "vagrant/util/presence"
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
require_relative "base_runner"
|
2013-01-14 00:41:32 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Chef
|
|
|
|
module Config
|
2014-10-31 18:22:09 +00:00
|
|
|
class ChefSolo < BaseRunner
|
2015-11-23 23:14:32 +00:00
|
|
|
include Vagrant::Util::Presence
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# The path on disk where Chef cookbooks are stored.
|
|
|
|
# Default is "cookbooks".
|
|
|
|
# @return [String]
|
2013-01-14 00:41:32 +00:00
|
|
|
attr_accessor :cookbooks_path
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# The path where data bags are stored on disk.
|
|
|
|
# @return [String]
|
2013-01-14 00:41:32 +00:00
|
|
|
attr_accessor :data_bags_path
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# The path where environments are stored on disk.
|
|
|
|
# @return [String]
|
2013-07-11 05:52:37 +00:00
|
|
|
attr_accessor :environments_path
|
2014-10-31 18:22:09 +00:00
|
|
|
|
2015-09-28 03:23:28 +00:00
|
|
|
# The path where nodes are stored on disk.
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :nodes_path
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
# A URL download a remote recipe from. Note: you should use chef-apply
|
|
|
|
# instead.
|
|
|
|
#
|
|
|
|
# @deprecated
|
|
|
|
#
|
|
|
|
# @return [String]
|
2013-11-26 19:44:16 +00:00
|
|
|
attr_accessor :recipe_url
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# The path where roles are stored on disk.
|
|
|
|
# @return [String]
|
2013-11-26 19:44:16 +00:00
|
|
|
attr_accessor :roles_path
|
2014-10-31 18:22:09 +00:00
|
|
|
|
|
|
|
# The type of synced folders to use.
|
|
|
|
# @return [String]
|
2014-01-02 22:40:57 +00:00
|
|
|
attr_accessor :synced_folder_type
|
2013-01-14 00:41:32 +00:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
|
2014-10-31 18:22:09 +00:00
|
|
|
@cookbooks_path = UNSET_VALUE
|
|
|
|
@data_bags_path = UNSET_VALUE
|
|
|
|
@environments_path = UNSET_VALUE
|
2015-09-28 03:23:28 +00:00
|
|
|
@nodes_path = UNSET_VALUE
|
2014-10-31 18:22:09 +00:00
|
|
|
@recipe_url = UNSET_VALUE
|
|
|
|
@roles_path = UNSET_VALUE
|
|
|
|
@synced_folder_type = UNSET_VALUE
|
|
|
|
end
|
|
|
|
|
2013-04-10 18:21:18 +00:00
|
|
|
#------------------------------------------------------------
|
|
|
|
# Internal methods
|
|
|
|
#------------------------------------------------------------
|
|
|
|
|
2013-02-06 06:00:03 +00:00
|
|
|
def finalize!
|
2013-04-15 19:08:08 +00:00
|
|
|
super
|
|
|
|
|
2014-01-02 22:40:57 +00:00
|
|
|
@recipe_url = nil if @recipe_url == UNSET_VALUE
|
|
|
|
@synced_folder_type = nil if @synced_folder_type == UNSET_VALUE
|
2013-03-21 05:20:19 +00:00
|
|
|
|
2013-02-06 06:00:03 +00:00
|
|
|
if @cookbooks_path == UNSET_VALUE
|
2013-03-21 05:20:19 +00:00
|
|
|
@cookbooks_path = []
|
|
|
|
@cookbooks_path << [:host, "cookbooks"] if !@recipe_url
|
|
|
|
@cookbooks_path << [:vm, "cookbooks"]
|
2013-02-06 06:00:03 +00:00
|
|
|
end
|
2013-01-14 00:41:32 +00:00
|
|
|
|
2013-07-11 05:52:37 +00:00
|
|
|
@data_bags_path = [] if @data_bags_path == UNSET_VALUE
|
2015-09-28 03:23:28 +00:00
|
|
|
@nodes_path = [] if @nodes_path == UNSET_VALUE
|
2013-07-11 05:52:37 +00:00
|
|
|
@roles_path = [] if @roles_path == UNSET_VALUE
|
2013-09-05 23:34:21 +00:00
|
|
|
@environments_path = [] if @environments_path == UNSET_VALUE
|
|
|
|
@environments_path = [@environments_path].flatten
|
2013-03-05 18:19:36 +00:00
|
|
|
|
2013-03-05 19:53:57 +00:00
|
|
|
# Make sure the path is an array.
|
2013-07-11 05:52:37 +00:00
|
|
|
@cookbooks_path = prepare_folders_config(@cookbooks_path)
|
|
|
|
@data_bags_path = prepare_folders_config(@data_bags_path)
|
2015-09-28 03:23:28 +00:00
|
|
|
@nodes_path = prepare_folders_config(@nodes_path)
|
2013-07-11 05:52:37 +00:00
|
|
|
@roles_path = prepare_folders_config(@roles_path)
|
|
|
|
@environments_path = prepare_folders_config(@environments_path)
|
2013-01-14 00:41:32 +00:00
|
|
|
end
|
|
|
|
|
2013-01-18 21:12:02 +00:00
|
|
|
def validate(machine)
|
2014-10-31 18:22:09 +00:00
|
|
|
errors = validate_base(machine)
|
2014-10-30 16:00:45 +00:00
|
|
|
|
2015-11-23 23:14:32 +00:00
|
|
|
if !present?(Array(cookbooks_path))
|
2014-10-30 16:00:45 +00:00
|
|
|
errors << I18n.t("vagrant.config.chef.cookbooks_path_empty")
|
|
|
|
end
|
|
|
|
|
2015-11-23 23:14:32 +00:00
|
|
|
if environment && !present?(environments_path)
|
2014-10-30 16:00:45 +00:00
|
|
|
errors << I18n.t("vagrant.config.chef.environment_path_required")
|
|
|
|
end
|
2013-11-27 02:57:27 +00:00
|
|
|
|
|
|
|
environments_path.each do |type, raw_path|
|
|
|
|
next if type != :host
|
|
|
|
|
|
|
|
path = Pathname.new(raw_path).expand_path(machine.env.root_path)
|
2013-12-06 21:57:27 +00:00
|
|
|
if !path.directory?
|
2013-11-27 02:57:27 +00:00
|
|
|
errors << I18n.t("vagrant.config.chef.environment_path_missing",
|
2014-10-30 16:00:45 +00:00
|
|
|
path: raw_path.to_s
|
|
|
|
)
|
2013-11-27 02:57:27 +00:00
|
|
|
end
|
|
|
|
end
|
2013-12-03 21:59:59 +00:00
|
|
|
|
|
|
|
{ "chef solo provisioner" => errors }
|
2013-01-14 00:41:32 +00:00
|
|
|
end
|
2013-03-05 19:53:57 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2014-10-30 16:00:45 +00:00
|
|
|
return [] if config.flatten.compact.empty?
|
|
|
|
|
2013-03-05 19:53:57 +00:00
|
|
|
# Make sure all the paths are in the proper format
|
|
|
|
config.map do |path|
|
|
|
|
path = [:host, path] if !path.is_a?(Array)
|
|
|
|
path
|
|
|
|
end
|
|
|
|
end
|
2013-01-14 00:41:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|