Module: Puppet
- Extended by:
- Util, Util::Logging
- Defined in:
- lib/puppet.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/version.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/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/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/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/util/command_line/trollop.rb,
lib/puppet/module_tool/install_directory.rb,
lib/puppet/ssl/certificate_authority/interface.rb,
lib/puppet/util/command_line/puppet_option_parser.rb
Overview
The main Puppet class. Everything is contained here.
Defined Under Namespace
Modules: ApplicationSupport, Coercion, Confiner, DataProviders, DataSync, Environments, ExternalFileError, FileBucket, FileBucketFile, FileSystem, Functions, 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
- Face =
Puppet::Interface
- PUPPETVERSION =
'4.4.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. Apparently the alias was created in March 2007, should could probably be removed soon.
Puppet::Util::Log
- ResourceType =
self
- @@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
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
-
.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_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
59 60 61 62 63 64 65 |
# File 'lib/puppet.rb', line 59 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
85 86 87 |
# File 'lib/puppet.rb', line 85 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
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/puppet.rb', line 176 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 loaders << Puppet::Environments::StaticPrivate.new( Puppet::Node::Environment.create(default_environment, basemodulepath, 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 } } 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
207 208 209 210 211 212 213 |
# File 'lib/puppet.rb', line 207 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
93 94 95 96 97 98 99 |
# File 'lib/puppet.rb', line 93 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.
80 81 82 |
# File 'lib/puppet.rb', line 80 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.
245 246 247 |
# File 'lib/puppet.rb', line 245 def self.ignore(name) @context.ignore(name) end |
.initialize_facts ⇒ Object
Initialize puppet’s core facts. It should not be called before initialize_settings.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/puppet.rb', line 142 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.
126 127 128 |
# File 'lib/puppet.rb', line 126 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).
231 232 233 |
# File 'lib/puppet.rb', line 231 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.
256 257 258 |
# File 'lib/puppet.rb', line 256 def self.mark_context(name) @context.mark(name) 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
161 162 163 164 |
# File 'lib/puppet.rb', line 161 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.") 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.
239 240 241 |
# File 'lib/puppet.rb', line 239 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.
225 226 227 |
# File 'lib/puppet.rb', line 225 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.
218 219 220 |
# File 'lib/puppet.rb', line 218 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.
251 252 253 |
# File 'lib/puppet.rb', line 251 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.
261 262 263 |
# File 'lib/puppet.rb', line 261 def self.rollback_context(name) @context.rollback(name) end |
.run_mode ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/puppet.rb', line 101 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.
50 51 52 |
# File 'lib/puppet.rb', line 50 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
62 63 64 65 66 67 68 69 |
# File 'lib/puppet/version.rb', line 62 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
71 72 73 |
# File 'lib/puppet/version.rb', line 71 def self.version=(version) @puppet_version = version end |