2013-01-14 00:22:47 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Puppet
|
|
|
|
module Config
|
2015-04-12 06:35:25 +00:00
|
|
|
class Puppet < Vagrant.plugin("2", :config)
|
|
|
|
|
|
|
|
# The path to Puppet's bin/ directory.
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :binary_path
|
|
|
|
|
2013-05-01 01:27:33 +00:00
|
|
|
attr_accessor :facter
|
2013-05-02 01:44:18 +00:00
|
|
|
attr_accessor :hiera_config_path
|
2013-01-14 00:22:47 +00:00
|
|
|
attr_accessor :manifest_file
|
|
|
|
attr_accessor :manifests_path
|
2014-10-20 04:28:38 +00:00
|
|
|
attr_accessor :environment
|
2014-10-20 04:34:54 +00:00
|
|
|
attr_accessor :environment_path
|
2013-01-14 00:22:47 +00:00
|
|
|
attr_accessor :module_path
|
|
|
|
attr_accessor :options
|
2014-01-02 22:44:49 +00:00
|
|
|
attr_accessor :synced_folder_type
|
2013-05-01 01:27:33 +00:00
|
|
|
attr_accessor :temp_dir
|
|
|
|
attr_accessor :working_directory
|
2013-01-14 00:22:47 +00:00
|
|
|
|
2013-05-01 01:27:33 +00:00
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
|
2015-04-12 06:35:25 +00:00
|
|
|
@binary_path = UNSET_VALUE
|
2014-10-20 04:34:54 +00:00
|
|
|
@hiera_config_path = UNSET_VALUE
|
|
|
|
@manifest_file = UNSET_VALUE
|
|
|
|
@manifests_path = UNSET_VALUE
|
|
|
|
@environment = UNSET_VALUE
|
|
|
|
@environment_path = UNSET_VALUE
|
|
|
|
@module_path = UNSET_VALUE
|
|
|
|
@options = []
|
|
|
|
@facter = {}
|
2014-01-02 22:37:47 +00:00
|
|
|
@synced_folder_type = UNSET_VALUE
|
2014-10-20 04:34:54 +00:00
|
|
|
@temp_dir = UNSET_VALUE
|
|
|
|
@working_directory = UNSET_VALUE
|
2014-01-02 22:37:47 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def nfs=(value)
|
|
|
|
puts "DEPRECATION: The 'nfs' setting for the Puppet provisioner is"
|
|
|
|
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
|
2013-05-01 01:27:33 +00:00
|
|
|
end
|
|
|
|
|
2014-02-03 21:27:23 +00:00
|
|
|
def merge(other)
|
|
|
|
super.tap do |result|
|
|
|
|
result.facter = @facter.merge(other.facter)
|
2014-10-20 04:34:54 +00:00
|
|
|
result.environment_path = @facter.merge(other.environment_path)
|
2014-10-20 04:28:38 +00:00
|
|
|
result.environment = @facter.merge(other.environment)
|
2014-02-03 21:27:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-05-01 01:27:33 +00:00
|
|
|
def finalize!
|
|
|
|
super
|
|
|
|
|
2015-04-12 19:31:31 +00:00
|
|
|
if @environment_path == UNSET_VALUE && @manifests_path == UNSET_VALUE
|
|
|
|
#If both are unset, assume 'manifests' mode for now. TBD: Switch to environments by default?
|
|
|
|
@manifests_path = [:host, "manifests"]
|
2013-11-26 06:39:20 +00:00
|
|
|
end
|
|
|
|
|
2015-04-12 19:31:31 +00:00
|
|
|
# If the paths are just strings, assume they are 'host' paths (rather than guest)
|
|
|
|
if @environment_path != UNSET_VALUE && !@environment_path.is_a?(Array)
|
|
|
|
@environment_path = [:host, @environment_path]
|
|
|
|
end
|
|
|
|
if @manifests_path != UNSET_VALUE && !@manifests_path.is_a?(Array)
|
|
|
|
@manifests_path = [:host, @manifests_path]
|
|
|
|
end
|
2013-05-02 01:44:18 +00:00
|
|
|
@hiera_config_path = nil if @hiera_config_path == UNSET_VALUE
|
2014-10-20 04:28:38 +00:00
|
|
|
|
2014-10-20 04:34:54 +00:00
|
|
|
if @environment_path == UNSET_VALUE
|
2014-10-20 04:28:38 +00:00
|
|
|
@manifests_path[0] = @manifests_path[0].to_sym
|
2014-10-20 04:34:54 +00:00
|
|
|
@environment_path = nil
|
2014-10-20 04:28:38 +00:00
|
|
|
@manifest_file = "default.pp" if @manifest_file == UNSET_VALUE
|
|
|
|
else
|
2014-10-20 04:34:54 +00:00
|
|
|
@environment_path[0] = @environment_path[0].to_sym
|
2014-10-20 04:28:38 +00:00
|
|
|
@environment = "production" if @environment == UNSET_VALUE
|
2015-04-12 19:31:31 +00:00
|
|
|
if @manifests_path == UNSET_VALUE
|
|
|
|
@manifests_path = nil
|
|
|
|
end
|
|
|
|
if @manifest_file == UNSET_VALUE
|
|
|
|
@manifest_file = nil
|
|
|
|
end
|
2014-10-20 04:28:38 +00:00
|
|
|
end
|
|
|
|
|
2015-04-12 06:35:25 +00:00
|
|
|
@binary_path = nil if @binary_path == UNSET_VALUE
|
2015-04-12 08:26:41 +00:00
|
|
|
@module_path = nil if @module_path == UNSET_VALUE
|
|
|
|
@synced_folder_type = nil if @synced_folder_type == UNSET_VALUE
|
|
|
|
@temp_dir = "/tmp/vagrant-puppet" if @temp_dir == UNSET_VALUE
|
|
|
|
@working_directory = nil if @working_directory == UNSET_VALUE
|
|
|
|
|
2013-05-01 01:27:33 +00:00
|
|
|
end
|
2013-01-14 00:22:47 +00:00
|
|
|
|
|
|
|
# Returns the module paths as an array of paths expanded relative to the
|
|
|
|
# root path.
|
|
|
|
def expanded_module_paths(root_path)
|
|
|
|
return [] if !module_path
|
|
|
|
|
|
|
|
# Get all the paths and expand them relative to the root path, returning
|
|
|
|
# the array of expanded paths
|
|
|
|
paths = module_path
|
|
|
|
paths = [paths] if !paths.is_a?(Array)
|
|
|
|
paths.map do |path|
|
|
|
|
Pathname.new(path).expand_path(root_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-18 21:08:38 +00:00
|
|
|
def validate(machine)
|
2013-09-04 23:56:45 +00:00
|
|
|
errors = _detected_errors
|
2013-01-18 21:08:38 +00:00
|
|
|
|
2013-01-14 00:22:47 +00:00
|
|
|
# Calculate the manifests and module paths based on env
|
2013-01-18 21:08:38 +00:00
|
|
|
this_expanded_module_paths = expanded_module_paths(machine.env.root_path)
|
2013-01-14 00:22:47 +00:00
|
|
|
|
|
|
|
# Manifests path/file validation
|
2015-04-12 08:26:41 +00:00
|
|
|
if manifests_path != nil && manifests_path[0].to_sym == :host
|
2013-11-26 06:46:10 +00:00
|
|
|
expanded_path = Pathname.new(manifests_path[1]).
|
|
|
|
expand_path(machine.env.root_path)
|
|
|
|
if !expanded_path.directory?
|
2013-11-26 06:39:20 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.puppet.manifests_path_missing",
|
2014-05-22 16:35:12 +00:00
|
|
|
path: expanded_path.to_s)
|
2013-11-26 06:39:20 +00:00
|
|
|
else
|
|
|
|
expanded_manifest_file = expanded_path.join(manifest_file)
|
2014-07-09 19:37:55 +00:00
|
|
|
if !expanded_manifest_file.file? && !expanded_manifest_file.directory?
|
2013-11-26 06:39:20 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.puppet.manifest_missing",
|
2014-05-22 16:35:12 +00:00
|
|
|
manifest: expanded_manifest_file.to_s)
|
2013-11-26 06:39:20 +00:00
|
|
|
end
|
2013-01-14 00:22:47 +00:00
|
|
|
end
|
2015-04-12 08:26:41 +00:00
|
|
|
elsif environment_path != nil && environment_path[0].to_sym == :host
|
|
|
|
# Environments path/file validation
|
2014-10-20 04:34:54 +00:00
|
|
|
expanded_path = Pathname.new(environment_path[1]).
|
2014-10-20 04:28:38 +00:00
|
|
|
expand_path(machine.env.root_path)
|
|
|
|
if !expanded_path.directory?
|
2014-10-20 04:34:54 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.puppet.environment_path_missing",
|
2014-10-20 04:28:38 +00:00
|
|
|
path: expanded_path.to_s)
|
|
|
|
else
|
|
|
|
expanded_environment_file = expanded_path.join(environment)
|
|
|
|
if !expanded_environment_file.file? && !expanded_environment_file.directory?
|
|
|
|
errors << I18n.t("vagrant.provisioners.puppet.environment_missing",
|
|
|
|
environment: environment.to_s,
|
2014-10-20 04:34:54 +00:00
|
|
|
environment_path: expanded_path.to_s)
|
2014-10-20 04:28:38 +00:00
|
|
|
end
|
|
|
|
end
|
2013-01-14 00:22:47 +00:00
|
|
|
end
|
|
|
|
|
2015-04-12 08:26:41 +00:00
|
|
|
if environment_path == nil && manifests_path == nil
|
2014-10-20 04:34:54 +00:00
|
|
|
errors << "Please specify either a Puppet environment_path + environment (preferred) or manifests_path (deprecated)."
|
2014-10-20 04:28:38 +00:00
|
|
|
end
|
|
|
|
|
2013-01-14 00:22:47 +00:00
|
|
|
# Module paths validation
|
|
|
|
this_expanded_module_paths.each do |path|
|
|
|
|
if !path.directory?
|
2013-01-18 21:08:38 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.puppet.module_path_missing",
|
2014-05-22 16:35:12 +00:00
|
|
|
path: path)
|
2013-01-14 00:22:47 +00:00
|
|
|
end
|
|
|
|
end
|
2013-01-18 21:08:38 +00:00
|
|
|
{ "puppet provisioner" => errors }
|
2013-01-14 00:22:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|