No description
Find a file
Dan Bode a0cb8cdee4 Add function ensure_resource and defined_with_params
This commit adds 2 new functions with unit tests.

defined_with_params works similarily to puppet's defined
function, except it allows you to also specify a hash of
params. defined_with_params will return true if a resource
also exists that matches the specified type/title (just like
with defined) as well as all of the specified params.

ensure_resource is a function that basically combines defined_with_params
with create_resources to conditionally create resources only if the
specified resource (title, type, params) does not already exist.

These functions are created to serve as an alternative to using
defined as follows:

    if ! defined(Package['some_package']) {
      package { 'some_package': ensure => present,
    }

The issue with this usage is that there is no guarentee about
what parameters were set in the previous definition of the package
that made its way into the catalog.

ensure_resource could be used instead, as:

    ensure_resource('package', 'some_package', { 'ensure' => 'present' })

This will creat the package resources only if another resource does
not exist with the specified parameters.
2012-10-25 10:54:33 -07:00
lib Add function ensure_resource and defined_with_params 2012-10-25 10:54:33 -07:00
manifests Docs: Update documentation of stdlib classes 2011-08-18 12:39:04 -07:00
spec Add function ensure_resource and defined_with_params 2012-10-25 10:54:33 -07:00
tests (#8792) Rename basic smoke test to reflect file_line rename 2011-08-08 09:33:56 -07:00
.gitignore (#8797) Merge puppetlabs-functions into puppetlabs-stdlib 2011-08-05 10:31:46 +01:00
.rspec Add .rspec file to repo root 2012-08-20 11:49:45 -07:00
CHANGELOG Update Modulefile, CHANGELOG for 2.4.0 2012-08-14 10:18:42 -07:00
LICENSE (#8797) Merge puppetlabs-functions into puppetlabs-stdlib 2011-08-05 10:31:46 +01:00
Modulefile Update Modulefile, CHANGELOG for 2.4.0 2012-08-14 10:18:42 -07:00
Rakefile Copied function test scaffolding from puppet. 2011-06-29 12:25:43 +01:00
README.markdown (maint) Add semantic versioning info to README 2011-12-30 11:46:21 -08:00
README_DEVELOPER.markdown (#12357) Add puppet_vardir custom fact 2012-03-05 16:26:22 -08:00
RELEASE_PROCESS.markdown Add note about semver.org leading v in tags. 2011-11-08 14:31:51 -08:00

Puppet Labs Standard Library

This module provides a "standard library" of resources for developing Puppet Modules. This modules will include the following additions to Puppet

  • Stages
  • Facts
  • Functions
  • Defined resource types
  • Types
  • Providers

This module is officially curated and provided by Puppet Labs. The modules Puppet Labs writes and distributes will make heavy use of this standard library.

Versions

This module follows semver.org (v1.0.0) versioning guidelines. The standard library module is released as part of Puppet Enterprise and as a result older versions of Puppet Enterprise that Puppet Labs still supports will have bugfix maintenance branches periodically "merged up" into master. The current list of integration branches are:

  • v2.1.x (v2.1.1 released in PE 1.2, 1.2.1, 1.2.3, 1.2.4)
  • v2.2.x (Never released as part of PE, only to the Forge)
  • v2.3.x (Scheduled for next PE feature release)
  • master (mainline development branch)

The first Puppet Enterprise version including the stdlib module is Puppet Enterprise 1.2.

Compatibility

stdlib v2.1.x, v2.2.x

v2.1.x and v2.2.x of this module are designed to work with Puppet versions 2.6.x and 2.7.x. There are currently no plans for a Puppet 0.25 standard library module.

stdlib v2.3.x

While not yet released, the standard library may only work with Puppet 2.7.x.

Functions

Please see puppet doc -r function for documentation on each function. The current list of functions is:

  • getvar
  • has_key
  • loadyaml
  • merge.rb
  • validate_array
  • validate_bool
  • validate_hash
  • validate_re
  • validate_string

validate_hash

$somehash = { 'one' => 'two' }
validate\_hash($somehash)

getvar()

This function aims to look up variables in user-defined namespaces within puppet. Note, if the namespace is a class, it should already be evaluated before the function is used.

$namespace = 'site::data'
include "${namespace}"
$myvar = getvar("${namespace}::myvar")

Facts

Facts in /etc/facter/facts.d and /etc/puppetlabs/facter/facts.d are now loaded automatically. This is a direct copy of R.I. Pienaar's custom facter fact located at: https://github.com/ripienaar/facter-facts/tree/master/facts-dot-d