Sha256: 722d12a3fb7112a2148912e0993656f4f592b9d4acf3e7ad990bdd6900d1dfe8

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

#
# Simple configuration loader from yaml
#
require 'yaml'

module Environmate

  def self.load_configuration(environment, config_file = nil)
    config_file ||= config_location
    if config_file.nil?
      raise "No configuration file was provided"
    end
    unless File.exists?(config_file)
      raise "Configuration file #{config_file} does not exist"
    end
    config = YAML.load_file(config_file)
    if config[environment].nil?
      raise "No configuration for environment '#{environment}' found in file #{config_file}"
    end
    @configuration = config_defaults.merge(config[environment])
  end

  def self.configuration
    @configuration
  end

  private

  def self.config_defaults
    {
      'logfile'                     => '/var/log/enviromate.log',
      'loglevel'                    => 'WARN',
      'environment_path'            => '/etc/puppetlabs/code/environments',
      'lockfile_path'               => '/var/run/lock/environmate',
      'lockfile_options'            => {
        'timeout' => 300
      },
      'master_repository'           => 'http://gitlab.example.com/puppet/control',
      'master_branch'               => 'origin/master',
      'master_path'                 => '/etc/puppetlabs/code/environmate',
      'dynamic_environments_prefix' => 'env/',
      'static_environments'         => {},
      'install_modules_command'     => 'librarian-puppet install --destructive',
      'server_settings'             => {},
    }
  end

  def self.config_location
    [
      '/etc/environmate.yml',
      File.expand_path('~/.environmate.yml'),
    ].find{|c| File.exist?(c)}
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
environmate-0.1.1 lib/environmate/configuration.rb