Sha256: 9293e68b6e30b6fae994e04a1d438e73b9490683904bc405f819a1dafb7d354b

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'r10k/logging'

module R10K
  class Deployment
    class Config
      class Loader

        include R10K::Logging

        attr_reader :loadpath

        CONFIG_FILE = 'r10k.yaml'
        DEFAULT_LOCATION = File.join('/etc/puppetlabs/r10k', CONFIG_FILE)
        OLD_DEFAULT_LOCATION = File.join('/etc', CONFIG_FILE)

        # Search for a deployment configuration file (r10k.yaml) in several locations
        def initialize
          @loadpath = []
          populate_loadpath
        end

        # @return [String] The path to the first valid configfile
        def search

          # If both default files are present, issue a warning.
          if (File.file? DEFAULT_LOCATION) && (File.file? OLD_DEFAULT_LOCATION)
            logger.warn "Both #{DEFAULT_LOCATION} and #{OLD_DEFAULT_LOCATION} configuration files exist."
            logger.warn "#{DEFAULT_LOCATION} will be used."
          end

          first = @loadpath.find {|filename| File.file? filename}
        end

        private

        def populate_loadpath

          # Add the current directory for r10k.yaml
          @loadpath << File.join(Dir.getwd, CONFIG_FILE)

          # Add the AIO location for of r10k.yaml
          @loadpath << DEFAULT_LOCATION

          # Add the old default location last.
          @loadpath << OLD_DEFAULT_LOCATION

          @loadpath
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
r10k-1.5.1 lib/r10k/deployment/config/loader.rb