Class: Puppet::Settings
- Includes:
- Enumerable
- Defined in:
- lib/puppet/settings.rb,
lib/puppet/settings/errors.rb
Overview
The class for handling configuration files.
Defined Under Namespace
Classes: AutosignSetting, BaseSetting, BooleanSetting, ConfigFile, DirectorySetting, DurationSetting, EnumSetting, FileSetting, InterpolationError, ParseError, PathSetting, PrioritySetting, SettingsError, StringSetting, TerminusSetting, ValidationError, ValueTranslator
Constant Summary collapse
- PuppetOptionParser =
local reference for convenience
Puppet::Util::CommandLine::PuppetOptionParser
- REQUIRED_APP_SETTINGS =
These are the settings that every app is required to specify; there are reasonable defaults defined in application.rb.
[:logdir, :confdir, :vardir]
- SETTING_TYPES =
{ :string => StringSetting, :file => FileSetting, :directory => DirectorySetting, :path => PathSetting, :boolean => BooleanSetting, :terminus => TerminusSetting, :duration => DurationSetting, :enum => EnumSetting, :priority => PrioritySetting, :autosign => AutosignSetting, }
Instance Attribute Summary collapse
- #files ⇒ Object writeonly
- #timer ⇒ Object readonly
Class Method Summary collapse
-
.app_defaults_for_run_mode(run_mode) ⇒ Object
This method is intended for puppet internal use only; it is a convenience method that returns reasonable application default settings values for a given run_mode.
-
.clean_opt(opt, val) ⇒ Object
A utility method (public, is used by application.rb and perhaps elsewhere) that munges a command-line option string into the format that Puppet.settings expects.
- .default_certname ⇒ Object
- .default_config_file_name ⇒ Object
- .domain_fact ⇒ Object
- .hostname_fact ⇒ Object
Instance Method Summary collapse
-
#[](param) ⇒ Object
Retrieve a config value.
-
#[]=(param, value) ⇒ Object
Set a config value.
-
#addargs(options) ⇒ Object
Generate the list of valid arguments, in a format that GetoptLong can understand, and add them to the passed option list.
- #app_defaults_initialized? ⇒ Boolean
-
#boolean?(param) ⇒ Boolean
Is our parameter a boolean parameter?.
-
#clear ⇒ Object
Remove all set values, potentially skipping cli values.
- #clearused ⇒ Object
-
#convert(value, environment = nil) ⇒ Object
Do variable interpolation on the value.
-
#define_settings(section, defs) ⇒ Object
Define a group of settings.
-
#description(name) ⇒ Object
Return a value’s description.
- #each ⇒ Object
-
#eachsection ⇒ Object
Iterate over each section name.
-
#flush_cache ⇒ Object
Clear @cache, @used and the Environment.
- #generate_config ⇒ Object
- #generate_manifest ⇒ Object
- #global_defaults_initialized? ⇒ Boolean
-
#handlearg(opt, value = nil) ⇒ Object
Handle a command-line argument.
- #include?(name) ⇒ Boolean
-
#initialize ⇒ Settings
constructor
Create a new collection of config settings.
- #initialize_app_defaults(app_defaults) ⇒ Object
- #initialize_global_settings(args = []) ⇒ Object
-
#metadata(param) ⇒ Object
Return a given object’s file metadata.
-
#mkdir(default) ⇒ Object
Make a directory with the appropriate user, group, and mode.
-
#optparse_addargs(options) ⇒ Object
Generate the list of valid arguments, in a format that OptionParser can understand, and add them to the passed option list.
-
#params(section = nil) ⇒ Object
Return all of the parameters associated with a given section.
-
#persection(section) ⇒ Object
Iterate across all of the objects in a given section.
-
#preferred_run_mode ⇒ Object
The currently configured run mode that is preferred for constructing the application configuration.
-
#preferred_run_mode=(mode) ⇒ Object
private
PRIVATE! This only exists because we need a hook to validate the run mode when it’s being set, and it should never, ever, ever, ever be called from outside of this file.
-
#print_config_options ⇒ Object
Prints the contents of a config file with the available config settings, or it prints a single value of a config setting.
- #print_configs ⇒ Object
- #print_configs? ⇒ Boolean
-
#reparse_config_files ⇒ Object
Reparse our config file, if necessary.
- #reuse ⇒ Object
-
#searchpath(environment = nil) ⇒ Object
The order in which to search for values.
-
#sectionlist ⇒ Object
Get a list of objects per section.
- #service_group_available? ⇒ Boolean
- #service_user_available? ⇒ Boolean
-
#set_by_cli?(param) ⇒ Boolean
Allow later inspection to determine if the setting was set on the command line, or through some other code path.
- #set_value(param, value, type, options = {}) ⇒ Object
-
#setdefaults(section, defs) ⇒ Object
Deprecated; use #define_settings instead.
-
#setting(param) ⇒ Object
Return an object by name.
-
#shortinclude?(short) ⇒ Boolean
check to see if a short name is already defined.
-
#to_catalog(*sections) ⇒ Object
Convert the settings we manage into a catalog full of resources that model those settings.
-
#to_config ⇒ Object
Convert our list of config settings into a configuration file.
-
#to_manifest ⇒ Object
Convert to a parseable manifest.
- #uninterpolated_value(param, environment = nil) ⇒ Object
-
#use(*sections) ⇒ Object
Create the necessary objects to use a section.
- #valid?(param) ⇒ Boolean
-
#value(param, environment = nil, bypass_interpolation = false) ⇒ Object
Find the correct value using our search path.
Constructor Details
#initialize ⇒ Settings
Create a new collection of config settings.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/puppet/settings.rb', line 71 def initialize @config = {} @shortnames = {} @created = [] @searchpath = nil # Keep track of set values. @values = Hash.new { |hash, key| hash[key] = {} } # Hold parsed metadata until run_mode is known = {} # And keep a per-environment cache @cache = Hash.new { |hash, key| hash[key] = {} } # The list of sections we've used. @used = [] @hooks_to_call_on_application_initialization = [] @translate = Puppet::Settings::ValueTranslator.new @config_file_parser = Puppet::Settings::ConfigFile.new(@translate) end |
Instance Attribute Details
#files=(value) ⇒ Object
28 29 30 |
# File 'lib/puppet/settings.rb', line 28 def files=(value) @files = value end |
Class Method Details
.app_defaults_for_run_mode(run_mode) ⇒ Object
This method is intended for puppet internal use only; it is a convenience method that returns reasonable application default settings values for a given run_mode.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/puppet/settings.rb', line 36 def self.app_defaults_for_run_mode(run_mode) { :name => run_mode.to_s, :run_mode => run_mode.name, :confdir => run_mode.conf_dir, :vardir => run_mode.var_dir, :rundir => run_mode.run_dir, :logdir => run_mode.log_dir, } end |
.clean_opt(opt, val) ⇒ Object
A utility method (public, is used by application.rb and perhaps elsewhere) that munges a command-line option string into the format that Puppet.settings expects. (This mostly has to deal with handling the “no-” prefix on flag/boolean options).
256 257 258 259 260 261 262 263 264 |
# File 'lib/puppet/settings.rb', line 256 def self.clean_opt(opt, val) # rewrite --[no-]option to --no-option if that's what was given if opt =~ /\[no-\]/ and !val opt = opt.gsub(/\[no-\]/,'no-') end # otherwise remove the [no-] prefix to not confuse everybody opt = opt.gsub(/\[no-\]/, '') [opt, val] end |
.default_certname ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppet/settings.rb', line 47 def self.default_certname() hostname = hostname_fact domain = domain_fact if domain and domain != "" fqdn = [hostname, domain].join(".") else fqdn = hostname end fqdn.to_s.gsub(/\.$/, '') end |
.default_config_file_name ⇒ Object
66 67 68 |
# File 'lib/puppet/settings.rb', line 66 def self.default_config_file_name "puppet.conf" end |
.domain_fact ⇒ Object
62 63 64 |
# File 'lib/puppet/settings.rb', line 62 def self.domain_fact() Facter["domain"].value end |
.hostname_fact ⇒ Object
58 59 60 |
# File 'lib/puppet/settings.rb', line 58 def self.hostname_fact() Facter["hostname"].value end |
Instance Method Details
#[](param) ⇒ Object
Retrieve a config value
103 104 105 |
# File 'lib/puppet/settings.rb', line 103 def [](param) value(param) end |
#[]=(param, value) ⇒ Object
Set a config value. This doesn’t set the defaults, it sets the value itself.
108 109 110 |
# File 'lib/puppet/settings.rb', line 108 def []=(param, value) set_value(param, value, :memory) end |
#addargs(options) ⇒ Object
Generate the list of valid arguments, in a format that GetoptLong can understand, and add them to the passed option list.
114 115 116 117 118 119 120 121 |
# File 'lib/puppet/settings.rb', line 114 def addargs() # Add all of the config parameters as valid options. self.each { |name, setting| setting.getopt_args.each { |args| << args } } end |
#app_defaults_initialized? ⇒ Boolean
267 268 269 |
# File 'lib/puppet/settings.rb', line 267 def app_defaults_initialized? @app_defaults_initialized end |
#boolean?(param) ⇒ Boolean
Is our parameter a boolean parameter?
135 136 137 138 |
# File 'lib/puppet/settings.rb', line 135 def boolean?(param) param = param.to_sym @config.include?(param) and @config[param].kind_of?(BooleanSetting) end |
#clear ⇒ Object
Remove all set values, potentially skipping cli values.
141 142 143 |
# File 'lib/puppet/settings.rb', line 141 def clear unsafe_clear end |
#clearused ⇒ Object
190 191 192 193 |
# File 'lib/puppet/settings.rb', line 190 def clearused @cache.clear @used = [] end |
#convert(value, environment = nil) ⇒ Object
Do variable interpolation on the value.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/puppet/settings.rb', line 303 def convert(value, environment = nil) return nil if value.nil? return value unless value.is_a? String newval = value.gsub(/\$(\w+)|\$\{(\w+)\}/) do |value| varname = $2 || $1 if varname == "environment" and environment environment elsif varname == "run_mode" preferred_run_mode elsif pval = self.value(varname, environment) pval else raise InterpolationError, "Could not find value for #{value}" end end newval end |
#define_settings(section, defs) ⇒ Object
Define a group of settings.
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 |
# File 'lib/puppet/settings.rb', line 837 def define_settings(section, defs) section = section.to_sym call = [] defs.each do |name, hash| raise ArgumentError, "setting definition for '#{name}' is not a hash!" unless hash.is_a? Hash name = name.to_sym hash[:name] = name hash[:section] = section raise ArgumentError, "Parameter #{name} is already defined" if @config.include?(name) tryconfig = newsetting(hash) if short = tryconfig.short if other = @shortnames[short] raise ArgumentError, "Parameter #{other.name} is already using short name '#{short}'" end @shortnames[short] = tryconfig end @config[name] = tryconfig # Collect the settings that need to have their hooks called immediately. # We have to collect them so that we can be sure we're fully initialized before # the hook is called. if tryconfig.call_hook_on_define? call << tryconfig elsif tryconfig.call_hook_on_initialize? @hooks_to_call_on_application_initialization << tryconfig end end call.each { |setting| setting.handle(self.value(setting.name)) } end |
#description(name) ⇒ Object
Return a value’s description.
323 324 325 326 327 328 329 |
# File 'lib/puppet/settings.rb', line 323 def description(name) if obj = @config[name.to_sym] obj.desc else nil end end |
#each ⇒ Object
331 332 333 334 335 |
# File 'lib/puppet/settings.rb', line 331 def each @config.each { |name, object| yield name, object } end |
#eachsection ⇒ Object
Iterate over each section name.
338 339 340 341 342 343 344 345 346 347 |
# File 'lib/puppet/settings.rb', line 338 def eachsection yielded = [] @config.each do |name, object| section = object.section unless yielded.include? section yield section yielded << section end end end |
#flush_cache ⇒ Object
Clear @cache, @used and the Environment.
Whenever an object is returned by Settings, a copy is stored in @cache. As long as Setting attributes that determine the content of returned objects remain unchanged, Settings can keep returning objects from @cache without re-fetching or re-generating them.
Whenever a Settings attribute changes, such as @values or @preferred_run_mode, this method must be called to clear out the caches so that updated objects will be returned.
174 175 176 |
# File 'lib/puppet/settings.rb', line 174 def flush_cache unsafe_flush_cache end |
#generate_config ⇒ Object
429 430 431 432 |
# File 'lib/puppet/settings.rb', line 429 def generate_config puts to_config true end |
#generate_manifest ⇒ Object
434 435 436 437 |
# File 'lib/puppet/settings.rb', line 434 def generate_manifest puts to_manifest true end |
#global_defaults_initialized? ⇒ Boolean
195 196 197 |
# File 'lib/puppet/settings.rb', line 195 def global_defaults_initialized?() @global_defaults_initialized end |
#handlearg(opt, value = nil) ⇒ Object
Handle a command-line argument.
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/puppet/settings.rb', line 356 def handlearg(opt, value = nil) @cache.clear if value.is_a?(FalseClass) value = "false" elsif value.is_a?(TrueClass) value = "true" end value &&= @translate[value] str = opt.sub(/^--/,'') bool = true newstr = str.sub(/^no-/, '') if newstr != str str = newstr bool = false end str = str.intern if @config[str].is_a?(Puppet::Settings::BooleanSetting) if value == "" or value.nil? value = bool end end set_value(str, value, :cli) end |
#include?(name) ⇒ Boolean
385 386 387 388 |
# File 'lib/puppet/settings.rb', line 385 def include?(name) name = name.intern if name.is_a? String @config.include?(name) end |
#initialize_app_defaults(app_defaults) ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/puppet/settings.rb', line 271 def initialize_app_defaults(app_defaults) REQUIRED_APP_SETTINGS.each do |key| raise SettingsError, "missing required app default setting '#{key}'" unless app_defaults.has_key?(key) end app_defaults.each do |key, value| if key == :run_mode self.preferred_run_mode = value else set_value(key, value, :application_defaults) end end call_hooks_deferred_to_application_initialization @app_defaults_initialized = true end |
#initialize_global_settings(args = []) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/puppet/settings.rb', line 199 def initialize_global_settings(args = []) raise Puppet::DevError, "Attempting to initialize global default settings more than once!" if global_defaults_initialized? # The first two phases of the lifecycle of a puppet application are: # 1) Parse the command line options and handle any of them that are # registered, defined "global" puppet settings (mostly from defaults.rb). # 2) Parse the puppet config file(s). (args) parse_config_files @global_defaults_initialized = true end |
#metadata(param) ⇒ Object
Return a given object’s file metadata.
450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/puppet/settings.rb', line 450 def (param) if obj = @config[param.to_sym] and obj.is_a?(FileSetting) return [:owner, :group, :mode].inject({}) do |, p| if v = obj.send(p) [p] = v end end else nil end end |
#mkdir(default) ⇒ Object
Make a directory with the appropriate user, group, and mode
464 465 466 467 468 469 470 471 |
# File 'lib/puppet/settings.rb', line 464 def mkdir(default) obj = get_config_file_default(default) Puppet::Util::SUIDManager.asuser(obj.owner, obj.group) do mode = obj.mode || 0750 Dir.mkdir(obj.value, mode) end end |
#optparse_addargs(options) ⇒ Object
Generate the list of valid arguments, in a format that OptionParser can understand, and add them to the passed option list.
125 126 127 128 129 130 131 132 |
# File 'lib/puppet/settings.rb', line 125 def optparse_addargs() # Add all of the config parameters as valid options. self.each { |name, setting| << setting.optparse_args } end |
#params(section = nil) ⇒ Object
Return all of the parameters associated with a given section.
495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'lib/puppet/settings.rb', line 495 def params(section = nil) if section section = section.intern if section.is_a? String @config.find_all { |name, obj| obj.section == section }.collect { |name, obj| name } else @config.keys end end |
#persection(section) ⇒ Object
Iterate across all of the objects in a given section.
675 676 677 678 679 680 681 682 |
# File 'lib/puppet/settings.rb', line 675 def persection(section) section = section.to_sym self.each { |name, obj| if obj.section == section yield obj end } end |
#preferred_run_mode ⇒ Object
The currently configured run mode that is preferred for constructing the application configuration.
474 475 476 |
# File 'lib/puppet/settings.rb', line 474 def preferred_run_mode @preferred_run_mode_name || :user end |
#preferred_run_mode=(mode) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
PRIVATE! This only exists because we need a hook to validate the run mode when it’s being set, and
it should never, ever, ever, ever be called from outside of this file.
This method is also called when –run_mode MODE is used on the command line to set the default
484 485 486 487 488 489 490 491 492 |
# File 'lib/puppet/settings.rb', line 484 def preferred_run_mode=(mode) mode = mode.to_s.downcase.intern raise ValidationError, "Invalid run mode '#{mode}'" unless [:master, :agent, :user].include?(mode) @preferred_run_mode_name = mode # Changing the run mode has far-reaching consequences. Flush any cached # settings so they will be re-generated. flush_cache mode end |
#print_config_options ⇒ Object
Prints the contents of a config file with the available config settings, or it prints a single value of a config setting.
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/puppet/settings.rb', line 398 def env = value(:environment) val = value(:configprint) if val == "all" hash = {} each do |name, obj| val = value(name,env) val = val.inspect if val == "" hash[name] = val end hash.sort { |a,b| a[0].to_s <=> b[0].to_s }.each do |name, val| puts "#{name} = #{val}" end else val.split(/\s*,\s*/).sort.each do |v| if include?(v) #if there is only one value, just print it for back compatibility if v == val puts value(val,env) break end puts "#{v} = #{value(v,env)}" else puts "invalid parameter: #{v}" return false end end end true end |
#print_configs ⇒ Object
439 440 441 442 443 |
# File 'lib/puppet/settings.rb', line 439 def print_configs return if value(:configprint) != "" return generate_config if value(:genconfig) generate_manifest if value(:genmanifest) end |
#print_configs? ⇒ Boolean
445 446 447 |
# File 'lib/puppet/settings.rb', line 445 def print_configs? (value(:configprint) != "" || value(:genconfig) || value(:genmanifest)) && true end |
#reparse_config_files ⇒ Object
Reparse our config file, if necessary.
685 686 687 688 689 690 691 692 693 |
# File 'lib/puppet/settings.rb', line 685 def reparse_config_files if files if filename = any_files_changed? Puppet.notice "Config file #{filename} changed; triggering re-parse of all config files." parse_config_files reuse end end end |
#reuse ⇒ Object
718 719 720 721 722 723 |
# File 'lib/puppet/settings.rb', line 718 def reuse return unless defined?(@used) new = @used @used = [] self.use(*new) end |
#searchpath(environment = nil) ⇒ Object
The order in which to search for values.
726 727 728 729 730 731 732 |
# File 'lib/puppet/settings.rb', line 726 def searchpath(environment = nil) if environment [:cli, :memory, environment, :run_mode, :main, :application_defaults] else [:cli, :memory, :run_mode, :main, :application_defaults] end end |
#sectionlist ⇒ Object
Get a list of objects per section
735 736 737 738 739 740 741 742 743 744 745 |
# File 'lib/puppet/settings.rb', line 735 def sectionlist sectionlist = [] self.each { |name, obj| section = obj.section || "puppet" sections[section] ||= [] sectionlist << section unless sectionlist.include?(section) sections[section] << obj } return sectionlist, sections end |
#service_group_available? ⇒ Boolean
759 760 761 762 763 764 765 766 767 768 769 |
# File 'lib/puppet/settings.rb', line 759 def service_group_available? return @service_group_available if defined?(@service_group_available) if self[:group] group = Puppet::Type.type(:group).new :name => self[:group], :audit => :ensure @service_group_available = group.exists? else @service_group_available = false end end |
#service_user_available? ⇒ Boolean
747 748 749 750 751 752 753 754 755 756 757 |
# File 'lib/puppet/settings.rb', line 747 def service_user_available? return @service_user_available if defined?(@service_user_available) if self[:user] user = Puppet::Type.type(:user).new :name => self[:user], :audit => :ensure @service_user_available = user.exists? else @service_user_available = false end end |
#set_by_cli?(param) ⇒ Boolean
Allow later inspection to determine if the setting was set on the command line, or through some other code path. Used for the dns_alt_names option during cert generate. –daniel 2011-10-18
774 775 776 777 |
# File 'lib/puppet/settings.rb', line 774 def set_by_cli?(param) param = param.to_sym !@values[:cli][param].nil? end |
#set_value(param, value, type, options = {}) ⇒ Object
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 |
# File 'lib/puppet/settings.rb', line 779 def set_value(param, value, type, = {}) param = param.to_sym if !(setting = @config[param]) if [:ignore_bad_settings] return else raise ArgumentError, "Attempt to assign a value to unknown configuration parameter #{param.inspect}" end end setting.handle(value) if setting.has_hook? and not [:dont_trigger_handles] @values[type][param] = value unsafe_flush_cache value end |
#setdefaults(section, defs) ⇒ Object
Deprecated; use #define_settings instead
803 804 805 806 |
# File 'lib/puppet/settings.rb', line 803 def setdefaults(section, defs) Puppet.deprecation_warning("'setdefaults' is deprecated and will be removed; please call 'define_settings' instead") define_settings(section, defs) end |
#setting(param) ⇒ Object
Return an object by name.
98 99 100 |
# File 'lib/puppet/settings.rb', line 98 def setting(name) @config[name] end |
#shortinclude?(short) ⇒ Boolean
check to see if a short name is already defined
391 392 393 394 |
# File 'lib/puppet/settings.rb', line 391 def shortinclude?(short) short = short.intern if name.is_a? String @shortnames.include?(short) end |
#to_catalog(*sections) ⇒ Object
Convert the settings we manage into a catalog full of resources that model those settings.
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
# File 'lib/puppet/settings.rb', line 870 def to_catalog(*sections) sections = nil if sections.empty? catalog = Puppet::Resource::Catalog.new("Settings") @config.keys.find_all { |key| @config[key].is_a?(FileSetting) }.each do |key| file = @config[key] next unless (sections.nil? or sections.include?(file.section)) next unless resource = file.to_resource next if catalog.resource(resource.ref) Puppet.debug("Using settings: adding file resource '#{key}': '#{resource.inspect}'") catalog.add_resource(resource) end add_user_resources(catalog, sections) catalog end |
#to_config ⇒ Object
Convert our list of config settings into a configuration file.
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 |
# File 'lib/puppet/settings.rb', line 892 def to_config str = %{The configuration file for #{Puppet.run_mode.name}. Note that this file is likely to have unused configuration parameters in it; any parameter that's valid anywhere in Puppet can be in any config file, even if it's not used. Every section can specify three special parameters: owner, group, and mode. These parameters affect the required permissions of any files specified after their specification. Puppet will sometimes use these parameters to check its own configured state, so they can be used to make Puppet a bit more self-managing. The file format supports octothorpe-commented lines, but not partial-line comments. Generated on #{Time.now}. }.gsub(/^/, "# ") # Add a section heading that matches our name. str += "[#{preferred_run_mode}]\n" eachsection do |section| persection(section) do |obj| str += obj.to_config + "\n" unless obj.name == :genconfig end end return str end |
#to_manifest ⇒ Object
Convert to a parseable manifest
920 921 922 923 924 925 |
# File 'lib/puppet/settings.rb', line 920 def to_manifest catalog = to_catalog catalog.resource_refs.collect do |ref| catalog.resource(ref).to_manifest end.join("\n\n") end |
#uninterpolated_value(param, environment = nil) ⇒ Object
959 960 961 962 963 964 965 966 967 968 969 970 |
# File 'lib/puppet/settings.rb', line 959 def uninterpolated_value(param, environment = nil) param = param.to_sym environment &&= environment.to_sym # See if we can find it within our searchable list of values val = find_value(environment, param) # If we didn't get a value, use the default val = @config[param].default if val.nil? val end |
#use(*sections) ⇒ Object
Create the necessary objects to use a section. This is idempotent; you can ‘use’ a section as many times as you want.
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 |
# File 'lib/puppet/settings.rb', line 929 def use(*sections) sections = sections.collect { |s| s.to_sym } sections = sections.reject { |s| @used.include?(s) } return if sections.empty? begin catalog = to_catalog(*sections).to_ral rescue => detail Puppet.log_and_raise(detail, "Could not create resources for managing Puppet's files and directories in sections #{sections.inspect}: #{detail}") end catalog.host_config = false catalog.apply do |transaction| if transaction.any_failed? report = transaction.report failures = report.logs.find_all { |log| log.level == :err } raise "Got #{failures.length} failure(s) while initializing: #{failures.collect { |l| l.to_s }.join("; ")}" end end sections.each { |s| @used << s } @used.uniq! end |
#valid?(param) ⇒ Boolean
954 955 956 957 |
# File 'lib/puppet/settings.rb', line 954 def valid?(param) param = param.to_sym @config.has_key?(param) end |
#value(param, environment = nil, bypass_interpolation = false) ⇒ Object
Find the correct value using our search path.
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 |
# File 'lib/puppet/settings.rb', line 991 def value(param, environment = nil, bypass_interpolation = false) param = param.to_sym environment &&= environment.to_sym setting = @config[param] # Short circuit to nil for undefined parameters. return nil unless @config.include?(param) # Yay, recursion. #self.reparse unless [:config, :filetimeout].include?(param) # Check the cache first. It needs to be a per-environment # cache so that we don't spread values from one env # to another. if @cache[environment||"none"].has_key?(param) return @cache[environment||"none"][param] end val = uninterpolated_value(param, environment) return val if bypass_interpolation if param == :code # if we interpolate code, all hell breaks loose. return val end # Convert it if necessary begin val = convert(val, environment) rescue InterpolationError => err # This happens because we don't have access to the param name when the # exception is originally raised, but we want it in the message raise InterpolationError, "Error converting value for param '#{param}': #{err}", err.backtrace end val = setting.munge(val) if setting.respond_to?(:munge) # And cache it @cache[environment||"none"][param] = val val end |