Sha256: fa54dc52fa6586755c96a1fbb5169d9b933491e2a278ebf16e665e68a9039b11

Contents?: true

Size: 1.54 KB

Versions: 27

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

require 'pathname'

module Bolt
  class Boltdir
    BOLTDIR_NAME = 'Boltdir'

    attr_reader :path, :config_file, :inventory_file, :modulepath, :hiera_config,
                :puppetfile, :rerunfile, :type, :resource_types

    def self.default_boltdir
      Boltdir.new(File.join('~', '.puppetlabs', 'bolt'), 'user')
    end

    # Search recursively up the directory hierarchy for the Boltdir. Look for a
    # directory called Boltdir or a file called bolt.yaml (for a control repo
    # type Boltdir). Otherwise, repeat the check on each directory up the
    # hierarchy, falling back to the default if we reach the root.
    def self.find_boltdir(dir)
      dir = Pathname.new(dir)
      if (dir + BOLTDIR_NAME).directory?
        new(dir + BOLTDIR_NAME, 'embedded')
      elsif (dir + 'bolt.yaml').file?
        new(dir, 'local')
      elsif dir.root?
        default_boltdir
      else
        find_boltdir(dir.parent)
      end
    end

    def initialize(path, type = 'option')
      @path = Pathname.new(path).expand_path
      @config_file = @path + 'bolt.yaml'
      @inventory_file = @path + 'inventory.yaml'
      @modulepath = [(@path + 'modules').to_s, (@path + 'site-modules').to_s, (@path + 'site').to_s]
      @hiera_config = @path + 'hiera.yaml'
      @puppetfile = @path + 'Puppetfile'
      @rerunfile = @path + '.rerun.json'
      @resource_types = @path + '.resource_types'
      @type = type
    end

    def to_s
      @path.to_s
    end

    def eql?(other)
      path == other.path
    end
    alias == eql?
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
bolt-2.7.0 lib/bolt/boltdir.rb
bolt-2.6.0 lib/bolt/boltdir.rb
bolt-2.5.0 lib/bolt/boltdir.rb
bolt-2.4.0 lib/bolt/boltdir.rb
bolt-2.3.1 lib/bolt/boltdir.rb
bolt-2.3.0 lib/bolt/boltdir.rb
bolt-2.2.0 lib/bolt/boltdir.rb
bolt-2.1.0 lib/bolt/boltdir.rb
bolt-2.0.1 lib/bolt/boltdir.rb
bolt-2.0.0 lib/bolt/boltdir.rb
bolt-1.49.0 lib/bolt/boltdir.rb
bolt-1.48.0 lib/bolt/boltdir.rb
bolt-1.47.0 lib/bolt/boltdir.rb
bolt-1.45.0 lib/bolt/boltdir.rb
bolt-1.44.0 lib/bolt/boltdir.rb
bolt-1.43.0 lib/bolt/boltdir.rb
bolt-1.42.0 lib/bolt/boltdir.rb
bolt-1.41.0 lib/bolt/boltdir.rb
bolt-1.40.0 lib/bolt/boltdir.rb
bolt-1.39.0 lib/bolt/boltdir.rb