vagrant/plugins/provisioners/puppet/config/puppet.rb

180 lines
6.7 KiB
Ruby
Raw Normal View History

require "vagrant/util/counter"
2013-01-14 00:22:47 +00:00
module VagrantPlugins
module Puppet
module Config
class Puppet < Vagrant.plugin("2", :config)
extend Vagrant::Util::Counter
attr_accessor :facter
attr_accessor :hiera_config_path
2013-01-14 00:22:47 +00:00
attr_accessor :manifest_file
attr_accessor :manifests_path
attr_accessor :environment
attr_accessor :environmentpath
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
attr_accessor :temp_dir
attr_accessor :working_directory
2013-01-14 00:22:47 +00:00
def initialize
super
@hiera_config_path = UNSET_VALUE
@manifest_file = UNSET_VALUE
@manifests_path = UNSET_VALUE
@environment = UNSET_VALUE
@environmentpath = UNSET_VALUE
@module_path = UNSET_VALUE
@options = []
@facter = {}
@synced_folder_type = UNSET_VALUE
@temp_dir = UNSET_VALUE
@working_directory = UNSET_VALUE
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
end
2014-02-03 21:27:23 +00:00
def merge(other)
super.tap do |result|
result.facter = @facter.merge(other.facter)
result.environmentpath = @facter.merge(other.environmentpath)
result.environment = @facter.merge(other.environment)
2014-02-03 21:27:23 +00:00
end
end
def finalize!
super
if @environmentpath == UNSET_VALUE
if @manifests_path == UNSET_VALUE
if 1 #If puppet 3.4+
puts "Puppet 3.4+, manifests_path is unset and environmentpath is unset, presuming an environment"
@environmentpath = [:host, "environments"]
else
@manifests_path = [:host, "manifests"]
end
end
if @manifests_path && !@manifests_path.is_a?(Array)
@manifests_path = [:host, @manifests_path]
end
else
if @environmentpath && !@environmentpath.is_a?(Array)
@environmentpath = [:host, @environmentpath]
end
end
@hiera_config_path = nil if @hiera_config_path == UNSET_VALUE
if @environmentpath == UNSET_VALUE
@manifests_path[0] = @manifests_path[0].to_sym
@environmentpath = nil
@manifest_file = "default.pp" if @manifest_file == UNSET_VALUE
else
@environmentpath[0] = @environmentpath[0].to_sym
@environment = "production" if @environment == UNSET_VALUE
@manifest_file = nil
end
@module_path = nil if @module_path == UNSET_VALUE
@synced_folder_type = nil if @synced_folder_type == UNSET_VALUE
@temp_dir = nil if @temp_dir == UNSET_VALUE
@working_directory = nil if @working_directory == UNSET_VALUE
# 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
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
def validate(machine)
errors = _detected_errors
2013-01-14 00:22:47 +00:00
# Calculate the manifests and module paths based on env
this_expanded_module_paths = expanded_module_paths(machine.env.root_path)
2013-01-14 00:22:47 +00:00
if environmentpath != UNSET_VALUE && manifests_path != UNSET_VALUE
errors << "You may not specify both environmentpath and manifests_path. Please specify environment and environmentpath only"
end
2013-01-14 00:22:47 +00:00
# Manifests path/file validation
puts "manifests_path is #{manifests_path}"
if manifests_path != UNSET_VALUE && manifests_path[0].to_sym == :host
expanded_path = Pathname.new(manifests_path[1]).
expand_path(machine.env.root_path)
if !expanded_path.directory?
errors << I18n.t("vagrant.provisioners.puppet.manifests_path_missing",
path: expanded_path.to_s)
else
expanded_manifest_file = expanded_path.join(manifest_file)
if !expanded_manifest_file.file? && !expanded_manifest_file.directory?
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
# Environments path/file validation
if environmentpath != UNSET_VALUE && environmentpath[0].to_sym == :host
expanded_path = Pathname.new(environmentpath[1]).
expand_path(machine.env.root_path)
if !expanded_path.directory?
errors << I18n.t("vagrant.provisioners.puppet.environmentpath_missing",
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,
environmentpath: expanded_path.to_s)
end
end
2013-01-14 00:22:47 +00:00
end
if environmentpath == UNSET_VALUE && manifests_path == UNSET_VALUE
errors << "Please specify either a Puppet environmentpath + environment (preferred) or manifests_path (deprecated)."
end
2013-01-14 00:22:47 +00:00
# Module paths validation
this_expanded_module_paths.each do |path|
if !path.directory?
errors << I18n.t("vagrant.provisioners.puppet.module_path_missing",
path: path)
2013-01-14 00:22:47 +00:00
end
end
{ "puppet provisioner" => errors }
2013-01-14 00:22:47 +00:00
end
end
end
end
end