class Kitchen::Provisioner::Ansible::Librarian

Ansible module resolver that uses Librarian-Ansible and a Ansiblefile to calculate # dependencies.

Attributes

ansiblefile[R]
logger[R]
path[R]

Public Class Methods

load!(logger = Kitchen.logger) click to toggle source
# File lib/kitchen/provisioner/ansible/librarian.rb, line 36
def self.load!(logger = Kitchen.logger)
  load_librarian!(logger)
end
load_librarian!(logger) click to toggle source
# File lib/kitchen/provisioner/ansible/librarian.rb, line 54
def self.load_librarian!(logger)
  first_load = require 'librarian/ansible'
  require 'librarian/ansible/environment'
  require 'librarian/action/resolve'
  require 'librarian/action/install'

  version = ::Librarian::Ansible::VERSION
  if first_load
    logger.debug("Librarian-Ansible #{version} library loaded")
  else
    logger.debug("Librarian-Ansible #{version} previously loaded")
  end
rescue LoadError => e
  logger.fatal("The `librarian-ansible' gem is missing and must be installed" \
    ' or cannot be properly activated. Run' \
    ' `gem install librarian-ansible` or add the following to your' \
    " Gemfile if you are using Bundler: `gem 'librarian-ansible'`.")
  raise UserError,
        "Could not load or activate Librarian-Ansible (#{e.message})"
end
new(ansiblefile, path, logger = Kitchen.logger) click to toggle source
# File lib/kitchen/provisioner/ansible/librarian.rb, line 30
def initialize(ansiblefile, path, logger = Kitchen.logger)
  @ansiblefile   = ansiblefile
  @path       = path
  @logger     = logger
end

Public Instance Methods

resolve() click to toggle source
# File lib/kitchen/provisioner/ansible/librarian.rb, line 40
def resolve
  version = ::Librarian::Ansible::VERSION
  info("Resolving role dependencies with Librarian-Ansible #{version}...")
  debug("Using Ansiblefile from #{ansiblefile}")

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