Class: R10K::Settings::Loader

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/r10k/settings/loader.rb

Overview

Look for the r10k configuration file in standard locations.

r10k.yaml is checked for in the following locations:

- $PWD/r10k.yaml
- /etc/puppetlabs/r10k/r10k.yaml
- /etc/r10k.yaml

Defined Under Namespace

Classes: ConfigError

Constant Summary collapse

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

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Constructor Details

#initializeLoader



27
28
29
30
# File 'lib/r10k/settings/loader.rb', line 27

def initialize
  @loadpath = []
  populate_loadpath
end

Instance Attribute Details

#loadpathObject (readonly)

Returns the value of attribute loadpath.



21
22
23
# File 'lib/r10k/settings/loader.rb', line 21

def loadpath
  @loadpath
end

Class Method Details

.search(override = nil) ⇒ Object



15
16
17
# File 'lib/r10k/settings/loader.rb', line 15

def self.search(override = nil)
  new.search(override)
end

Instance Method Details

#read(override = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/r10k/settings/loader.rb', line 59

def read(override = nil)
  path = search(override)

  if path.nil?
    raise ConfigError, "No configuration file given, no config file found in current directory, and no global config present"
  end

  begin
    contents = ::YAML.load_file(path)
  rescue => e
    raise ConfigError, "Couldn't load config file: #{e.message}"
  end

  R10K::Util::SymbolizeKeys.symbolize_keys!(contents, true)
  contents
end

#search(override = nil) ⇒ String?

Find the first valid config file.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/r10k/settings/loader.rb', line 40

def search(override = nil)
  return override if override

  # 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

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

  if path == OLD_DEFAULT_LOCATION
    logger.warn "The r10k configuration file at #{OLD_DEFAULT_LOCATION} is deprecated."
    logger.warn "Please move your r10k configuration to #{DEFAULT_LOCATION}."
  end

  path
end