Module: Puppet

Defined in:
lib/puppet.rb,
lib/puppet/pops.rb,
lib/puppet/util.rb,
lib/puppet/type.rb,
lib/puppet/error.rb,
lib/puppet/vendor.rb,
lib/puppet/loaders.rb,
lib/puppet/version.rb,
lib/puppet/type/zfs.rb,
lib/puppet/defaults.rb,
lib/puppet/type/exec.rb,
lib/puppet/type/user.rb,
lib/puppet/type/host.rb,
lib/puppet/type/zpool.rb,
lib/puppet/type/mount.rb,
lib/puppet/type/group.rb,
lib/puppet/type/notify.rb,
lib/puppet/type/router.rb,
lib/puppet/application.rb,
lib/puppet/module_tool.rb,
lib/puppet/type/sshkey.rb,
lib/puppet/type/package.rb,
lib/puppet/parser/lexer.rb,
lib/puppet/util/plugins.rb,
lib/puppet/type/service.rb,
lib/puppet/util/platform.rb,
lib/puppet/util/classgen.rb,
lib/puppet/parser/parser.rb,
lib/puppet/parser/parser.rb,
lib/puppet/type/maillist.rb,
lib/puppet/type/schedule.rb,
lib/puppet/util/run_mode.rb,
lib/puppet/property/list.rb,
lib/puppet/type/file/mode.rb,
lib/puppet/type/mailalias.rb,
lib/puppet/util/execution.rb,
lib/puppet/type/file/type.rb,
lib/puppet/resource/status.rb,
lib/puppet/type/file/ctime.rb,
lib/puppet/type/file/owner.rb,
lib/puppet/type/selboolean.rb,
lib/puppet/type/filebucket.rb,
lib/puppet/type/file/group.rb,
lib/puppet/type/file/mtime.rb,
lib/puppet/type/file/source.rb,
lib/puppet/type/file/ensure.rb,
lib/puppet/type/file/target.rb,
lib/puppet/property/keyvalue.rb,
lib/puppet/ssl/configuration.rb,
lib/puppet/network/authstore.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/util/constant_inflector.rb,
lib/puppet/util/symbolic_file_mode.rb,
lib/puppet/type/ssh_authorized_key.rb,
lib/puppet/parser/e4_parser_adapter.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, Environments, Functions, MetaType, Parser, Pops Classes: Bindings, Context, Daemon, ExecutionFailure, Interface, Parameter, Property, Provider, Reports, Resource, Transaction, Type

Constant Summary

Class Method Summary (collapse)

Methods included from Util

exit_on_fail, exit_on_fail, which, which

Class Method Details

+ (Object) [](param)

Get the value for a setting

Parameters:

  • param (Symbol)

    the setting to retrieve



55
56
57
58
59
60
61
# File 'lib/puppet.rb', line 55

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

+ (Object) base_context(settings)

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



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/puppet.rb', line 169

def self.base_context(settings)
  environments = settings[:environmentpath]
  modulepath = Puppet::Node::Environment.split_path(settings[:basemodulepath])

  if environments.empty?
    loaders = [Puppet::Environments::Legacy.new]
  else
    loaders = Puppet::Environments::Directories.from_path(environments, modulepath)
    # 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(Puppet[:environment].to_sym,
                                         [],
                                         Puppet::Node::Environment::NO_MANIFEST))
    end
  end

  {
    :environments => Puppet::Environments::Cached.new(*loaders),
    :http_pool => proc {
      require 'puppet/network/http'
      Puppet::Network::HTTP::NoCachePool.new
    }
  }
end

+ (Object) bootstrap_context

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



200
201
202
203
204
205
206
# File 'lib/puppet.rb', line 200

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

+ initialize_settings(args = [])

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



127
128
129
# File 'lib/puppet.rb', line 127

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

+ (Object) lookup(name, &block)

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



224
225
226
# File 'lib/puppet.rb', line 224

def self.lookup(name, &block)
  @context.lookup(name, &block)
end

+ (Object) mark_context(name)

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.



237
238
239
# File 'lib/puppet.rb', line 237

def self.mark_context(name)
  @context.mark(name)
end

+ (Object) override(bindings, description = "") { ... }

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.



232
233
234
# File 'lib/puppet.rb', line 232

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

+ (Object) pop_context

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



218
219
220
# File 'lib/puppet.rb', line 218

def self.pop_context
  @context.pop
end

+ (Object) push_context(overrides, description = "")

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.



211
212
213
# File 'lib/puppet.rb', line 211

def self.push_context(overrides, description = "")
  @context.push(overrides, description)
end

+ (String) read_version_file(path) (private)

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.

read_version_file reads the content of the "VERSION" file that lives in the same directory as this source code file.

Returns:

  • (String)

    for example: "1.6.14-6-gea42046" or nil if the VERSION file does not exist.



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

def self.read_version_file(path)
  if File.exist?(path)
    File.read(path).chomp
  end
end

+ (Object) rollback_context(name)

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.rollback_context(name)
  @context.rollback(name)
end

+ (String) version

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