2013-12-06 20:39:50 +00:00
|
|
|
require "vagrant/util/counter"
|
|
|
|
|
2013-01-14 00:22:47 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Puppet
|
|
|
|
module Config
|
|
|
|
class Puppet < Vagrant.plugin("2", :config)
|
2013-12-06 20:39:50 +00:00
|
|
|
extend Vagrant::Util::Counter
|
|
|
|
|
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
|
|
|
|
attr_accessor :module_path
|
|
|
|
attr_accessor :options
|
2013-05-01 01:27:33 +00:00
|
|
|
attr_accessor :temp_dir
|
|
|
|
attr_accessor :working_directory
|
2013-06-24 15:10:16 +00:00
|
|
|
attr_accessor :nfs
|
2013-01-14 00:22:47 +00:00
|
|
|
|
2013-05-01 01:27:33 +00:00
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
|
2013-05-02 01:44:18 +00:00
|
|
|
@hiera_config_path = UNSET_VALUE
|
2013-05-01 01:27:33 +00:00
|
|
|
@manifest_file = UNSET_VALUE
|
|
|
|
@manifests_path = UNSET_VALUE
|
|
|
|
@module_path = UNSET_VALUE
|
|
|
|
@options = []
|
|
|
|
@facter = {}
|
|
|
|
@temp_dir = UNSET_VALUE
|
|
|
|
@working_directory = UNSET_VALUE
|
2013-06-24 15:10:16 +00:00
|
|
|
@nfs = UNSET_VALUE
|
2013-05-01 01:27:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
|
|
|
super
|
|
|
|
|
2013-11-26 06:39:20 +00:00
|
|
|
if @manifests_path == UNSET_VALUE
|
|
|
|
@manifests_path = [:host, "manifests"]
|
|
|
|
end
|
|
|
|
|
|
|
|
if @manifests_path && !@manifests_path.is_a?(Array)
|
|
|
|
@manifests_path = [:host, @manifests_path]
|
|
|
|
end
|
|
|
|
|
|
|
|
@manifests_path[0] = @manifests_path[0].to_sym
|
|
|
|
|
2013-05-02 01:44:18 +00:00
|
|
|
@hiera_config_path = nil if @hiera_config_path == UNSET_VALUE
|
2013-05-01 01:27:33 +00:00
|
|
|
@manifest_file = "default.pp" if @manifest_file == UNSET_VALUE
|
|
|
|
@module_path = nil if @module_path == UNSET_VALUE
|
2013-12-06 20:39:50 +00:00
|
|
|
@temp_dir = nil if @temp_dir == UNSET_VALUE
|
2013-05-01 01:27:33 +00:00
|
|
|
@working_directory = nil if @working_directory == UNSET_VALUE
|
2013-06-24 15:10:16 +00:00
|
|
|
@nfs = false if @nfs == UNSET_VALUE
|
2013-12-06 20:39:50 +00:00
|
|
|
|
|
|
|
# Set a default temp dir that has an increasing counter so
|
|
|
|
# that multiple Puppet definitions won't overwrite each other
|
|
|
|
if !@temp_dir
|
|
|
|
counter = self.class.get_and_update_counter(:puppet_config)
|
|
|
|
@temp_dir = "/tmp/vagrant-puppet-#{counter}"
|
|
|
|
end
|
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
|
2013-11-26 06:39:20 +00:00
|
|
|
if 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",
|
2013-11-26 06:46:10 +00:00
|
|
|
:path => expanded_path.to_s)
|
2013-11-26 06:39:20 +00:00
|
|
|
else
|
|
|
|
expanded_manifest_file = expanded_path.join(manifest_file)
|
|
|
|
if !expanded_manifest_file.file?
|
|
|
|
errors << I18n.t("vagrant.provisioners.puppet.manifest_missing",
|
|
|
|
:manifest => expanded_manifest_file.to_s)
|
|
|
|
end
|
2013-01-14 00:22:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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",
|
|
|
|
: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
|