Class: Vagrant::Provisioners::Puppet

Inherits:
Base
  • Object
show all
Defined in:
lib/vagrant/provisioners/puppet.rb

Defined Under Namespace

Classes: Config

Instance Attribute Summary

Attributes inherited from Base

#action_env, #config

Instance Method Summary collapse

Methods inherited from Base

#cleanup, #env, #initialize, register, registered, #vm

Constructor Details

This class inherits a constructor from Vagrant::Provisioners::Base

Instance Method Details

#manifests_guest_pathObject



104
105
106
# File 'lib/vagrant/provisioners/puppet.rb', line 104

def manifests_guest_path
  File.join(config.pp_path, "manifests")
end

#prepareObject



72
73
74
75
76
# File 'lib/vagrant/provisioners/puppet.rb', line 72

def prepare
  set_module_paths
  share_manifests
  share_module_paths
end

#provision!Object



78
79
80
81
# File 'lib/vagrant/provisioners/puppet.rb', line 78

def provision!
  verify_binary("puppet")
  run_puppet_client
end

#run_puppet_clientObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/vagrant/provisioners/puppet.rb', line 114

def run_puppet_client
  options = [config.options].flatten
  options << "--modulepath '#{@module_paths.values.join(':')}'" if !@module_paths.empty?
  options << config.computed_manifest_file
  options = options.join(" ")

  commands = ["cd #{manifests_guest_path}",
              "puppet apply #{options}"]

  env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet", :manifest => config.computed_manifest_file)

  vm.ssh.execute do |ssh|
    ssh.sudo! commands do |ch, type, data|
      if type == :exit_status
        ssh.check_exit_status(data, commands)
      else
        env.ui.info(data)
      end
    end
  end
end

#set_module_pathsObject



97
98
99
100
101
102
# File 'lib/vagrant/provisioners/puppet.rb', line 97

def set_module_paths
  @module_paths = {}
  config.expanded_module_paths.each_with_index do |path, i|
    @module_paths[path] = File.join(config.pp_path, "modules-#{i}")
  end
end

#share_manifestsObject



83
84
85
# File 'lib/vagrant/provisioners/puppet.rb', line 83

def share_manifests
  env.config.vm.share_folder("manifests", manifests_guest_path, config.expanded_manifests_path)
end

#share_module_pathsObject



87
88
89
90
91
92
93
94
95
# File 'lib/vagrant/provisioners/puppet.rb', line 87

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.config.vm.share_folder("v-pp-m#{count}", to, from)
    count += 1
  end
end

#verify_binary(binary) ⇒ Object



108
109
110
111
112
# File 'lib/vagrant/provisioners/puppet.rb', line 108

def verify_binary(binary)
  vm.ssh.execute do |ssh|
    ssh.sudo!("which #{binary}", :error_class => PuppetError, :_key => :puppet_not_detected, :binary => binary)
  end
end