Module: VagrantPlugins::R10k::Helpers
- Included in:
- Action::Base
- Defined in:
- lib/vagrant-r10k/helpers.rb
Overview
General-use vagrant-r10k helper methosd
Defined Under Namespace
Classes: ErrorWrapper
Instance Method Summary collapse
-
#env_dir(env) ⇒ String
Get the root directory for the environment.
-
#get_puppetfile(config) ⇒ R10K::Puppetfile
Get a Puppetfile for the specified path.
-
#module_path(env, prov, env_dir_path) ⇒ File
Get the module path.
-
#provision_enabled?(env) ⇒ Boolean
Determine if –no-provision was specified.
-
#puppet_provisioner(env) ⇒ Object
Get the Puppet provisioner from config.
-
#puppetfile_path(env) ⇒ File
Get the Puppetfile path from config.
-
#r10k_config(env) ⇒ Hash
Get the r10k config.
-
#r10k_enabled?(env) ⇒ Boolean
Determine if r10k.puppet_dir and r10k.puppetfile_path are in config.
Instance Method Details
#env_dir(env) ⇒ String
Get the root directory for the environment
63 64 65 |
# File 'lib/vagrant-r10k/helpers.rb', line 63 def env_dir(env) env[:root_path] end |
#get_puppetfile(config) ⇒ R10K::Puppetfile
Get a Puppetfile for the specified path
147 148 149 150 |
# File 'lib/vagrant-r10k/helpers.rb', line 147 def get_puppetfile(config) require 'r10k/puppetfile' R10K::Puppetfile.new(config[:puppet_dir], config[:module_path], config[:puppetfile_path]) end |
#module_path(env, prov, env_dir_path) ⇒ File
Get the module path
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/vagrant-r10k/helpers.rb', line 119 def module_path(env, prov, env_dir_path) unset = Vagrant::Plugin::V2::Config::UNSET_VALUE # if module_path has been set before, check if it fits to one defined in the provisioner config if env[:machine].config.r10k.module_path != unset module_path = env[:machine].config.r10k.module_path if prov.config.module_path.is_a?(Array) and ! prov.config.module_path.include?(module_path) raise ErrorWrapper.new(RuntimeError.new("vagrant-r10k: module_path \"#{module_path}\" is not within the ones defined in puppet provisioner; please correct this condition")) elsif ! prov.config.module_path.is_a?(Array) and prov.config.module_path != module_path raise ErrorWrapper.new(RuntimeError.new("vagrant-r10k: module_path \"#{module_path}\" is not the same as in puppet provisioner; please correct this condition")) end # no modulepath explict set in config, build one from the provisioner config else module_path = prov.config.module_path.is_a?(Array) ? prov.config.module_path[0] : prov.config.module_path # TODO - raise here instead of returning nil later env[:ui].info "vagrant-r10k: Building the r10k module path with puppet provisioner module_path \"#{module_path}\". (if module_path is an array, first element is used)" end return nil if module_path.nil? # now join the module_path with the env_dir to have an absolute path File.join(env_dir_path, module_path) end |
#provision_enabled?(env) ⇒ Boolean
Determine if –no-provision was specified
54 55 56 |
# File 'lib/vagrant-r10k/helpers.rb', line 54 def provision_enabled?(env) env.fetch(:provision_enabled, true) end |
#puppet_provisioner(env) ⇒ Object
Get the Puppet provisioner from config
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vagrant-r10k/helpers.rb', line 81 def puppet_provisioner(env) provider = nil env[:machine].config.vm.provisioners.each do |prov| if prov.respond_to?(:type) next if prov.type != :puppet else next if prov.name != :puppet end provider = prov end provider end |
#puppetfile_path(env) ⇒ File
Get the Puppetfile path from config
72 73 74 |
# File 'lib/vagrant-r10k/helpers.rb', line 72 def puppetfile_path(env) File.join(env_dir(env), env[:machine].config.r10k.puppetfile_path) end |
#r10k_config(env) ⇒ Hash
Get the r10k config
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/vagrant-r10k/helpers.rb', line 99 def r10k_config(env) ret = { :manifests => nil, :module_path => nil, :manifest_file => nil } ret[:env_dir_path] = env_dir(env) ret[:puppetfile_path] = puppetfile_path(env) prov = puppet_provisioner(env) return nil if prov.nil? ret[:module_path] = module_path(env, prov, ret[:env_dir_path]) return nil if ret[:module_path].nil? ret[:manifest_file] = File.join(ret[:env_dir_path], prov.config.manifest_file) ret[:manifests] = File.join(ret[:env_dir_path], prov.config.manifests_path[1]) ret[:puppet_dir] = File.join(ret[:env_dir_path], env[:machine].config.r10k.puppet_dir) ret end |
#r10k_enabled?(env) ⇒ Boolean
Determine if r10k.puppet_dir and r10k.puppetfile_path are in config
41 42 43 44 45 46 47 |
# File 'lib/vagrant-r10k/helpers.rb', line 41 def r10k_enabled?(env) unset = Vagrant::Plugin::V2::Config::UNSET_VALUE if env[:machine].config.r10k.puppet_dir == unset or env[:machine].config.r10k.puppetfile_path == unset return false end return true end |