Class: Boxen::Puppeteer

Inherits:
Object
  • Object
show all
Defined in:
lib/boxen/puppeteer.rb

Overview

Manages an invocation of puppet.

Defined Under Namespace

Classes: Status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Puppeteer

Returns a new instance of Puppeteer.



19
20
21
# File 'lib/boxen/puppeteer.rb', line 19

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



17
18
19
# File 'lib/boxen/puppeteer.rb', line 17

def config
  @config
end

Instance Method Details

#commandObject



23
24
25
26
27
28
# File 'lib/boxen/puppeteer.rb', line 23

def command
  manifest = "#{config.repodir}/manifests/site.pp"
  puppet   = "#{config.repodir}/bin/puppet"

  [puppet, "apply", flags, manifest].flatten
end

#flagsObject



30
31
32
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
63
64
65
66
# File 'lib/boxen/puppeteer.rb', line 30

def flags
  flags = []
  root  = File.expand_path "../../..", __FILE__

  flags << ["--group",       "admin"]
  flags << ["--confdir",     "#{config.puppetdir}/conf"]
  flags << ["--vardir",      "#{config.puppetdir}/var"]
  flags << ["--libdir",      "#{config.repodir}/lib"]#:#{root}/lib"]
  flags << ["--libdir",      "#{root}/lib"]
  flags << ["--manifestdir", "#{config.repodir}/manifests"]
  flags << ["--modulepath",  "#{config.repodir}/modules:#{config.repodir}/shared"]

  # Log to both the console and a file.

  flags << ["--logdest", config.logfile]
  flags << ["--logdest", "console"]

  # For some reason Puppet tries to set up a bunch of rrd stuff
  # (user, group) unless reports are completely disabled.

  flags << "--no-report"
  flags << "--detailed-exitcodes"

  flags << "--show_diff"

  if config.profile?
    flags << "--evaltrace"
    flags << "--summarize"
  end

  flags << "--debug" if config.debug?
  flags << "--noop"  if config.pretend?

  flags << "--color=false" unless config.color?

  flags.flatten
end

#runObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/boxen/puppeteer.rb', line 68

def run
  FileUtils.mkdir_p config.puppetdir

  FileUtils.rm_f config.logfile

  FileUtils.mkdir_p File.dirname config.logfile
  FileUtils.touch config.logfile

  if File.file? "Puppetfile"
    librarian = "#{config.repodir}/bin/librarian-puppet"

    # Set an environment variable for librarian-puppet's
    # github_tarball source strategy.

    ENV["GITHUB_API_TOKEN"] = config.token

    unless system librarian, "install", "--path=#{config.repodir}/shared"
      abort "Can't run Puppet, fetching dependencies with librarian failed."
    end
  end

  warn command.join " " if config.debug?
  Boxen::Util.sudo *command

  Status.new($?.exitstatus)
end