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/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/parser/files.rb,
lib/puppet/parser/lexer.rb,
lib/puppet/type/package.rb,
lib/puppet/type/service.rb,
lib/puppet/type/yumrepo.rb,
lib/puppet/util/plugins.rb,
lib/puppet/parser/parser.rb,
lib/puppet/parser/parser.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/pops/parser/lexer.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/pops/parser/eparser.rb,
lib/puppet/pops/parser/eparser.rb,
lib/puppet/type/file/selcontext.rb,
lib/puppet/parser/parser_factory.rb,
lib/puppet/property/ordered_list.rb,
lib/puppet/parser/e_parser_adapter.rb,
lib/puppet/type/ssh_authorized_key.rb,
lib/puppet/util/constant_inflector.rb,
lib/puppet/util/symbolic_file_mode.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: Coercion, Confiner, DSL, ExternalFileError, FileBucket, FileBucketFile, FileSystem, Graph, Indirector, MetaType, ModuleTool, Network, Parser, Pops, Rails, SSL, Scheduler, Test, Util Classes: Agent, AlreadyImportedError, Application, AuthStoreError, AuthorizationError, Bindings, ConfigurationError, Configurer, Confine, ConfineCollection, ConstantAlreadyDefined, Daemon, DataBinding, DevError, Error, ExecutionFailure, FileCollection, FileServing, Forge, ImportError, IniProperty, Interface, LexError, Module, Node, Parameter, ParseError, Plugins, Property, Provider, Relationship, Reports, Resource, ResourceError, Run, SELFileContext, Settings, Status, SubclassAlreadyDefined, Transaction, Type, Vendor

Constant Summary collapse

Face =
Puppet::Interface
PUPPETVERSION =
'3.4.3'
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).}
STORECONFIGS_ONLY =
%q{This setting is only used by the ActiveRecord storeconfigs and inventory backends, which are deprecated.}
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
Metric =

This is necessary because we changed the class path in early 2007, and reports directly yaml-dump these metrics, so both client and server have to agree on the class name.

Puppet::Util::Metric
ABSENT_DOC =

Doc string for properties that can be made ‘absent’

"Set this to `absent` to remove it from the file completely."
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

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, deterministic_rand, execfail, execpipe, execute, exit_on_fail, logmethods, memory, path_to_uri, pretty_backtrace, proxy, replace_file, safe_posix_fork, 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, deprecation_warning, format_exception, get_deprecation_offender, log_and_raise, log_deprecations_to_file, log_exception, send_log

Class Attribute Details

.featuresObject (readonly)



34
35
36
# File 'lib/puppet.rb', line 34

def features
  @features
end

.name=(value) ⇒ Object (writeonly)



35
36
37
# File 'lib/puppet.rb', line 35

def name=(value)
  @name = value
end

Class Method Details

.[](param) ⇒ Object

Get the value for a setting

Parameters:

  • param (Symbol)

    the setting to retrieve



64
65
66
67
68
69
70
# File 'lib/puppet.rb', line 64

def self.[](param)
  if param == :debug
    return Puppet::Util::Log.level == :debug
  else
    return @@settings[param]
  end
end

.[]=(param, value) ⇒ Object

configuration parameter access and stuff



73
74
75
# File 'lib/puppet.rb', line 73

def self.[]=(param,value)
  @@settings[param] = value
end

.clearObject



77
78
79
# File 'lib/puppet.rb', line 77

def self.clear
  @@settings.clear
end

.debug=(value) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/puppet.rb', line 81

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

.default_diffargsObject



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.



55
56
57
# File 'lib/puppet.rb', line 55

def self.define_settings(section, hash)
  @@settings.define_settings(section, hash)
end

.genmanifestObject



111
112
113
114
115
116
# File 'lib/puppet.rb', line 111

def self.genmanifest
  if Puppet[:genmanifest]
    puts Puppet.settings.to_manifest
    exit(0)
  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.

Parameters:

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

    the command line arguments to use for initialization



133
134
135
# File 'lib/puppet.rb', line 133

def self.initialize_settings(args = [])
  do_initialize_settings_for_run_mode(:user, args)
end

.initialize_settings_for_run_mode(run_mode) ⇒ Object

Deprecated.

Use #initialize_settings

Initialize puppet’s settings for a specified run_mode.



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

def self.initialize_settings_for_run_mode(run_mode)
  Puppet.deprecation_warning("initialize_settings_for_run_mode may be removed in a future release, as may run_mode itself")
  do_initialize_settings_for_run_mode(run_mode, [])
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



157
158
159
# File 'lib/puppet.rb', line 157

def self.newtype(name, options = {}, &block)
  Puppet::Type.newtype(name, options, &block)
end

.parse_configObject

Deprecated.

Use #initialize_settings

Parse the config file for this process.



120
121
122
123
# File 'lib/puppet.rb', line 120

def self.parse_config()
  Puppet.deprecation_warning("Puppet.parse_config is deprecated; please use Faces API (which will handle settings and state management for you), or (less desirable) call Puppet.initialize_settings")
  Puppet.initialize_settings
end

.run_modeObject



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/puppet.rb', line 94

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



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

def self.settings
  @@settings
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”



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