2012-04-19 04:53:19 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module Puppet
|
|
|
|
module Provisioner
|
|
|
|
class PuppetServerError < Vagrant::Errors::VagrantError
|
|
|
|
error_namespace("vagrant.provisioners.puppet_server")
|
|
|
|
end
|
|
|
|
|
2012-06-26 23:04:51 +00:00
|
|
|
class PuppetServer < Vagrant.plugin("1", :provisioner)
|
2012-06-26 23:02:44 +00:00
|
|
|
class Config < Vagrant.plugin("1", :config)
|
2012-04-19 04:53:19 +00:00
|
|
|
attr_accessor :puppet_server
|
|
|
|
attr_accessor :puppet_node
|
|
|
|
attr_accessor :options
|
|
|
|
attr_accessor :facter
|
|
|
|
|
|
|
|
def facter; @facter ||= {}; end
|
|
|
|
def puppet_server; @puppet_server || "puppet"; end
|
|
|
|
def options; @options ||= []; end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.config_class
|
|
|
|
Config
|
|
|
|
end
|
|
|
|
|
|
|
|
def provision!
|
2012-07-11 17:59:20 +00:00
|
|
|
verify_binary("puppet")
|
|
|
|
run_puppet_agent
|
2012-04-19 04:53:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def verify_binary(binary)
|
|
|
|
env[:vm].channel.sudo("which #{binary}",
|
|
|
|
:error_class => PuppetServerError,
|
|
|
|
:error_key => :not_detected,
|
|
|
|
:binary => binary)
|
|
|
|
end
|
|
|
|
|
2012-07-11 17:59:20 +00:00
|
|
|
def run_puppet_agent
|
2012-04-19 04:53:19 +00:00
|
|
|
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
|
|
|
|
|
2012-10-08 19:22:30 +00:00
|
|
|
command = "#{facter}puppet agent #{options} --server #{config.puppet_server} --detailed-exitcodes || [ $? -eq 2 ]"
|
2012-04-19 04:53:19 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|