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/exec.rb,
lib/puppet/type/user.rb,
lib/puppet/type/group.rb,
lib/puppet/application.rb,
lib/puppet/module_tool.rb,
lib/puppet/pal/pal_api.rb,
lib/puppet/type/notify.rb,
lib/puppet/pal/compiler.rb,
lib/puppet/pal/pal_impl.rb,
lib/puppet/type/package.rb,
lib/puppet/type/service.rb,
lib/puppet/generate/type.rb,
lib/puppet/property/list.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/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/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/type/file/content.rb,
lib/puppet/util/command_line.rb,
lib/puppet/network/authconfig.rb,
lib/puppet/pal/plan_signature.rb,
lib/puppet/pal/task_signature.rb,
lib/puppet/application_support.rb,
lib/puppet/pal/script_compiler.rb,
lib/puppet/pops/parser/eparser.rb,
lib/puppet/pops/parser/eparser.rb,
lib/puppet/type/file/data_sync.rb,
lib/puppet/pal/catalog_compiler.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/pal/function_signature.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/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, DataTypes, Environments, Etc, ExternalFileError, FileBucket, FileBucketFile, FileSystem, Functions, Generate, GettextConfig, Graph, Indirector, InfoService, MetaType, ModuleTool, ModuleTranslations, Network, Pal, Parser, Plugins, Pops, Rest, SSL, Scheduler, SyntaxCheckers, Test, Util, X509 Classes: Agent, AlreadyImportedError, Application, AuthStoreError, AuthorizationError, ConfigurationError, Configurer, Confine, ConfineCollection, ConstantAlreadyDefined, Context, Daemon, DataBinding, DevError, Error, ErrorWithData, 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 =
'6.4.0'
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
'2.3.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, Util::RFC_3986_URI_REGEX

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

Class Attribute Summary collapse

Class Method Summary collapse

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, groups_of, #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

.featuresObject (readonly)



49
50
51
# File 'lib/puppet.rb', line 49

def features
  @features
end

Class Method Details

.[](param) ⇒ Object

Get the value for a setting

Parameters:

  • param (Symbol)

    the setting to retrieve



68
69
70
71
72
73
74
# File 'lib/puppet.rb', line 68

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



94
95
96
# File 'lib/puppet.rb', line 94

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

Parameters:

  • settings (Puppet::Settings, Hash<Symbol,String>)

    either a Puppet::Settings instance or a Hash of settings key/value pairs.



183
184
185
186
187
188
189
190
191
192
193
194
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 183

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_context => proc {
      begin
        ssl = Puppet::SSL::SSLProvider.new
        ssl.load_context(certname: Puppet[:certname])
      rescue => e
        # TRANSLATORS: `message` is an already translated string of why SSL failed to initialize
        Puppet.log_exception(e, _("Failed to initialize SSL: %{message}") % { message: e.message })
        # TRANSLATORS: `puppet agent -t` is a command and should not be translated
        Puppet.err(_("Run `puppet agent -t`"))
        raise e
      end
    },
    :ssl_host => proc { Puppet::SSL::Host.localhost },
    :plugins => proc { Puppet::Plugins::Configuration.load_plugins },
    :rich_data => false
  }
end

.bootstrap_contextObject

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

.clearObject



98
99
100
# File 'lib/puppet.rb', line 98

def self.clear
  @@settings.clear
end

.debug=(value) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/puppet.rb', line 102

def self.debug=(value)
  if value
    Puppet::Util::Log.level=(:debug)
  else
    Puppet::Util::Log.level=(:notice)
  end
end

.default_basemodulepathObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/puppet/defaults.rb', line 35

def self.default_basemodulepath
  if Puppet::Util::Platform.windows?
    path = ['$codedir/modules']
    installdir = Facter.value(:env_windows_installdir)
    if installdir
      path << "#{installdir}/puppet/modules"
    end
    path.join(File::PATH_SEPARATOR)
  else
    '$codedir/modules:/opt/puppetlabs/puppet/modules'
  end
end

.default_diffargsObject



5
6
7
8
9
10
11
# File 'lib/puppet/defaults.rb', line 5

def self.default_diffargs
  if (Facter.value(:kernel) == "AIX" && Facter.value(:kernelmajversion) == "5300")
    ""
  else
    "-u"
  end
end

.default_digest_algorithmObject



13
14
15
# File 'lib/puppet/defaults.rb', line 13

def self.default_digest_algorithm
  Puppet::Util::Platform.fips_enabled? ? 'sha256' : 'md5'
end

.default_file_checksum_typesObject



23
24
25
26
27
# File 'lib/puppet/defaults.rb', line 23

def self.default_file_checksum_types
  Puppet::Util::Platform.fips_enabled? ?
    %w[sha256 sha384 sha512 sha224] :
    %w[md5 sha256 sha384 sha512 sha224]
end

.default_vendormoduledirObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/puppet/defaults.rb', line 48

def self.default_vendormoduledir
  if Puppet::Util::Platform.windows?
    installdir = Facter.value(:env_windows_installdir)
    if installdir
      "#{installdir}\\puppet\\vendor_modules"
    else
      nil
    end
  else
    '/opt/puppetlabs/puppet/vendor_modules'
  end
end

.define_settings(section, hash) ⇒ Object

Store a new default value.



89
90
91
# File 'lib/puppet.rb', line 89

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.

Parameters:

  • name

    The name of a context key to ignore; intended for test usage.



269
270
271
# File 'lib/puppet.rb', line 269

def self.ignore(name)
  @context.ignore(name)
end

.initialize_factsObject

Initialize puppet’s core facts. It should not be called before initialize_settings.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/puppet.rb', line 157

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 = [], require_config = true) ⇒ 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.

Parameters:

  • args (Array<String>) (defaults to: [])

    the command line arguments to use for initialization



141
142
143
# File 'lib/puppet.rb', line 141

def self.initialize_settings(args = [], require_config = true)
  do_initialize_settings_for_run_mode(:user, args, require_config)
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_versionString

Returns containing the puppet version to minor specificity, e.g. “3.0”.

Returns:

  • (String)

    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

.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.

Parameters:

  • bindings (Hash)

    A hash of bindings to be merged with the parent context.

  • description (String) (defaults to: "")

    A description of the context.

Yields:

  • A block executed in the context of the temporarily pushed bindings.



263
264
265
# File 'lib/puppet.rb', line 263

def self.override(bindings, description = "", &block)
  @context.override(bindings, description, &block)
end

.pop_contextObject

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.

Raises:

  • (StackUnderflow)

    if the current context is the root



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.

Parameters:

  • overrides (Hash)

    A hash of bindings to be merged with the parent context.

  • description (String) (defaults to: "")

    A description of the context.



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.

Parameters:

  • name

    The name of a previously ignored context key to restore; intended for test usage.



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_modeObject



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/puppet.rb', line 110

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

.settingsObject

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.



59
60
61
# File 'lib/puppet.rb', line 59

def self.settings
  @@settings
end

.valid_digest_algorithmsObject



17
18
19
20
21
# File 'lib/puppet/defaults.rb', line 17

def self.valid_digest_algorithms
  Puppet::Util::Platform.fips_enabled? ?
    %w[sha256 sha384 sha512 sha224] :
    %w[md5 sha256 sha384 sha512 sha224]
end

.valid_file_checksum_typesObject



29
30
31
32
33
# File 'lib/puppet/defaults.rb', line 29

def self.valid_file_checksum_types
  Puppet::Util::Platform.fips_enabled? ?
    %w[sha256 sha256lite sha384 sha512 sha224 sha1 sha1lite mtime ctime] :
    %w[md5 md5lite sha256 sha256lite sha384 sha512 sha224 sha1 sha1lite mtime ctime]
end

.versionString

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

Returns:

  • (String)

    containing the puppet version, e.g. “3.0.1”



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