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

Returns a new instance of Librarian.



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

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.



58
59
60
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 58

def logger
  @logger
end

#pathObject (readonly)

Returns the value of attribute path.



58
59
60
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 58

def path
  @path
end

#puppetfileObject (readonly)

Returns the value of attribute puppetfile.



58
59
60
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 58

def puppetfile
  @puppetfile
end

Class Method Details

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



42
43
44
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 42

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

.load_librarian!(logger) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 60

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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 46

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