Module: Puppet
- Extended by:
- Util, Util::Logging
- Defined in:
- lib/puppet/version.rb,
lib/puppet/pops.rb,
lib/puppet/type.rb,
lib/puppet/util.rb,
lib/puppet/error.rb,
lib/puppet/vendor.rb,
lib/puppet/loaders.rb,
lib/puppet/defaults.rb,
lib/puppet/type/zfs.rb,
lib/puppet/type/exec.rb,
lib/puppet/type/host.rb,
lib/puppet/type/user.rb,
lib/puppet/type/group.rb,
lib/puppet/type/mount.rb,
lib/puppet/type/zpool.rb,
lib/puppet/application.rb,
lib/puppet/module_tool.rb,
lib/puppet/type/notify.rb,
lib/puppet/type/router.rb,
lib/puppet/type/sshkey.rb,
lib/puppet/type/package.rb,
lib/puppet/type/service.rb,
lib/puppet/generate/type.rb,
lib/puppet/property/list.rb,
lib/puppet/type/maillist.rb,
lib/puppet/type/schedule.rb,
lib/puppet/util/classgen.rb,
lib/puppet/util/platform.rb,
lib/puppet/util/run_mode.rb,
lib/puppet/pops/model/ast.rb,
lib/puppet/type/file/mode.rb,
lib/puppet/type/file/type.rb,
lib/puppet/type/mailalias.rb,
lib/puppet/util/execution.rb,
lib/puppet/resource/status.rb,
lib/puppet/type/file/ctime.rb,
lib/puppet/type/file/group.rb,
lib/puppet/type/file/mtime.rb,
lib/puppet/type/file/owner.rb,
lib/puppet/type/filebucket.rb,
lib/puppet/type/selboolean.rb,
lib/puppet/type/file/ensure.rb,
lib/puppet/type/file/source.rb,
lib/puppet/type/file/target.rb,
lib/puppet/network/authstore.rb,
lib/puppet/property/keyvalue.rb,
lib/puppet/ssl/configuration.rb,
lib/puppet/type/file/content.rb,
lib/puppet/util/command_line.rb,
lib/puppet/network/authconfig.rb,
lib/puppet/application_support.rb,
lib/puppet/pops/parser/eparser.rb,
lib/puppet/pops/parser/eparser.rb,
lib/puppet/type/file/data_sync.rb,
lib/puppet/type/file/selcontext.rb,
lib/puppet/parser/parser_factory.rb,
lib/puppet/property/ordered_list.rb,
lib/puppet/util/windows/eventlog.rb,
lib/puppet/type/ssh_authorized_key.rb,
lib/puppet/util/constant_inflector.rb,
lib/puppet/util/symbolic_file_mode.rb,
lib/puppet/parser/e4_parser_adapter.rb,
lib/puppet/type/file/checksum_value.rb,
lib/puppet/generate/models/type/type.rb,
lib/puppet/util/command_line/trollop.rb,
lib/puppet/generate/models/type/property.rb,
lib/puppet/module_tool/install_directory.rb,
lib/puppet/ssl/certificate_authority/interface.rb,
lib/puppet/util/command_line/puppet_option_parser.rb,
lib/puppet.rb
Overview
The main Puppet class. Everything is contained here.
Defined Under Namespace
Modules: ApplicationSupport, Coercion, CompilableResourceType, Confiner, DataSync, Environments, Etc, ExternalFileError, FileBucket, FileBucketFile, FileSystem, Functions, Generate, GettextConfig, Graph, Indirector, InfoService, MetaType, ModuleTool, Network, Parser, Plugins, Pops, SSL, Scheduler, SyntaxCheckers, Test, Util Classes: Agent, AlreadyImportedError, Application, AuthStoreError, AuthorizationError, Bindings, ConfigurationError, Configurer, Confine, ConfineCollection, ConstantAlreadyDefined, Context, Daemon, DataBinding, DevError, Error, ExecutionFailure, FileServing, Forge, ImportError, Interface, LexError, LockError, MissingCommand, Module, Node, Parameter, ParseError, ParseErrorWithIssue, PreformattedError, Property, Provider, Relationship, Reports, Resource, ResourceError, SELFileContext, Settings, Status, SubclassAlreadyDefined, Transaction, Type, Vendor
Constant Summary collapse
- PUPPETVERSION =
'5.3.1'
- AS_DURATION =
NOTE: For information about the available values for the “:type” property of settings,
see the docs for Settings.define_settings
%q{This setting can be a time interval in seconds (30 or 30s), minutes (30m), hours (6h), days (2d), or years (5y).}
- Log =
This is for backward compatibility from when we changed the constant to Puppet::Util::Log because the reports include the constant name. It was considered for removal but left in due to risk of breakage (PUP-7502).
Puppet::Util::Log
- ResourceType =
self
- Face =
Puppet::Interface
- OLDEST_RECOMMENDED_RUBY_VERSION =
'2.1.0'
- @@settings =
the hash that determines how our system behaves
Puppet::Settings.new
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE
Constants included from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Constants included from Util::SymbolicFileMode
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Constants included from Util::Logging
Util::Logging::FILE_AND_LINE, Util::Logging::FILE_NO_LINE, Util::Logging::MM, Util::Logging::NO_FILE_LINE, Util::Logging::SUPPRESS_FILE_LINE
Class Attribute Summary collapse
- .features ⇒ Object readonly
Class Method Summary collapse
-
.[](param) ⇒ Object
Get the value for a setting.
-
.[]=(param, value) ⇒ Object
setting access and stuff.
-
.base_context(settings) ⇒ Object
private
The bindings used for initialization of puppet.
-
.bootstrap_context ⇒ Object
private
A simple set of bindings that is just enough to limp along to initialization where the Puppet.base_context bindings are put in place.
- .clear ⇒ Object
- .debug=(value) ⇒ Object
- .default_diffargs ⇒ Object
-
.define_settings(section, hash) ⇒ Object
Store a new default value.
- .ignore(name) ⇒ Object private
-
.initialize_facts ⇒ Object
Initialize puppet’s core facts.
-
.initialize_settings(args = []) ⇒ void
Initialize puppet’s settings.
-
.lookup(name, &block) ⇒ Object
private
Lookup a binding by name or return a default value provided by a passed block (if given).
- .mark_context(name) ⇒ Object private
-
.minor_version ⇒ String
Containing the puppet version to minor specificity, e.g.
-
.newtype(name, options = {}, &block) ⇒ Object
Create a new type.
- .override(bindings, description = "") { ... } ⇒ Object private
-
.pop_context ⇒ Object
private
Return to the previous context.
- .push_context(overrides, description = "") ⇒ Object private
- .restore(name) ⇒ Object private
- .rollback_context(name) ⇒ Object private
- .run_mode ⇒ Object
-
.settings ⇒ Object
Note: It’s important that these accessors (‘self.settings`, `self.[]`) are defined before we try to load any “features” (which happens a few lines below), because the implementation of the features loading may examine the values of settings.
-
.version ⇒ String
version is a public API method intended to always provide a fast and lightweight way to determine the version of Puppet.
- .version=(version) ⇒ Object
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Methods included from Util::Logging
clear_deprecation_warnings, debug, deprecation_warning, format_exception, get_deprecation_offender, log_and_raise, log_deprecations_to_file, log_exception, puppet_deprecation_warning, send_log, setup_facter_logging!, warn_once
Class Attribute Details
Class Method Details
.[](param) ⇒ Object
Get the value for a setting
72 73 74 75 76 77 78 |
# File 'lib/puppet.rb', line 72 def self.[](param) if param == :debug return Puppet::Util::Log.level == :debug else return @@settings[param] end end |
.[]=(param, value) ⇒ Object
setting access and stuff
98 99 100 |
# File 'lib/puppet.rb', line 98 def self.[]=(param,value) @@settings[param] = value end |
.base_context(settings) ⇒ 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.
The bindings used for initialization of puppet
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/puppet.rb', line 195 def self.base_context(settings) environmentpath = settings[:environmentpath] basemodulepath = Puppet::Node::Environment.split_path(settings[:basemodulepath]) if environmentpath.nil? || environmentpath.empty? raise(Puppet::Error, _("The environmentpath setting cannot be empty or nil.")) else loaders = Puppet::Environments::Directories.from_path(environmentpath, basemodulepath) # in case the configured environment (used for the default sometimes) # doesn't exist default_environment = Puppet[:environment].to_sym if default_environment == :production modulepath = settings[:modulepath] modulepath = (modulepath.nil? || '' == modulepath) ? basemodulepath : Puppet::Node::Environment.split_path(modulepath) loaders << Puppet::Environments::StaticPrivate.new( Puppet::Node::Environment.create(default_environment, modulepath, Puppet::Node::Environment::NO_MANIFEST)) end end { :environments => Puppet::Environments::Cached.new(Puppet::Environments::Combined.new(*loaders)), :http_pool => proc { require 'puppet/network/http' Puppet::Network::HTTP::NoCachePool.new }, :ssl_host => proc { Puppet::SSL::Host.localhost }, :certificate_revocation => proc { Puppet[:certificate_revocation] }, :plugins => proc { Puppet::Plugins::Configuration.load_plugins } } end |
.bootstrap_context ⇒ 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.
A simple set of bindings that is just enough to limp along to initialization where the base_context bindings are put in place
231 232 233 234 235 236 237 |
# File 'lib/puppet.rb', line 231 def self.bootstrap_context root_environment = Puppet::Node::Environment.create(:'*root*', [], Puppet::Node::Environment::NO_MANIFEST) { :current_environment => root_environment, :root_environment => root_environment } end |
.debug=(value) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/puppet.rb', line 106 def self.debug=(value) if value Puppet::Util::Log.level=(:debug) else Puppet::Util::Log.level=(:notice) end end |
.default_diffargs ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/puppet/defaults.rb', line 3 def self.default_diffargs if (Facter.value(:kernel) == "AIX" && Facter.value(:kernelmajversion) == "5300") "" else "-u" end end |
.define_settings(section, hash) ⇒ Object
Store a new default value.
93 94 95 |
# File 'lib/puppet.rb', line 93 def self.define_settings(section, hash) @@settings.define_settings(section, hash) end |
.ignore(name) ⇒ 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.
269 270 271 |
# File 'lib/puppet.rb', line 269 def self.ignore(name) @context.ignore(name) end |
.initialize_facts ⇒ Object
Initialize puppet’s core facts. It should not be called before initialize_settings.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/puppet.rb', line 161 def self.initialize_facts # Add the puppetversion fact; this is done before generating the hash so it is # accessible to custom facts. Facter.add(:puppetversion) do setcode { Puppet.version.to_s } end Facter.add(:agent_specified_environment) do setcode do if Puppet.settings.set_by_config?(:environment) Puppet[:environment] end end end end |
.initialize_settings(args = []) ⇒ void
This method returns an undefined value.
Initialize puppet’s settings. This is intended only for use by external tools that are not
built off of the Faces API or the Puppet::Util::Application class. It may also be used
to initialize state so that a Face may be used programatically, rather than as a stand-alone
command-line tool.
145 146 147 |
# File 'lib/puppet.rb', line 145 def self.initialize_settings(args = []) do_initialize_settings_for_run_mode(:user, args) end |
.lookup(name, &block) ⇒ 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.
Lookup a binding by name or return a default value provided by a passed block (if given).
255 256 257 |
# File 'lib/puppet.rb', line 255 def self.lookup(name, &block) @context.lookup(name, &block) end |
.mark_context(name) ⇒ 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.
280 281 282 |
# File 'lib/puppet.rb', line 280 def self.mark_context(name) @context.mark(name) end |
.minor_version ⇒ String
Returns containing the puppet version to minor specificity, e.g. “3.0”.
71 72 73 |
# File 'lib/puppet/version.rb', line 71 def self.minor_version self.version.split('.')[0..1].join('.') end |
.newtype(name, options = {}, &block) ⇒ Object
Create a new type. Just proxy to the Type class. The mirroring query code was deprecated in 2008, but this is still in heavy use. I suppose this can count as a soft deprecation for the next dev. –daniel 2011-04-12
180 181 182 183 |
# File 'lib/puppet.rb', line 180 def self.newtype(name, = {}, &block) Puppet.deprecation_warning(_("Creating %{name} via Puppet.newtype is deprecated and will be removed in a future release. Use Puppet::Type.newtype instead.") % { name: name }) Puppet::Type.newtype(name, , &block) end |
.override(bindings, description = "") { ... } ⇒ 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.
263 264 265 |
# File 'lib/puppet.rb', line 263 def self.override(bindings, description = "", &block) @context.override(bindings, description, &block) end |
.pop_context ⇒ 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.
Return to the previous context.
249 250 251 |
# File 'lib/puppet.rb', line 249 def self.pop_context @context.pop end |
.push_context(overrides, description = "") ⇒ 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.
242 243 244 |
# File 'lib/puppet.rb', line 242 def self.push_context(overrides, description = "") @context.push(overrides, description) end |
.restore(name) ⇒ 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.
275 276 277 |
# File 'lib/puppet.rb', line 275 def self.restore(name) @context.restore(name) end |
.rollback_context(name) ⇒ 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.
285 286 287 |
# File 'lib/puppet.rb', line 285 def self.rollback_context(name) @context.rollback(name) end |
.run_mode ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/puppet.rb', line 114 def self.run_mode # This sucks (the existence of this method); there are a lot of places in our code that branch based the value of # "run mode", but there used to be some really confusing code paths that made it almost impossible to determine # when during the lifecycle of a puppet application run the value would be set properly. A lot of the lifecycle # stuff has been cleaned up now, but it still seems frightening that we rely so heavily on this value. # # I'd like to see about getting rid of the concept of "run_mode" entirely, but there are just too many places in # the code that call this method at the moment... so I've settled for isolating it inside of the Settings class # (rather than using a global variable, as we did previously...). Would be good to revisit this at some point. # # --cprice 2012-03-16 Puppet::Util::RunMode[@@settings.preferred_run_mode] end |
.settings ⇒ Object
Note: It’s important that these accessors (‘self.settings`, `self.[]`) are defined before we try to load any “features” (which happens a few lines below), because the implementation of the features loading may examine the values of settings.
63 64 65 |
# File 'lib/puppet.rb', line 63 def self.settings @@settings end |
.version ⇒ String
version is a public API method intended to always provide a fast and lightweight way to determine the version of Puppet.
The intent is that software external to Puppet be able to determine the Puppet version with no side-effects. The expected use is:
require 'puppet/version'
version = Puppet.version
This function has the following ordering precedence. This precedence list is designed to facilitate automated packaging tasks by simply writing to the VERSION file in the same directory as this source file.
1. If a version has been explicitly assigned using the Puppet.version=
method, return that version.
2. If there is a VERSION file, read the contents, trim any
trailing whitespace, and return that version string.
3. Return the value of the Puppet::PUPPETVERSION constant hard-coded into
the source code.
If there is no VERSION file, the method must return the version string of the nearest parent version that is an officially released version. That is to say, if a branch named 3.1.x contains 25 patches on top of the most recent official release of 3.1.1, then the version method must return the string “3.1.1” if no “VERSION” file is present.
By design the version identifier is not intended to vary during the life a process. There is no guarantee provided that writing to the VERSION file while a Puppet process is running will cause the version string to be updated. On the contrary, the contents of the VERSION are cached to reduce filesystem accesses.
The VERSION file is intended to be used by package maintainers who may be applying patches or otherwise changing the software version in a manner that warrants a different software version identifier. The VERSION file is intended to be managed and owned by the release process and packaging related tasks, and as such should not reside in version control. The PUPPETVERSION constant is intended to be version controlled in history.
Ideally, this behavior will allow package maintainers to precisely specify the version of the software they’re packaging as in the following example:
$ git describe --match "3.0.*" > lib/puppet/VERSION
$ ruby -r puppet -e 'puts Puppet.version'
3.0.1-260-g9ca4e54
61 62 63 64 65 66 67 68 |
# File 'lib/puppet/version.rb', line 61 def self.version version_file = File.join(File.dirname(__FILE__), 'VERSION') return @puppet_version if @puppet_version if version = read_version_file(version_file) @puppet_version = version end @puppet_version ||= PUPPETVERSION end |
.version=(version) ⇒ Object
75 76 77 |
# File 'lib/puppet/version.rb', line 75 def self.version=(version) @puppet_version = version end |