Class: Vagrant::Provisioners::Puppet
- Defined in:
- lib/vagrant/provisioners/puppet.rb
Defined Under Namespace
Classes: Config
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(env, config) ⇒ Puppet
constructor
A new instance of Puppet.
- #manifests_guest_path ⇒ Object
- #prepare ⇒ Object
- #provision! ⇒ Object
- #run_puppet_client ⇒ Object
- #set_module_paths ⇒ Object
- #share_manifests ⇒ Object
- #share_module_paths ⇒ Object
- #verify_binary(binary) ⇒ Object
- #verify_shared_folders(folders) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(env, config) ⇒ Puppet
Returns a new instance of Puppet.
74 75 76 77 78 |
# File 'lib/vagrant/provisioners/puppet.rb', line 74 def initialize(env, config) super @logger = Log4r::Logger.new("vagrant::provisioners::puppet") end |
Class Method Details
.config_class ⇒ Object
70 71 72 |
# File 'lib/vagrant/provisioners/puppet.rb', line 70 def self.config_class Config end |
Instance Method Details
#manifests_guest_path ⇒ Object
126 127 128 |
# File 'lib/vagrant/provisioners/puppet.rb', line 126 def manifests_guest_path File.join(config.pp_path, "manifests") end |
#prepare ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vagrant/provisioners/puppet.rb', line 80 def prepare # Calculate the paths we're going to use based on the environment @expanded_manifests_path = config.(env[:root_path]) @expanded_module_paths = config.(env[:root_path]) @manifest_file = File.join(manifests_guest_path, config.manifest_file) set_module_paths share_manifests share_module_paths end |
#provision! ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/vagrant/provisioners/puppet.rb', line 91 def provision! # Check that the shared folders are properly shared check = [manifests_guest_path] @module_paths.each do |host_path, guest_path| check << guest_path end verify_shared_folders(check) # Verify Puppet is installed and run it verify_binary("puppet") run_puppet_client end |
#run_puppet_client ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/vagrant/provisioners/puppet.rb', line 137 def run_puppet_client = [config.].flatten << "--modulepath '#{@module_paths.values.join(':')}'" if !@module_paths.empty? << @manifest_file = .join(" ") # Build up the custom facts if we have any facter = "" if !config.facter.empty? facts = [] config.facter.each do |key, value| facts << "FACTER_#{key}='#{value}'" end facter = "#{facts.join(" ")} " end command = "cd #{manifests_guest_path} && #{facter}puppet apply #{}" env[:ui].info I18n.t("vagrant.provisioners.puppet.running_puppet", :manifest => @manifest_file) env[:vm].channel.sudo(command) do |type, data| env[:ui].info(data.chomp, :prefix => false) end end |
#set_module_paths ⇒ Object
119 120 121 122 123 124 |
# File 'lib/vagrant/provisioners/puppet.rb', line 119 def set_module_paths @module_paths = {} @expanded_module_paths.each_with_index do |path, i| @module_paths[path] = File.join(config.pp_path, "modules-#{i}") end end |
#share_manifests ⇒ Object
105 106 107 |
# File 'lib/vagrant/provisioners/puppet.rb', line 105 def share_manifests env[:vm].config.vm.share_folder("manifests", manifests_guest_path, @expanded_manifests_path) end |
#share_module_paths ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/vagrant/provisioners/puppet.rb', line 109 def share_module_paths count = 0 @module_paths.each do |from, to| # Sorry for the cryptic key here, but VirtualBox has a strange limit on # maximum size for it and its something small (around 10) env[:vm].config.vm.share_folder("v-pp-m#{count}", to, from) count += 1 end end |
#verify_binary(binary) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/vagrant/provisioners/puppet.rb', line 130 def verify_binary(binary) env[:vm].channel.sudo("which #{binary}", :error_class => PuppetError, :error_key => :not_detected, :binary => binary) end |
#verify_shared_folders(folders) ⇒ Object
164 165 166 167 168 169 170 171 |
# File 'lib/vagrant/provisioners/puppet.rb', line 164 def verify_shared_folders(folders) folders.each do |folder| @logger.debug("Checking for shared folder: #{folder}") if !env[:vm].channel.test("test -d #{folder}") raise PuppetError, :missing_shared_folders end end end |