Class: Kitchen::Provisioner::Ansible::Librarian

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

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Librarian.



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

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

Instance Attribute Details

#ansiblefileObject (readonly)

Returns the value of attribute ansiblefile.



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

def ansiblefile
  @ansiblefile
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

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



37
38
39
# File 'lib/kitchen/provisioner/ansible/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/ansible/librarian.rb', line 55

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

Instance Method Details

#resolveObject



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

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