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
  manifestdir = "#{config.repodir}/manifests"
  puppet      = "#{config.repodir}/bin/puppet"

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

#flagsObject



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
76
77
78
79
80
81
82
# File 'lib/boxen/puppeteer.rb', line 38

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 << ["--modulepath",  "#{config.repodir}/modules:#{config.repodir}/shared"]

  # Don't ever complain about Hiera to me
  flags << ["--hiera_config", hiera_config]

  # 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" unless config.report?
  flags << "--detailed-exitcodes"

  flags << "--graph" if config.graph?

  flags << "--show_diff"

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

  if config.future_parser?
    flags << "--parser=future"
  end

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

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

  flags.flatten
end

#hiera_configObject



30
31
32
33
34
35
36
# File 'lib/boxen/puppeteer.rb', line 30

def hiera_config
  if File.exist? "#{config.repodir}/config/hiera.yaml"
    "#{config.repodir}/config/hiera.yaml"
  else
    "/dev/null"
  end
end

#runObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/boxen/puppeteer.rb', line 84

def run
  FileUtils.mkdir_p config.puppetdir

  FileUtils.rm_f config.logfile

  FileUtils.rm_rf "#{config.puppetdir}/var/reports" if config.report?

  FileUtils.rm_rf "#{config.puppetdir}/var/state/graphs" if config.graph?

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

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

    unless config.enterprise?
      # Set an environment variable for librarian-puppet's
      # github_tarball source strategy.
      ENV["GITHUB_API_TOKEN"] = config.token
    end

    librarian_command = [librarian, "install", "--path=#{config.repodir}/shared"]
    librarian_command << "--verbose" if config.debug?

    warn librarian_command.join(" ") if config.debug?
    unless system *librarian_command
      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