Class: Vagrant::Provisioners::PuppetServer

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

Defined Under Namespace

Classes: Config

Instance Attribute Summary

Attributes inherited from Base

#config, #env

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cleanup, #initialize, #prepare

Constructor Details

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

Class Method Details

.config_classObject



17
18
19
# File 'lib/vagrant/provisioners/puppet_server.rb', line 17

def self.config_class
  Config
end

Instance Method Details

#provision!Object



21
22
23
24
# File 'lib/vagrant/provisioners/puppet_server.rb', line 21

def provision!
  verify_binary("puppetd")
  run_puppetd_client
end

#run_puppetd_clientObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vagrant/provisioners/puppet_server.rb', line 33

def run_puppetd_client
  options = config.options
  options = [options] if !options.is_a?(Array)

  # Intelligently set the puppet node cert name based on certain
  # external parameters.
  cn = nil
  if config.puppet_node
    # If a node name is given, we use that directly for the certname
    cn = config.puppet_node
  elsif env[:vm].config.vm.host_name
    # If a host name is given, we explicitly set the certname to
    # nil so that the hostname becomes the cert name.
    cn = nil
  else
    # Otherwise, we default to the name of the box.
    cn = env[:vm].config.vm.box
  end

  # Add the certname option if there is one
  options += ["--certname", cn] if cn
  options = options.join(" ")

  command = "puppetd #{options} --server #{config.puppet_server}"

  env[:ui].info I18n.t("vagrant.provisioners.puppet_server.running_puppetd")
  env[:vm].channel.sudo(command) do |type, data|
    env[:ui].info(data.chomp, :prefix => false)
  end
end

#verify_binary(binary) ⇒ Object



26
27
28
29
30
31
# File 'lib/vagrant/provisioners/puppet_server.rb', line 26

def verify_binary(binary)
  env[:vm].channel.sudo("which #{binary}",
                        :error_class => PuppetServerError,
                        :error_key => :not_detected,
                        :binary => binary)
end