vagrant/plugins/provisioners/chef/config/chef_solo.rb

106 lines
3.6 KiB
Ruby
Raw Normal View History

require_relative "base"
2013-01-14 00:41:32 +00:00
module VagrantPlugins
module Chef
module Config
class ChefSolo < Base
attr_accessor :cookbooks_path
attr_accessor :data_bags_path
attr_accessor :environments_path
attr_accessor :recipe_url
attr_accessor :roles_path
2014-01-02 22:40:57 +00:00
attr_accessor :synced_folder_type
2013-01-14 00:41:32 +00:00
def initialize
super
@cookbooks_path = UNSET_VALUE
2013-02-06 06:07:50 +00:00
@data_bags_path = UNSET_VALUE
@environments_path = UNSET_VALUE
2013-02-06 06:07:50 +00:00
@recipe_url = UNSET_VALUE
@roles_path = UNSET_VALUE
2014-01-02 22:40:57 +00:00
@synced_folder_type = UNSET_VALUE
2013-01-14 00:41:32 +00:00
end
2014-01-02 22:40:57 +00:00
def nfs=(value)
puts "DEPRECATION: The 'nfs' setting for the Chef Solo provisioner is"
2014-01-02 22:40:57 +00:00
puts "deprecated. Please use the 'synced_folder_type' setting instead."
puts "The 'nfs' setting will be removed in the next version of Vagrant."
if value
@synced_folder_type = "nfs"
else
@synced_folder_type = nil
end
end
#------------------------------------------------------------
# Internal methods
#------------------------------------------------------------
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
if @cookbooks_path == UNSET_VALUE
@cookbooks_path = []
@cookbooks_path << [:host, "cookbooks"] if !@recipe_url
@cookbooks_path << [:vm, "cookbooks"]
end
2013-01-14 00:41:32 +00:00
@data_bags_path = [] if @data_bags_path == UNSET_VALUE
@roles_path = [] if @roles_path == UNSET_VALUE
@environments_path = [] if @environments_path == UNSET_VALUE
@environments_path = [@environments_path].flatten
# Make sure the path is an array.
@cookbooks_path = prepare_folders_config(@cookbooks_path)
@data_bags_path = prepare_folders_config(@data_bags_path)
@roles_path = prepare_folders_config(@roles_path)
@environments_path = prepare_folders_config(@environments_path)
2013-01-14 00:41:32 +00:00
end
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 \
2013-09-06 06:59:11 +00:00
environment && environments_path.empty?
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",
2014-01-02 22:40:57 +00:00
path: raw_path.to_s)
end
end
{ "chef solo provisioner" => errors }
2013-01-14 00:41:32 +00:00
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)
# 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