Sha256: 9e856ad5dab8431a6378cd881ed85987712dbd36adcf87b47ecbddeed57a49d6

Contents?: true

Size: 1.31 KB

Versions: 15

Compression:

Stored size: 1.31 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

    def self.default_boltdir
      Boltdir.new(File.join('~', '.puppetlabs', 'bolt'))
    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)
      elsif (dir + 'bolt.yaml').file?
        new(dir)
      elsif dir.root?
        default_boltdir
      else
        find_boltdir(dir.parent)
      end
    end

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

    def to_s
      @path.to_s
    end

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
bolt-1.11.0 lib/bolt/boltdir.rb
bolt-1.10.0 lib/bolt/boltdir.rb
bolt-1.9.0 lib/bolt/boltdir.rb
bolt-1.8.1 lib/bolt/boltdir.rb
bolt-1.8.0 lib/bolt/boltdir.rb
bolt-1.7.0 lib/bolt/boltdir.rb
bolt-1.6.0 lib/bolt/boltdir.rb
bolt-1.5.0 lib/bolt/boltdir.rb
bolt-1.4.0 lib/bolt/boltdir.rb
bolt-1.3.0 lib/bolt/boltdir.rb
bolt-1.2.0 lib/bolt/boltdir.rb
bolt-1.1.0 lib/bolt/boltdir.rb
bolt-1.0.0 lib/bolt/boltdir.rb
bolt-0.25.0 lib/bolt/boltdir.rb
bolt-0.24.0 lib/bolt/boltdir.rb