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.

Defined Under Namespace

Classes: LoggerUI

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.



61
62
63
64
65
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 61

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.



86
87
88
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 86

def logger
  @logger
end

#pathObject (readonly)

Returns the value of attribute path.



86
87
88
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 86

def path
  @path
end

#puppetfileObject (readonly)

Returns the value of attribute puppetfile.



86
87
88
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 86

def puppetfile
  @puppetfile
end

Class Method Details

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



67
68
69
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 67

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

.load_librarian!(logger) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 88

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



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/kitchen/provisioner/puppet/librarian.rb', line 71

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.expand_path(File.dirname(puppetfile))
  )
  env.ui = LoggerUI.new(@logger)

  env.config_db.local['path'] = path
  ::Librarian::Action::Resolve.new(env).run
  ::Librarian::Action::Install.new(env).run
end