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



19
20
21
# File 'lib/vagrant/provisioners/puppet_server.rb', line 19

def self.config_class
  Config
end

Instance Method Details

#provision!Object



23
24
25
26
# File 'lib/vagrant/provisioners/puppet_server.rb', line 23

def provision!
  verify_binary("puppet")
  run_puppet_agent
end

#run_puppet_agentObject



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
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vagrant/provisioners/puppet_server.rb', line 35

def run_puppet_agent
  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(" ")

  # 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 = "#{facter}puppet agent #{options} --server #{config.puppet_server} --detailed-exitcodes || [ $? -eq 2 ]"

  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



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

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