class Puppet::Settings::EnvironmentConf
Configuration settings for a single directory Environment. @api private
Constants
- ENVIRONMENT_CONF_ONLY_SETTINGS
- VALID_SETTINGS
Attributes
Public Class Methods
Given a path to a directory environment, attempts to load and parse an environment.conf in ini format, and return an EnvironmentConf
instance.
An environment.conf is optional, so if the file itself is missing, or empty, an EnvironmentConf
with default values will be returned.
@note logs warnings if the environment.conf contains any ini sections, or has settings other than the three handled for directory environments (:manifest, :modulepath, :config_version)
@param path_to_env
[String] path to the directory environment @param global_module_path [Array<String>] the installation's base modulepath
setting, appended to default environment modulepaths
@return [EnvironmentConf] the parsed EnvironmentConf
object
# File lib/puppet/settings/environment_conf.rb 22 def self.load_from(path_to_env, global_module_path) 23 path_to_env = File.expand_path(path_to_env) 24 conf_file = File.join(path_to_env, 'environment.conf') 25 26 begin 27 config = Puppet.settings.parse_file(conf_file) 28 validate(conf_file, config) 29 section = config.sections[:main] 30 rescue Errno::ENOENT 31 # environment.conf is an optional file 32 Puppet.debug { "Path to #{path_to_env} does not exist, using default environment.conf" } 33 end 34 35 new(path_to_env, section, global_module_path) 36 end
Create through EnvironmentConf.load_from()
# File lib/puppet/settings/environment_conf.rb 49 def initialize(path_to_env, section, global_module_path) 50 @path_to_env = path_to_env 51 @section = section 52 @global_module_path = global_module_path 53 end
Provides a configuration object tied directly to the passed environment. Configuration values are exactly those returned by the environment object, without interpolation. This is a special case for the default configured environment returned by the Puppet::Environments::StaticPrivate
loader.
# File lib/puppet/settings/environment_conf.rb 42 def self.static_for(environment, environment_timeout = 0, static_catalogs = false, rich_data = false) 43 Static.new(environment, environment_timeout, static_catalogs, nil, rich_data) 44 end
Private Class Methods
# File lib/puppet/settings/environment_conf.rb 134 def self.validate(path_to_conf_file, config) 135 valid = true 136 section_keys = config.sections.keys 137 main = config.sections[:main] 138 if section_keys.size > 1 139 # warn once per config file path 140 Puppet.warn_once( 141 :invalid_settings_section, "EnvironmentConf-section:#{path_to_conf_file}", 142 _("Invalid sections in environment.conf at '%{path_to_conf_file}'. Environment conf may not have sections. The following sections are being ignored: '%{sections}'") % { 143 path_to_conf_file: path_to_conf_file, 144 sections: (section_keys - [:main]).join(',') 145 }) 146 valid = false 147 end 148 149 extraneous_settings = main.settings.map(&:name) - VALID_SETTINGS 150 if !extraneous_settings.empty? 151 # warn once per config file path 152 Puppet.warn_once( 153 :invalid_settings, "EnvironmentConf-settings:#{path_to_conf_file}", 154 _("Invalid settings in environment.conf at '%{path_to_conf_file}'. The following unknown setting(s) are being ignored: %{ignored_settings}") % { 155 path_to_conf_file: path_to_conf_file, 156 ignored_settings: extraneous_settings.join(', ') 157 }) 158 valid = false 159 end 160 161 return valid 162 end
Public Instance Methods
# File lib/puppet/settings/environment_conf.rb 121 def config_version 122 get_setting(:config_version) do |config_version| 123 absolute(config_version) 124 end 125 end
# File lib/puppet/settings/environment_conf.rb 93 def environment_data_provider 94 get_setting(:environment_data_provider, Puppet.settings.value(:environment_data_provider)) do |value| 95 value 96 end 97 end
# File lib/puppet/settings/environment_conf.rb 83 def environment_timeout 84 # gen env specific config or use the default value 85 get_setting(:environment_timeout, Puppet.settings.value(:environment_timeout)) do |ttl| 86 # munges the string form statically without really needed the settings system, only 87 # its ability to munge "4s, 3m, 5d, and 'unlimited' into seconds - if already munged into 88 # numeric form, the TTLSetting handles that. 89 Puppet::Settings::TTLSetting.munge(ttl, 'environment_timeout') 90 end 91 end
# File lib/puppet/settings/environment_conf.rb 55 def manifest 56 puppet_conf_manifest = Pathname.new(Puppet.settings.value(:default_manifest)) 57 disable_per_environment_manifest = Puppet.settings.value(:disable_per_environment_manifest) 58 59 fallback_manifest_directory = 60 if puppet_conf_manifest.absolute? 61 puppet_conf_manifest.to_s 62 else 63 File.join(@path_to_env, puppet_conf_manifest.to_s) 64 end 65 66 if disable_per_environment_manifest 67 environment_conf_manifest = absolute(raw_setting(:manifest)) 68 if environment_conf_manifest && fallback_manifest_directory != environment_conf_manifest 69 #TRANSLATORS 'disable_per_environment_manifest' is a setting and 'environment.conf' is a file name and should not be translated 70 message = _("The 'disable_per_environment_manifest' setting is true, but the environment located at %{path_to_env} has a manifest setting in its environment.conf of '%{environment_conf}' which does not match the default_manifest setting '%{puppet_conf}'.") % 71 { path_to_env: @path_to_env, environment_conf: environment_conf_manifest, puppet_conf: puppet_conf_manifest } 72 message += ' ' + _("If this environment is expecting to find modules in '%{environment_conf}', they will not be available!") % { environment_conf: environment_conf_manifest } 73 Puppet.err(message) 74 end 75 fallback_manifest_directory.to_s 76 else 77 get_setting(:manifest, fallback_manifest_directory) do |manifest| 78 absolute(manifest) 79 end 80 end 81 end
# File lib/puppet/settings/environment_conf.rb 99 def modulepath 100 default_modulepath = [File.join(@path_to_env, "modules")] + @global_module_path 101 get_setting(:modulepath, default_modulepath) do |modulepath| 102 path = modulepath.kind_of?(String) ? 103 modulepath.split(File::PATH_SEPARATOR) : 104 modulepath 105 path.map { |p| expand_glob(absolute(p)) }.flatten.join(File::PATH_SEPARATOR) 106 end 107 end
# File lib/puppet/settings/environment_conf.rb 127 def raw_setting(setting_name) 128 setting = section.setting(setting_name) if section 129 setting.value if setting 130 end
# File lib/puppet/settings/environment_conf.rb 109 def rich_data 110 get_setting(:rich_data, Puppet.settings.value(:rich_data)) do |value| 111 value 112 end 113 end
# File lib/puppet/settings/environment_conf.rb 115 def static_catalogs 116 get_setting(:static_catalogs, Puppet.settings.value(:static_catalogs)) do |value| 117 value 118 end 119 end
Private Instance Methods
# File lib/puppet/settings/environment_conf.rb 180 def absolute(path) 181 return nil if path.nil? 182 if path =~ /^\$/ 183 # Path begins with $something interpolatable 184 path 185 else 186 Puppet::FileSystem.expand_path(path, @path_to_env) 187 end 188 end
# File lib/puppet/settings/environment_conf.rb 171 def expand_glob(path) 172 return nil if path.nil? 173 if path =~ /[*?\[\{]/ 174 Dir.glob(path) 175 else 176 path 177 end 178 end
# File lib/puppet/settings/environment_conf.rb 165 def get_setting(setting_name, default = nil) 166 value = raw_setting(setting_name) 167 value = default if value.nil? 168 yield value 169 end