Class: Kitchen::Provisioner::Puppet::Librarian

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/kitchen/provisioner/puppet/librarian.rb

Overview

Puppet module resolver that uses Librarian-Puppet and a Puppetfile to calculate # dependencies.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(puppetfile, path, logger = Kitchen.logger) ⇒ Librarian



31
32
33
34
35
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 31

def initialize(puppetfile, path, logger = Kitchen.logger)
  @puppetfile   = puppetfile
  @path       = path
  @logger     = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



53
54
55
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 53

def logger
  @logger
end

#pathObject (readonly)

Returns the value of attribute path.



53
54
55
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 53

def path
  @path
end

#puppetfileObject (readonly)

Returns the value of attribute puppetfile.



53
54
55
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 53

def puppetfile
  @puppetfile
end

Class Method Details

.load!(logger = Kitchen.logger) ⇒ Object



37
38
39
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 37

def self.load!(logger = Kitchen.logger)
  load_librarian!(logger)
end

.load_librarian!(logger) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 55

def self.load_librarian!(logger)
  first_load = require 'librarian/puppet'
  require 'librarian/puppet/environment'
  require 'librarian/action/resolve'
  require 'librarian/action/install'

  version = ::Librarian::Puppet::VERSION
  if first_load
    logger.debug("Librarian-Puppet #{version} library loaded")
  else
    logger.debug("Librarian-Puppet #{version} previously loaded")
  end
rescue LoadError => e
  logger.fatal("The `librarian-puppet' gem is missing and must be installed" \
    ' or cannot be properly activated. Run' \
    ' `gem install librarian-puppet` or add the following to your' \
    " Gemfile if you are using Bundler: `gem 'librarian-puppet'`.")
  raise UserError,
        "Could not load or activate Librarian-Puppet (#{e.message})"
end

Instance Method Details

#resolveObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 41

def resolve
  version = ::Librarian::Puppet::VERSION
  info("Resolving module dependencies with Librarian-Puppet #{version}...")
  debug("Using Puppetfile from #{puppetfile}")

  env = ::Librarian::Puppet::Environment.new(
    project_path: File.dirname(puppetfile))
  env.config_db.local['path'] = path
  ::Librarian::Action::Resolve.new(env).run
  ::Librarian::Action::Install.new(env).run
end