summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore8
-rw-r--r--.sync.yml9
-rw-r--r--.travis.yml26
-rw-r--r--CONTRIBUTING.md295
-rw-r--r--README.markdown1761
-rw-r--r--lib/puppet/parser/functions/bool2num.rb25
-rw-r--r--lib/puppet/parser/functions/capitalize.rb3
-rw-r--r--lib/puppet/parser/functions/chomp.rb3
-rw-r--r--lib/puppet/parser/functions/chop.rb3
-rw-r--r--lib/puppet/parser/functions/concat.rb6
-rw-r--r--lib/puppet/parser/functions/downcase.rb3
-rw-r--r--lib/puppet/parser/functions/empty.rb3
-rw-r--r--lib/puppet/parser/functions/fqdn_rotate.rb3
-rw-r--r--lib/puppet/parser/functions/getvar.rb5
-rw-r--r--lib/puppet/parser/functions/has_interface_with.rb10
-rw-r--r--lib/puppet/parser/functions/lstrip.rb3
-rw-r--r--lib/puppet/parser/functions/private.rb29
-rw-r--r--lib/puppet/parser/functions/reverse.rb3
-rw-r--r--lib/puppet/parser/functions/rstrip.rb3
-rw-r--r--lib/puppet/parser/functions/shuffle.rb3
-rw-r--r--lib/puppet/parser/functions/strip.rb3
-rw-r--r--lib/puppet/parser/functions/swapcase.rb3
-rw-r--r--lib/puppet/parser/functions/unique.rb3
-rw-r--r--lib/puppet/parser/functions/upcase.rb3
-rw-r--r--lib/puppet/parser/functions/uriescape.rb3
-rw-r--r--lib/puppet/parser/functions/validate_string.rb11
-rw-r--r--lib/puppet/parser/functions/zip.rb28
-rw-r--r--lib/puppet/type/file_line.rb3
-rw-r--r--spec/acceptance/nodesets/centos-59-x64.yml10
-rw-r--r--spec/acceptance/nodesets/centos-65-x64.yml10
-rw-r--r--spec/acceptance/nodesets/ubuntu-server-1404-x64.yml11
-rwxr-xr-xspec/functions/bool2num_spec.rb18
-rwxr-xr-xspec/functions/capitalize_spec.rb9
-rwxr-xr-xspec/functions/chomp_spec.rb9
-rwxr-xr-xspec/functions/chop_spec.rb9
-rwxr-xr-xspec/functions/concat_spec.rb5
-rwxr-xr-xspec/functions/downcase_spec.rb9
-rwxr-xr-xspec/functions/empty_spec.rb9
-rwxr-xr-xspec/functions/fqdn_rotate_spec.rb10
-rwxr-xr-xspec/functions/lstrip_spec.rb9
-rwxr-xr-xspec/functions/private_spec.rb55
-rwxr-xr-xspec/functions/reverse_spec.rb9
-rwxr-xr-xspec/functions/rstrip_spec.rb9
-rwxr-xr-xspec/functions/shuffle_spec.rb9
-rwxr-xr-xspec/functions/strip_spec.rb9
-rwxr-xr-xspec/functions/swapcase_spec.rb9
-rwxr-xr-xspec/functions/unique_spec.rb9
-rwxr-xr-xspec/functions/upcase_spec.rb9
-rwxr-xr-xspec/functions/uriescape_spec.rb9
-rwxr-xr-xspec/functions/zip_spec.rb16
-rwxr-xr-xspec/spec_helper_acceptance.rb15
51 files changed, 1086 insertions, 1451 deletions
diff --git a/.gitignore b/.gitignore
index 7d0fd8d..b5b7a00 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,7 @@
pkg/
-.DS_Store
-coverage/
-spec/fixtures/
Gemfile.lock
+vendor/
+spec/fixtures/
+.vagrant/
.bundle/
-vendor/bundle/
+coverage/
diff --git a/.sync.yml b/.sync.yml
new file mode 100644
index 0000000..21e872e
--- /dev/null
+++ b/.sync.yml
@@ -0,0 +1,9 @@
+---
+.travis.yml:
+ script: "\"bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'\""
+Rakefile:
+ unmanaged: true
+Gemfile:
+ unmanaged: true
+spec/spec_helper.rb:
+ unmanaged: true
diff --git a/.travis.yml b/.travis.yml
index 34d8cc9..3ed1153 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,26 +2,16 @@
language: ruby
bundler_args: --without development
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--color --format documentation'"
-rvm:
- - 1.8.7
- - 1.9.3
- - 2.0.0
- - ruby-head
-env:
- - PUPPET_GEM_VERSION=">= 3.0.0"
matrix:
fast_finish: true
- allow_failures:
- - rvm: 2.0.0
- - rvm: ruby-head
include:
- - rvm: 1.8.7
- env: PUPPET_GEM_VERSION="~> 2.7"
+ - rvm: 1.8.7
+ env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
+ - rvm: 1.8.7
+ env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
+ - rvm: 1.9.3
+ env: PUPPET_GEM_VERSION="~> 3.0"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 3.0"
notifications:
email: false
- webhooks:
- urls:
- - https://puppet-dev-community.herokuapp.com/event/travis-ci/
- on_success: always
- on_failure: always
- on_start: yes
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 5280da1..e128847 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,65 +1,234 @@
-# How to contribute
-
-Third-party patches are essential for keeping stdlib great. We simply can't
-access the huge number of platforms and myriad configurations for running
-stdlib. We want to keep it as easy as possible to contribute changes that
-get things working in your environment. There are a few guidelines that we
-need contributors to follow so that we can have a chance of keeping on
-top of things.
-
-## Getting Started
-
-* Make sure you have a [Jira account](http://tickets.puppetlabs.com)
-* Make sure you have a [GitHub account](https://github.com/signup/free)
-* Submit a ticket for your issue, assuming one does not already exist.
- * Clearly describe the issue including steps to reproduce when it is a bug.
- * Make sure you fill in the earliest version that you know has the issue.
-* Fork the repository on GitHub
-
-## Making Changes
-
-* Create a topic branch from where you want to base your work.
- * This is usually the master branch.
- * Only target release branches if you are certain your fix must be on that
- branch.
- * To quickly create a topic branch based on master; `git branch
- fix/master/my_contribution master` then checkout the new branch with `git
- checkout fix/master/my_contribution`. Please avoid working directly on the
- `master` branch.
-* Make commits of logical units.
-* Check for unnecessary whitespace with `git diff --check` before committing.
-* Make sure your commit messages are in the proper format.
-
-````
- (#99999) Make the example in CONTRIBUTING imperative and concrete
-
- Without this patch applied the example commit message in the CONTRIBUTING
- document is not a concrete example. This is a problem because the
- contributor is left to imagine what the commit message should look like
- based on a description rather than an example. This patch fixes the
- problem by making the example concrete and imperative.
-
- The first line is a real life imperative statement with a ticket number
- from our issue tracker. The body describes the behavior without the patch,
- why this is a problem, and how the patch fixes the problem when applied.
-````
-
-* Make sure you have added the necessary tests for your changes.
-* Run _all_ the tests to assure nothing else was accidentally broken.
-
-## Submitting Changes
-
-* Sign the [Contributor License Agreement](http://links.puppetlabs.com/cla).
-* Push your changes to a topic branch in your fork of the repository.
-* Submit a pull request to the repository in the puppetlabs organization.
-* Update your ticket to mark that you have submitted code and are ready for it to be reviewed.
- * Include a link to the pull request in the ticket
-
-# Additional Resources
-
-* [More information on contributing](http://links.puppetlabs.com/contribute-to-puppet)
-* [Bug tracker (Jira)](http://tickets.puppetlabs.com)
-* [Contributor License Agreement](http://links.puppetlabs.com/cla)
+Checklist (and a short version for the impatient)
+=================================================
+
+ * Commits:
+
+ - Make commits of logical units.
+
+ - Check for unnecessary whitespace with "git diff --check" before
+ committing.
+
+ - Commit using Unix line endings (check the settings around "crlf" in
+ git-config(1)).
+
+ - Do not check in commented out code or unneeded files.
+
+ - The first line of the commit message should be a short
+ description (50 characters is the soft limit, excluding ticket
+ number(s)), and should skip the full stop.
+
+ - Associate the issue in the message. The first line should include
+ the issue number in the form "(#XXXX) Rest of message".
+
+ - The body should provide a meaningful commit message, which:
+
+ - uses the imperative, present tense: "change", not "changed" or
+ "changes".
+
+ - includes motivation for the change, and contrasts its
+ implementation with the previous behavior.
+
+ - Make sure that you have tests for the bug you are fixing, or
+ feature you are adding.
+
+ - Make sure the test suites passes after your commit:
+ `bundle exec rspec spec/acceptance` More information on [testing](#Testing) below
+
+ - When introducing a new feature, make sure it is properly
+ documented in the README.md
+
+ * Submission:
+
+ * Pre-requisites:
+
+ - Sign the [Contributor License Agreement](https://cla.puppetlabs.com/)
+
+ - Make sure you have a [GitHub account](https://github.com/join)
+
+ - [Create a ticket](http://projects.puppetlabs.com/projects/modules/issues/new), or [watch the ticket](http://projects.puppetlabs.com/projects/modules/issues) you are patching for.
+
+ * Preferred method:
+
+ - Fork the repository on GitHub.
+
+ - Push your changes to a topic branch in your fork of the
+ repository. (the format ticket/1234-short_description_of_change is
+ usually preferred for this project).
+
+ - Submit a pull request to the repository in the puppetlabs
+ organization.
+
+The long version
+================
+
+ 1. Make separate commits for logically separate changes.
+
+ Please break your commits down into logically consistent units
+ which include new or changed tests relevant to the rest of the
+ change. The goal of doing this is to make the diff easier to
+ read for whoever is reviewing your code. In general, the easier
+ your diff is to read, the more likely someone will be happy to
+ review it and get it into the code base.
+
+ If you are going to refactor a piece of code, please do so as a
+ separate commit from your feature or bug fix changes.
+
+ We also really appreciate changes that include tests to make
+ sure the bug is not re-introduced, and that the feature is not
+ accidentally broken.
+
+ Describe the technical detail of the change(s). If your
+ description starts to get too long, that is a good sign that you
+ probably need to split up your commit into more finely grained
+ pieces.
+
+ Commits which plainly describe the things which help
+ reviewers check the patch and future developers understand the
+ code are much more likely to be merged in with a minimum of
+ bike-shedding or requested changes. Ideally, the commit message
+ would include information, and be in a form suitable for
+ inclusion in the release notes for the version of Puppet that
+ includes them.
+
+ Please also check that you are not introducing any trailing
+ whitespace or other "whitespace errors". You can do this by
+ running "git diff --check" on your changes before you commit.
+
+ 2. Sign the Contributor License Agreement
+
+ Before we can accept your changes, we do need a signed Puppet
+ Labs Contributor License Agreement (CLA).
+
+ You can access the CLA via the [Contributor License Agreement link](https://cla.puppetlabs.com/)
+
+ If you have any questions about the CLA, please feel free to
+ contact Puppet Labs via email at cla-submissions@puppetlabs.com.
+
+ 3. Sending your patches
+
+ To submit your changes via a GitHub pull request, we _highly_
+ recommend that you have them on a topic branch, instead of
+ directly on "master".
+ It makes things much easier to keep track of, especially if
+ you decide to work on another thing before your first change
+ is merged in.
+
+ GitHub has some pretty good
+ [general documentation](http://help.github.com/) on using
+ their site. They also have documentation on
+ [creating pull requests](http://help.github.com/send-pull-requests/).
+
+ In general, after pushing your topic branch up to your
+ repository on GitHub, you can switch to the branch in the
+ GitHub UI and click "Pull Request" towards the top of the page
+ in order to open a pull request.
+
+
+ 4. Update the related GitHub issue.
+
+ If there is a GitHub issue associated with the change you
+ submitted, then you should update the ticket to include the
+ location of your branch, along with any other commentary you
+ may wish to make.
+
+Testing
+=======
+
+Getting Started
+---------------
+
+Our puppet modules provide [`Gemfile`](./Gemfile)s which can tell a ruby
+package manager such as [bundler](http://bundler.io/) what Ruby packages,
+or Gems, are required to build, develop, and test this software.
+
+Please make sure you have [bundler installed](http://bundler.io/#getting-started)
+on your system, then use it to install all dependencies needed for this project,
+by running
+
+```shell
+% bundle install
+Fetching gem metadata from https://rubygems.org/........
+Fetching gem metadata from https://rubygems.org/..
+Using rake (10.1.0)
+Using builder (3.2.2)
+-- 8><-- many more --><8 --
+Using rspec-system-puppet (2.2.0)
+Using serverspec (0.6.3)
+Using rspec-system-serverspec (1.0.0)
+Using bundler (1.3.5)
+Your bundle is complete!
+Use `bundle show [gemname]` to see where a bundled gem is installed.
+```
+
+NOTE some systems may require you to run this command with sudo.
+
+If you already have those gems installed, make sure they are up-to-date:
+
+```shell
+% bundle update
+```
+
+With all dependencies in place and up-to-date we can now run the tests:
+
+```shell
+% rake spec
+```
+
+This will execute all the [rspec tests](http://rspec-puppet.com/) tests
+under [spec/defines](./spec/defines), [spec/classes](./spec/classes),
+and so on. rspec tests may have the same kind of dependencies as the
+module they are testing. While the module defines in its [Modulefile](./Modulefile),
+rspec tests define them in [.fixtures.yml](./fixtures.yml).
+
+Some puppet modules also come with [beaker](https://github.com/puppetlabs/beaker)
+tests. These tests spin up a virtual machine under
+[VirtualBox](https://www.virtualbox.org/)) with, controlling it with
+[Vagrant](http://www.vagrantup.com/) to actually simulate scripted test
+scenarios. In order to run these, you will need both of those tools
+installed on your system.
+
+You can run them by issuing the following command
+
+```shell
+% rake spec_clean
+% rspec spec/acceptance
+```
+
+This will now download a pre-fabricated image configured in the [default node-set](./spec/acceptance/nodesets/default.yml),
+install puppet, copy this module and install its dependencies per [spec/spec_helper_acceptance.rb](./spec/spec_helper_acceptance.rb)
+and then run all the tests under [spec/acceptance](./spec/acceptance).
+
+Writing Tests
+-------------
+
+XXX getting started writing tests.
+
+If you have commit access to the repository
+===========================================
+
+Even if you have commit access to the repository, you will still need to
+go through the process above, and have someone else review and merge
+in your changes. The rule is that all changes must be reviewed by a
+developer on the project (that did not write the code) to ensure that
+all changes go through a code review process.
+
+Having someone other than the author of the topic branch recorded as
+performing the merge is the record that they performed the code
+review.
+
+
+Additional Resources
+====================
+
+* [Getting additional help](http://projects.puppetlabs.com/projects/puppet/wiki/Getting_Help)
+
+* [Writing tests](http://projects.puppetlabs.com/projects/puppet/wiki/Development_Writing_Tests)
+
+* [Patchwork](https://patchwork.puppetlabs.com)
+
+* [Contributor License Agreement](https://projects.puppetlabs.com/contributor_licenses/sign)
+
* [General GitHub documentation](http://help.github.com/)
+
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
-* #puppet-dev IRC channel on freenode.org
+
diff --git a/README.markdown b/README.markdown
index e033b15..78839c6 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,9 +1,25 @@
-# Puppet Labs Standard Library #
+#stdlib
[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-stdlib.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-stdlib)
-This module provides a "standard library" of resources for developing Puppet
-Modules. This modules will include the following additions to Puppet
+####Table of Contents
+
+1. [Overview](#overview)
+2. [Module Description - What the module does and why it is useful](#module-description)
+3. [Setup - The basics of getting started with stdlib](#setup)
+4. [Usage - Configuration options and additional functionality](#usage)
+5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
+5. [Limitations - OS compatibility, etc.](#limitations)
+6. [Development - Guide for contributing to the module](#development)
+
+##Overview
+
+Adds a standard library of resources for Puppet modules.
+
+##Module Description
+
+This module provides a standard library of resources for the development of Puppet
+modules. Puppet modules make heavy use of this standard library. The stdlib module adds the following resources to Puppet:
* Stages
* Facts
@@ -12,1461 +28,680 @@ Modules. This modules will include the following additions to Puppet
* 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.
-
-To report or research a bug with any part of this module, please go to
-[http://tickets.puppetlabs.com/browse/PUP](http://tickets.puppetlabs.com/browse/PUP)
-
-# Versions #
-
-This module follows semver.org (v1.0.0) versioning guidelines. The standard
-library module is released as part of [Puppet
-Enterprise](http://puppetlabs.com/puppet/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)
- * v2.2.x (Never released as part of PE, only to the Forge)
- * v2.3.x (Released in PE 2)
- * v3.0.x (Released in PE 3)
- * v4.0.x (Maintains compatibility with v3.x despite the major semantic version bump. Compatible with Puppet 2.7.x)
- * v5.x (To be released when stdlib can drop support for Puppet 2.7.x. Please see [this discussion](https://github.com/puppetlabs/puppetlabs-stdlib/pull/176#issuecomment-30251414))
- * master (mainline development branch)
-
-The first Puppet Enterprise version including the stdlib module is Puppet
-Enterprise 1.2.
-
-# Compatibility #
-
-Puppet Versions | < 2.6 | 2.6 | 2.7 | 3.x |
-:---------------|:-----:|:---:|:---:|:----:
-**stdlib 2.x** | no | **yes** | **yes** | no
-**stdlib 3.x** | no | no | **yes** | **yes**
-**stdlib 4.x** | no | no | **yes** | **yes**
-
-The stdlib module does not work with Puppet versions released prior to Puppet
-2.6.0.
-
-## stdlib 2.x ##
-
-All stdlib releases in the 2.0 major version support Puppet 2.6 and Puppet 2.7.
-
-## stdlib 3.x ##
-
-The 3.0 major release of stdlib drops support for Puppet 2.6. Stdlib 3.x
-supports Puppet 2 and Puppet 3.
-
-## stdlib 4.x ##
-
-The 4.0 major release of stdlib was intended to drop support for Puppet 2.7,
-but the impact on end users was too high. The decision was made to treat
-stdlib 4.x as a continuation of stdlib 3.x support. Stdlib 4.x supports Puppet
-2.7 and 3. Notably, ruby 1.8.5 is no longer supported though ruby
-1.8.7, 1.9.3, and 2.0.0 are fully supported.
-
-# Functions #
-
-abs
----
-Returns the absolute value of a number, for example -34.56 becomes
-34.56. Takes a single integer and float value as an argument.
-
-
-- *Type*: rvalue
-
-anchor
-------
-A simple resource type intended to be used as an anchor in a composite class.
-
-In Puppet 2.6, when a class declares another class, the resources in the
-interior class are not contained by the exterior class. This interacts badly
-with the pattern of composing complex modules from smaller classes, as it
-makes it impossible for end users to specify order relationships between the
-exterior class and other modules.
-
-The anchor type lets you work around this. By sandwiching any interior
-classes between two no-op resources that _are_ contained by the exterior
-class, you can ensure that all resources in the module are contained.
-
- class ntp {
- # These classes will have the correct order relationship with each
- # other. However, without anchors, they won't have any order
- # relationship to Class['ntp'].
- class { 'ntp::package': }
- -> class { 'ntp::config': }
- -> class { 'ntp::service': }
-
- # These two resources "anchor" the composed classes within the ntp
- # class.
- anchor { 'ntp::begin': } -> Class['ntp::package']
- Class['ntp::service'] -> anchor { 'ntp::end': }
- }
-
-This allows the end user of the ntp module to establish require and before
-relationships with Class['ntp']:
-
- class { 'ntp': } -> class { 'mcollective': }
- class { 'mcollective': } -> class { 'ntp': }
-
-
-- *Type*: resource
-
-any2array
----------
-This converts any object to an array containing that object. Empty argument
-lists are converted to an empty array. Arrays are left untouched. Hashes are
-converted to arrays of alternating keys and values.
-
-
-- *Type*: rvalue
-
-base64
---------
-Converts a string to and from base64 encoding.
-Requires an action ['encode','decode'] and either a plain or base64 encoded
-string
-
-
-- *Type*: rvalue
-
-bool2num
---------
-Converts a boolean to a number. Converts the values:
-false, f, 0, n, and no to 0
-true, t, 1, y, and yes to 1
- Requires a single boolean or string as an input.
+##Setup
+Installing the stdlib module adds the functions, facts, and resources of this standard library to Puppet.
-- *Type*: rvalue
+##Usage
-bool2str
---------
-Converts a boolean to a string.
-Requires a single boolean as an input.
+After you've installed stdlib, all of its functions, facts, and resources are available for module use or development.
-- *Type*: rvalue
+If you want to use a standardized set of run stages for Puppet, `include stdlib` in your manifest.
-camelcase
----------
-Converts the case of a string or all strings in an array to camel case.
+##Reference
-- *Type*: rvalue
+### Classes
-capitalize
-----------
-Capitalizes the first letter of a string or array of strings.
-Requires either a single string or an array as an input.
+#### Public Classes
+* `stdlib`: Most of stdlib's features are automatically loaded by Puppet. To use standardized run stages in Puppet, declare this class in your manifest with `include stdlib`.
-- *Type*: rvalue
+ When declared, stdlib declares all other classes in the module. The only other class currently included in the module is `stdlib::stages`.
-chomp
------
-Removes the record separator from the end of a string or an array of
-strings, for example `hello\n` becomes `hello`.
-Requires a single string or array as an input.
+ The stdlib class has no parameters.
+#### Private Classes
-- *Type*: rvalue
+* `stdlib::stages`: This class manages a standard set of run stages for Puppet. It is managed by the stdlib class and should not be declared independently.
-chop
-----
-Returns a new string with the last character removed. If the string ends
-with `\r\n`, both characters are removed. Applying chop to an empty
-string returns an empty string. If you wish to merely remove record
-separators then you should use the `chomp` function.
-Requires a string or array of strings as input.
+ The `stdlib::stages` class declares various run stages for deploying infrastructure, language runtimes, and application layers. The high level stages are (in order):
+ * setup
+ * main
+ * runtime
+ * setup_infra
+ * deploy_infra
+ * setup_app
+ * deploy_app
+ * deploy
-- *Type*: rvalue
+ Sample usage:
-concat
-------
-Appends the contents of array 2 onto array 1.
+ ```
+ node default {
+ include stdlib
+ class { java: stage => 'runtime' }
+ }
+ ```
-*Example:*
+### Functions
- concat(['1','2','3'],['4','5','6'])
+* `abs`: Returns the absolute value of a number; for example, '-34.56' becomes '34.56'. Takes a single integer and float value as an argument. *Type*: rvalue
-Would result in:
+* `any2array`: This converts any object to an array containing that object. Empty argument lists are converted to an empty array. Arrays are left untouched. Hashes are converted to arrays of alternating keys and values. *Type*: rvalue
- ['1','2','3','4','5','6']
+* `base64`: Converts a string to and from base64 encoding.
+Requires an action ('encode', 'decode') and either a plain or base64-encoded
+string. *Type*: rvalue
- concat(['1','2','3'],'4')
+* `bool2num`: Converts a boolean to a number. Converts values:
+ * 'false', 'f', '0', 'n', and 'no' to 0.
+ * 'true', 't', '1', 'y', and 'yes' to 1.
+ Requires a single boolean or string as an input. *Type*: rvalue
-Would result in:
+* `capitalize`: Capitalizes the first letter of a string or array of strings.
+Requires either a single string or an array as an input. *Type*: rvalue
- ['1','2','3','4']
+* `chomp`: Removes the record separator from the end of a string or an array of
+strings; for example, 'hello\n' becomes 'hello'. Requires a single string or array as an input. *Type*: rvalue
-- *Type*: rvalue
+* `chop`: Returns a new string with the last character removed. If the string ends with '\r\n', both characters are removed. Applying `chop` to an empty string returns an empty string. If you want to merely remove record separators, then you should use the `chomp` function. Requires a string or an array of strings as input. *Type*: rvalue
-count
------
-Takes an array as first argument and an optional second argument.
-Count the number of elements in array that matches second argument.
-If called with only an array it counts the number of elements that are not nil/undef.
+* `concat`: Appends the contents of array 2 onto array 1. For example, `concat(['1','2','3'],'4')` results in: ['1','2','3','4']. *Type*: rvalue
+* `count`: Takes an array as first argument and an optional second argument. Count the number of elements in array that matches second argument. If called with only an array, it counts the number of elements that are **not** nil/undef. *Type*: rvalue
-- *Type*: rvalue
+* `defined_with_params`: Takes a resource reference and an optional hash of attributes. Returns 'true' if a resource with the specified attributes has already been added to the catalog. Returns 'false' otherwise.
-deep_merge
-----------
-Recursively merges two or more hashes together and returns the resulting hash.
+ ```
+ user { 'dan':
+ ensure => present,
+ }
-*Example:*
+ if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
+ user { 'dan': ensure => present, }
+ }
+ ```
+
+ *Type*: rvalue
- $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }
- $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } }
- $merged_hash = deep_merge($hash1, $hash2)
- # The resulting hash is equivalent to:
- # $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } }
+* `delete`: Deletes all instances of a given element from an array, substring from a
+string, or key from a hash. For example, `delete(['a','b','c','b'], 'b')` returns ['a','c']; `delete('abracadabra', 'bra')` returns 'acada'. *Type*: rvalue
-When there is a duplicate key that is a hash, they are recursively merged.
-When there is a duplicate key that is not a hash, the key in the rightmost hash will "win."
+* `delete_at`: Deletes a determined indexed value from an array. For example, `delete_at(['a','b','c'], 1)` returns ['a','c']. *Type*: rvalue
-- *Type*: rvalue
+* `delete_values`: Deletes all instances of a given value from a hash. For example, `delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B')` returns {'a'=>'A','c'=>'C','B'=>'D'} *Type*: rvalue
-defined_with_params
--------------------
-Takes a resource reference and an optional hash of attributes.
+* `delete_undef_values`: Deletes all instances of the undef value from an array or hash. For example, `$hash = delete_undef_values({a=>'A', b=>'', c=>undef, d => false})` returns {a => 'A', b => '', d => false}. *Type*: rvalue
-Returns true if a resource with the specified attributes has already been added
-to the catalog, and false otherwise.
-
- user { 'dan':
- ensure => present,
- }
-
- if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
- user { 'dan': ensure => present, }
- }
-
-
-- *Type*: rvalue
-
-delete
-------
-Deletes all instances of a given element from an array, substring from a
-string, or key from a hash.
-
-*Examples:*
-
- delete(['a','b','c','b'], 'b')
- Would return: ['a','c']
-
- delete({'a'=>1,'b'=>2,'c'=>3}, 'b')
- Would return: {'a'=>1,'c'=>3}
-
- delete('abracadabra', 'bra')
- Would return: 'acada'
-
-
-- *Type*: rvalue
-
-delete_at
----------
-Deletes a determined indexed value from an array.
-
-*Examples:*
-
- delete_at(['a','b','c'], 1)
-
-Would return: ['a','c']
-
-
-- *Type*: rvalue
-
-delete_values
--------------
-Deletes all instances of a given value from a hash.
-
-*Examples:*
-
- delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B')
-
-Would return: {'a'=>'A','c'=>'C','B'=>'D'}
-
-
-- *Type*: rvalue
-
-delete_undef_values
--------------------
-Deletes all instances of the undef value from an array or hash.
-
-*Examples:*
-
- $hash = delete_undef_values({a=>'A', b=>'', c=>undef, d => false})
-
-Would return: {a => 'A', b => '', d => false}
-
- $array = delete_undef_values(['A','',undef,false])
-
-Would return: ['A','',false]
-
-- *Type*: rvalue
-
-difference
-----------
-This function returns the difference between two arrays.
+* `difference`: Returns the difference between two arrays.
The returned array is a copy of the original array, removing any items that
-also appear in the second array.
-
-*Examples:*
-
- difference(["a","b","c"],["b","c","d"])
-
-Would return: ["a"]
-
-dirname
--------
-Returns the `dirname` of a path.
-
-*Examples:*
-
- dirname('/path/to/a/file.ext')
-
-Would return: '/path/to/a'
-
-downcase
---------
-Converts the case of a string or all strings in an array to lower case.
-
-
-- *Type*: rvalue
-
-empty
------
-Returns true if the variable is empty.
-
-
-- *Type*: rvalue
-
-ensure_packages
----------------
-Takes a list of packages and only installs them if they don't already exist.
-It optionally takes a hash as a second parameter that will be passed as the
-third argument to the ensure_resource() function.
-
-
-- *Type*: statement
-
-ensure_resource
----------------
-Takes a resource type, title, and a list of attributes that describe a
-resource.
-
- user { 'dan':
- ensure => present,
- }
-
-This example only creates the resource if it does not already exist:
-
- ensure_resource('user', 'dan', {'ensure' => 'present' })
-
-If the resource already exists but does not match the specified parameters,
-this function will attempt to recreate the resource leading to a duplicate
-resource definition error.
-
-An array of resources can also be passed in and each will be created with
-the type and parameters specified if it doesn't already exist.
-
- ensure_resource('user', ['dan','alex'], {'ensure' => 'present'})
-
-
-
-- *Type*: statement
-
-file_line
----------
-Ensures that a given line is contained within a file. The implementation
-matches the full line, including whitespace at the beginning and end. If
-the line is not contained in the given file, Puppet will add the line to
-ensure the desired state. Multiple resources may be declared to manage
-multiple lines in the same file.
-
-*Examples:*
-
- file_line { 'sudo_rule':
- path => '/etc/sudoers',
- line => '%sudo ALL=(ALL) ALL',
- }
- file_line { 'sudo_rule_nopw':
- path => '/etc/sudoers',
- line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
- }
-
-In this example, Puppet will ensure both of the specified lines are
-contained in the file /etc/sudoers.
-
-*Parameters within `file_line`:*
-
-**`after`**
-
-An optional value used to specify the line after which we will add any new
-lines. (Existing lines are added in place)
-
-**`line`**
-
-The line to be appended to the file located by the path parameter.
-
-**`match`**
-
-An optional regular expression to run against existing lines in the file;
-if a match is found, we replace that line rather than adding a new line.
-
-**`multiple`**
-
-An optional value to determine if match can change multiple lines.
-
-**`name`**
-
-An arbitrary name used as the identity of the resource.
-
-**`path`**
-
-The file Puppet will ensure contains the line specified by the line parameter.
-
-- *Type*: resource
-
-flatten
--------
-This function flattens any deeply nested arrays and returns a single flat array
-as a result.
-
-*Examples:*
-
- flatten(['a', ['b', ['c']]])
-
-Would return: ['a','b','c']
-
-
-- *Type*: rvalue
-
-floor
------
-Returns the largest integer less or equal to the argument.
-Takes a single numeric value as an argument.
-
-
-- *Type*: rvalue
-
-fqdn_rotate
------------
-Rotates an array a random number of times based on a nodes fqdn.
-
-
-- *Type*: rvalue
-
-get_module_path
----------------
-Returns the absolute path of the specified module for the current
-environment.
-
-Example:
- $module_path = get_module_path('stdlib')
-
-
-- *Type*: rvalue
-
-getparam
---------
-Takes a resource reference and name of the parameter and
-returns value of resource's parameter.
-
-*Examples:*
-
- define example_resource($param) {
- }
-
- example_resource { "example_resource_instance":
- param => "param_value"
- }
-
- getparam(Example_resource["example_resource_instance"], "param")
-
-Would return: param_value
-
-
-- *Type*: rvalue
-
-getvar
-------
-Lookup a variable in a remote namespace.
-
-For example:
-
- $foo = getvar('site::data::foo')
- # Equivalent to $foo = $site::data::foo
-
-This is useful if the namespace itself is stored in a string:
-
- $datalocation = 'site::data'
- $bar = getvar("${datalocation}::bar")
- # Equivalent to $bar = $site::data::bar
-
-
-- *Type*: rvalue
-
-grep
-----
-This function searches through an array and returns any elements that match
-the provided regular expression.
-
-*Examples:*
-
- grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
-
-Would return:
-
- ['aaa','aaaddd']
-
-
-- *Type*: rvalue
-
-has_interface_with
-------------------
-Returns boolean based on kind and value:
-* macaddress
-* netmask
-* ipaddress
-* network
-
-*Examples:*
-
- has_interface_with("macaddress", "x:x:x:x:x:x")
- has_interface_with("ipaddress", "127.0.0.1") => true
-
-etc.
-
-If no "kind" is given, then the presence of the interface is checked:
-
- has_interface_with("lo") => true
-
-
-- *Type*: rvalue
-
-has_ip_address
---------------
-Returns true if the client has the requested IP address on some interface.
-
-This function iterates through the 'interfaces' fact and checks the
-'ipaddress_IFACE' facts, performing a simple string comparison.
+also appear in the second array. For example, `difference(["a","b","c"],["b","c","d"])` returns ["a"].
+* `dirname`: Returns the `dirname` of a path. For example, `dirname('/path/to/a/file.ext')` returns '/path/to/a'.
-- *Type*: rvalue
+* `downcase`: Converts the case of a string or of all strings in an array to lowercase. *Type*: rvalue
-has_ip_network
---------------
-Returns true if the client has an IP address within the requested network.
+* `empty`: Returns 'true' if the variable is empty. *Type*: rvalue
-This function iterates through the 'interfaces' fact and checks the
-'network_IFACE' facts, performing a simple string comparision.
+* `ensure_packages`: Takes a list of packages and only installs them if they don't already exist. It optionally takes a hash as a second parameter to be passed as the third argument to the `ensure_resource()` function. *Type*: statement
+* `ensure_resource`: Takes a resource type, title, and a list of attributes that describe a resource.
-- *Type*: rvalue
+ ```
+ user { 'dan':
+ ensure => present,
+ }
+ ```
-has_key
--------
-Determine if a hash has a certain key value.
+ This example only creates the resource if it does not already exist:
-Example:
+ `ensure_resource('user', 'dan', {'ensure' => 'present' })`
- $my_hash = {'key_one' => 'value_one'}
- if has_key($my_hash, 'key_two') {
- notice('we will not reach here')
- }
- if has_key($my_hash, 'key_one') {
- notice('this will be printed')
- }
+ If the resource already exists, but does not match the specified parameters, this function attempts to recreate the resource, leading to a duplicate resource definition error.
+ An array of resources can also be passed in, and each will be created with the type and parameters specified if it doesn't already exist.
+ `ensure_resource('user', ['dan','alex'], {'ensure' => 'present'})`
-- *Type*: rvalue
+ *Type*: statement
-hash
-----
-This function converts an array into a hash.
+* `file_line`: This resource ensures that a given line is contained within a file. You can also use match to replace existing lines.
-*Examples:*
+ *Example:*
+
+ ```
+ file_line { 'sudo_rule':
+ path => '/etc/sudoers',
+ line => '%sudo ALL=(ALL) ALL',
+ }
- hash(['a',1,'b',2,'c',3])
+ file_line { 'change_mount':
+ path => '/etc/fstab',
+ line => '10.0.0.1:/vol/data /opt/data nfs defaults 0 0',
+ match => '^172.16.17.2:/vol/old',
+ }
+ ```
+
+ *Type*: resource
-Would return: {'a'=>1,'b'=>2,'c'=>3}
+* `flatten`: This function flattens any deeply nested arrays and returns a single flat array as a result. For example, `flatten(['a', ['b', ['c']]])` returns ['a','b','c']. *Type*: rvalue
+* `floor`: Returns the largest integer less than or equal to the argument.
+Takes a single numeric value as an argument. *Type*: rvalue
-- *Type*: rvalue
+* `fqdn_rotate`: Rotates an array a random number of times based on a node's fqdn. *Type*: rvalue
-intersection
------------
-This function returns an array an intersection of two.
+* `get_module_path`: Returns the absolute path of the specified module for the current environment.
-*Examples:*
+ `$module_path = get_module_path('stdlib')`
- intersection(["a","b","c"],["b","c","d"])
+ *Type*: rvalue
-Would return: ["b","c"]
+* `getparam`: Takes a resource reference and the name of the parameter and
+returns the value of the resource's parameter. For example, the following code returns 'param_value'.
-is_array
---------
-Returns true if the variable passed to this function is an array.
+ *Example:*
-- *Type*: rvalue
+ ```
+ define example_resource($param) {
+ }
-is_bool
---------
-Returns true if the variable passed to this function is a boolean.
+ example_resource { "example_resource_instance":
+ param => "param_value"
+ }
-- *Type*: rvalue
+ getparam(Example_resource["example_resource_instance"], "param")
+ ```
-is_domain_name
---------------
-Returns true if the string passed to this function is a syntactically correct domain name.
+ *Type*: rvalue
-- *Type*: rvalue
+* `getvar`: Lookup a variable in a remote namespace.
-is_float
---------
-Returns true if the variable passed to this function is a float.
+ For example:
-- *Type*: rvalue
+ ```
+ $foo = getvar('site::data::foo')
+ # Equivalent to $foo = $site::data::foo
+ ```
-is_function_available
----------------------
-This function accepts a string as an argument, determines whether the
-Puppet runtime has access to a function by that name. It returns a
-true if the function exists, false if not.
+ This is useful if the namespace itself is stored in a string:
-- *Type*: rvalue
+ ```
+ $datalocation = 'site::data'
+ $bar = getvar("${datalocation}::bar")
+ # Equivalent to $bar = $site::data::bar
+ ```
-is_hash
--------
-Returns true if the variable passed to this function is a hash.
+ *Type*: rvalue
-- *Type*: rvalue
+* `grep`: This function searches through an array and returns any elements that match the provided regular expression. For example, `grep(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['aaa','aaaddd']. *Type*: rvalue
-is_integer
-----------
-Returns true if the variable returned to this string is an integer.
+* `has_interface_with`: Returns boolean based on kind and value:
+ * macaddress
+ * netmask
+ * ipaddress
+ * network
-- *Type*: rvalue
+ *Examples:*
-is_ip_address
--------------
-Returns true if the string passed to this function is a valid IP address.
-
-- *Type*: rvalue
-
-is_mac_address
---------------
-Returns true if the string passed to this function is a valid mac address.
-
-- *Type*: rvalue
-
-is_numeric
-----------
-Returns true if the variable passed to this function is a number.
-
-- *Type*: rvalue
-
-is_string
----------
-Returns true if the variable passed to this function is a string.
-
-- *Type*: rvalue
-
-join
-----
-This function joins an array into a string using a separator.
-
-*Examples:*
-
- join(['a','b','c'], ",")
-
-Would result in: "a,b,c"
-
-- *Type*: rvalue
-
-join_keys_to_values
--------------------
-This function joins each key of a hash to that key's corresponding value with a
-separator. Keys and values are cast to strings. The return value is an array in
-which each element is one joined key/value pair.
-
-*Examples:*
-
- join_keys_to_values({'a'=>1,'b'=>2}, " is ")
-
-Would result in: ["a is 1","b is 2"]
-
-- *Type*: rvalue
-
-keys
-----
-Returns the keys of a hash as an array.
-
-- *Type*: rvalue
-
-loadyaml
---------
-Load a YAML file containing an array, string, or hash, and return the data
-in the corresponding native data type.
-
-For example:
-
- $myhash = loadyaml('/etc/puppet/data/myhash.yaml')
-
-
-- *Type*: rvalue
-
-lstrip
-------
-Strips leading spaces to the left of a string.
-
-- *Type*: rvalue
-
-max
----
-Returns the highest value of all arguments.
-Requires at least one argument.
-
-- *Type*: rvalue
-
-member
-------
-This function determines if a variable is a member of an array.
-
-*Examples:*
-
- member(['a','b'], 'b')
-
-Would return: true
-
- member(['a','b'], 'c')
-
-Would return: false
-
-- *Type*: rvalue
-
-merge
------
-Merges two or more hashes together and returns the resulting hash.
-
-For example:
-
- $hash1 = {'one' => 1, 'two' => 2}
- $hash2 = {'two' => 'dos', 'three' => 'tres'}
- $merged_hash = merge($hash1, $hash2)
- # The resulting hash is equivalent to:
- # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'}
-
-When there is a duplicate key, the key in the rightmost hash will "win."
-
-- *Type*: rvalue
-
-min
----
-Returns the lowest value of all arguments.
-Requires at least one argument.
-
-- *Type*: rvalue
-
-num2bool
---------
-This function converts a number or a string representation of a number into a
-true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0
-become true.
-
-- *Type*: rvalue
-
-parsejson
----------
-This function accepts JSON as a string and converts into the correct Puppet
-structure.
-
-- *Type*: rvalue
-
-parseyaml
----------
-This function accepts YAML as a string and converts it into the correct
-Puppet structure.
-
-- *Type*: rvalue
-
-pick
-----
-This function is similar to a coalesce function in SQL in that it will return
-the first value in a list of values that is not undefined or an empty string
-(two things in Puppet that will return a boolean false value). Typically,
-this function is used to check for a value in the Puppet Dashboard/Enterprise
-Console, and failover to a default value like the following:
-
- $real_jenkins_version = pick($::jenkins_version, '1.449')
-
-The value of $real_jenkins_version will first look for a top-scope variable
-called 'jenkins_version' (note that parameters set in the Puppet Dashboard/
-Enterprise Console are brought into Puppet as top-scope variables), and,
-failing that, will use a default value of 1.449.
-
-- *Type*: rvalue
-
-pick_default
-------------
-This function is similar to a coalesce function in SQL in that it will return
-the first value in a list of values that is not undefined or an empty string
-(two things in Puppet that will return a boolean false value). If no value is
-found, it will return the last argument.
-
-Typically, this function is used to check for a value in the Puppet
-Dashboard/Enterprise Console, and failover to a default value like the
-following:
-
- $real_jenkins_version = pick_default($::jenkins_version, '1.449')
-
-The value of $real_jenkins_version will first look for a top-scope variable
-called 'jenkins_version' (note that parameters set in the Puppet Dashboard/
-Enterprise Console are brought into Puppet as top-scope variables), and,
-failing that, will use a default value of 1.449.
-
-Note that, contrary to the pick() function, the pick_default does not fail if
-all arguments are empty. This allows pick_default to use an empty value as
-default.
-
-- *Type*: rvalue
-
-prefix
-------
-This function applies a prefix to all elements in an array.
-
-*Examples:*
-
- prefix(['a','b','c'], 'p')
-
-Will return: ['pa','pb','pc']
-
-- *Type*: rvalue
-
-range
------
-When given range in the form of (start, stop) it will extrapolate a range as
-an array.
-
-*Examples:*
-
- range("0", "9")
-
-Will return: [0,1,2,3,4,5,6,7,8,9]
-
- range("00", "09")
-
-Will return: [0,1,2,3,4,5,6,7,8,9] - Zero padded strings are converted to
-integers automatically
-
- range("a", "c")
-
-Will return: ["a","b","c"]
-
- range("host01", "host10")
-
-Will return: ["host01", "host02", ..., "host09", "host10"]
-
-Passing a third argument will cause the generated range to step by that
-interval, e.g.
-
- range("0", "9", "2")
-
-Will return: [0,2,4,6,8]
-
-- *Type*: rvalue
-
-reject
-------
-This function searches through an array and rejects all elements that match
-the provided regular expression.
-
-*Examples:*
-
- reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
-
-Would return:
-
- ['bbb','ccc']
-
-
-- *Type*: rvalue
-
-reverse
--------
-Reverses the order of a string or array.
-
-- *Type*: rvalue
-
-rstrip
-------
-Strips leading spaces to the right of the string.
-
-- *Type*: rvalue
-
-shuffle
--------
-Randomizes the order of a string or array elements.
-
-- *Type*: rvalue
-
-size
-----
-Returns the number of elements in a string or array.
-
-- *Type*: rvalue
-
-sort
-----
-Sorts strings and arrays lexically.
-
-- *Type*: rvalue
-
-squeeze
--------
-Returns a new string where runs of the same character that occur in this set
-are replaced by a single character.
-
-- *Type*: rvalue
-
-str2bool
---------
-This converts a string to a boolean. This attempts to convert strings that
-contain things like: y, 1, t, true to 'true' and strings that contain things
-like: 0, f, n, false, no to 'false'.
-
-
-- *Type*: rvalue
-
-str2saltedsha512
-----------------
-This converts a string to a salted-SHA512 password hash (which is used for
-OS X versions >= 10.7). Given any simple string, you will get a hex version
-of a salted-SHA512 password hash that can be inserted into your Puppet
-manifests as a valid password attribute.
-
-
-- *Type*: rvalue
-
-strftime
---------
-This function returns formatted time.
-
-*Examples:*
-
-To return the time since epoch:
-
- strftime("%s")
-
-To return the date:
-
- strftime("%Y-%m-%d")
-
-*Format meaning:*
-
- %a - The abbreviated weekday name (``Sun'')
- %A - The full weekday name (``Sunday'')
- %b - The abbreviated month name (``Jan'')
- %B - The full month name (``January'')
- %c - The preferred local date and time representation
- %C - Century (20 in 2009)
- %d - Day of the month (01..31)
- %D - Date (%m/%d/%y)
- %e - Day of the month, blank-padded ( 1..31)
- %F - Equivalent to %Y-%m-%d (the ISO 8601 date format)
- %h - Equivalent to %b
- %H - Hour of the day, 24-hour clock (00..23)
- %I - Hour of the day, 12-hour clock (01..12)
- %j - Day of the year (001..366)
- %k - hour, 24-hour clock, blank-padded ( 0..23)
- %l - hour, 12-hour clock, blank-padded ( 0..12)
- %L - Millisecond of the second (000..999)
- %m - Month of the year (01..12)
- %M - Minute of the hour (00..59)
- %n - Newline (\n)
- %N - Fractional seconds digits, default is 9 digits (nanosecond)
- %3N millisecond (3 digits)
- %6N microsecond (6 digits)
- %9N nanosecond (9 digits)
- %p - Meridian indicator (``AM'' or ``PM'')
- %P - Meridian indicator (``am'' or ``pm'')
- %r - time, 12-hour (same as %I:%M:%S %p)
- %R - time, 24-hour (%H:%M)
- %s - Number of seconds since 1970-01-01 00:00:00 UTC.
- %S - Second of the minute (00..60)
- %t - Tab character ( )
- %T - time, 24-hour (%H:%M:%S)
- %u - Day of the week as a decimal, Monday being 1. (1..7)
- %U - Week number of the current year,
- starting with the first Sunday as the first
- day of the first week (00..53)
- %v - VMS date (%e-%b-%Y)
- %V - Week number of year according to ISO 8601 (01..53)
- %W - Week number of the current year,
- starting with the first Monday as the first
- day of the first week (00..53)
- %w - Day of the week (Sunday is 0, 0..6)
- %x - Preferred representation for the date alone, no time
- %X - Preferred representation for the time alone, no date
- %y - Year without a century (00..99)
- %Y - Year with century
- %z - Time zone as hour offset from UTC (e.g. +0900)
- %Z - Time zone name
- %% - Literal ``%'' character
-
-
-- *Type*: rvalue
-
-strip
------
-This function removes leading and trailing whitespace from a string or from
-every string inside an array.
-
-*Examples:*
-
- strip(" aaa ")
-
-Would result in: "aaa"
-
-
-- *Type*: rvalue
-
-suffix
-------
-This function applies a suffix to all elements in an array.
-
-*Examples:*
-
- suffix(['a','b','c'], 'p')
-
-Will return: ['ap','bp','cp']
-
-
-- *Type*: rvalue
-
-swapcase
---------
-This function will swap the existing case of a string.
-
-*Examples:*
-
- swapcase("aBcD")
-
-Would result in: "AbCd"
-
-
-- *Type*: rvalue
-
-time
-----
-This function will return the current time since epoch as an integer.
-
-*Examples:*
-
- time()
-
-Will return something like: 1311972653
-
-
-- *Type*: rvalue
-
-to_bytes
---------
-Converts the argument into bytes, for example 4 kB becomes 4096.
-Takes a single string value as an argument.
-
-
-- *Type*: rvalue
-
-type
-----
-Returns the type when passed a variable. Type can be one of:
-
-* string
-* array
-* hash
-* float
-* integer
-* boolean
-
-
-- *Type*: rvalue
-
-union
------
-This function returns a union of two arrays.
-
-*Examples:*
-
- union(["a","b","c"],["b","c","d"])
-
-Would return: ["a","b","c","d"]
-
-
-unique
-------
-This function will remove duplicates from strings and arrays.
-
-*Examples:*
-
- unique("aabbcc")
+ ```
+ has_interface_with("macaddress", "x:x:x:x:x:x")
+ has_interface_with("ipaddress", "127.0.0.1") => true
+ ```
+
+ If no kind is given, then the presence of the interface is checked:
-Will return:
+ ```
+ has_interface_with("lo") => true
+ ```
- abc
+ *Type*: rvalue
-You can also use this with arrays:
+* `has_ip_address`: Returns true if the client has the requested IP address on some interface. This function iterates through the `interfaces` fact and checks the `ipaddress_IFACE` facts, performing a simple string comparison. *Type*: rvalue
- unique(["a","a","b","b","c","c"])
+* `has_ip_network`: Returns true if the client has an IP address within the requested network. This function iterates through the 'interfaces' fact and checks the 'network_IFACE' facts, performing a simple string comparision. *Type*: rvalue
-This returns:
+* `has_key`: Determine if a hash has a certain key value.
- ["a","b","c"]
+ *Example*:
+ ```
+ $my_hash = {'key_one' => 'value_one'}
+ if has_key($my_hash, 'key_two') {
+ notice('we will not reach here')
+ }
+ if has_key($my_hash, 'key_one') {
+ notice('this will be printed')
+ }
+ ```
+
+ *Type*: rvalue
-- *Type*: rvalue
+* `hash`: This function converts an array into a hash. For example, `hash(['a',1,'b',2,'c',3])` returns {'a'=>1,'b'=>2,'c'=>3}. *Type*: rvalue
-upcase
-------
-Converts a string or an array of strings to uppercase.
+* `intersection`: This function returns an array an intersection of two. For example, `intersection(["a","b","c"],["b","c","d"])` returns ["b","c"].
-*Examples:*
+* `is_array`: Returns 'true' if the variable passed to this function is an array. *Type*: rvalue
- upcase("abcd")
+* `is_bool`: Returns 'true' if the variable passed to this function is a boolean. *Type*: rvalue
-Will return:
+* `is_domain_name`: Returns 'true' if the string passed to this function is a syntactically correct domain name. *Type*: rvalue
- ABCD
+* `is_float`: Returns 'true' if the variable passed to this function is a float. *Type*: rvalue
+* `is_function_available`: This function accepts a string as an argument and determines whether the Puppet runtime has access to a function by that name. It returns 'true' if the function exists, 'false' if not. *Type*: rvalue
-- *Type*: rvalue
+* `is_hash`: Returns 'true' if the variable passed to this function is a hash. *Type*: rvalue
-uriescape
----------
-Urlencodes a string or array of strings.
-Requires either a single string or an array as an input.
+* `is_integer`: Returns 'true' if the variable returned to this string is an integer. *Type*: rvalue
+* `is_ip_address`: Returns 'true' if the string passed to this function is a valid IP address. *Type*: rvalue
-- *Type*: rvalue
+* `is_mac_address`: Returns 'true' if the string passed to this function is a valid MAC address. *Type*: rvalue
-validate_absolute_path
-----------------------
-Validate the string represents an absolute path in the filesystem. This function works
-for windows and unix style paths.
+* `is_numeric`: Returns 'true' if the variable passed to this function is a number. *Type*: rvalue
-The following values will pass:
+* `is_string`: Returns 'true' if the variable passed to this function is a string. *Type*: rvalue
- $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet"
- validate_absolute_path($my_path)
- $my_path2 = "/var/lib/puppet"
- validate_absolute_path($my_path2)
+* `join`: This function joins an array into a string using a separator. For example, `join(['a','b','c'], ",")` results in: "a,b,c". *Type*: rvalue
+* `join_keys_to_values`: This function joins each key of a hash to that key's corresponding value with a separator. Keys and values are cast to strings. The return value is an array in which each element is one joined key/value pair. For example, `join_keys_to_values({'a'=>1,'b'=>2}, " is ")` results in ["a is 1","b is 2"]. *Type*: rvalue
-The following values will fail, causing compilation to abort:
+* `keys`: Returns the keys of a hash as an array. *Type*: rvalue
- validate_absolute_path(true)
- validate_absolute_path([ 'var/lib/puppet', '/var/foo' ])
- validate_absolute_path([ '/var/lib/puppet', 'var/foo' ])
- $undefined = undef
- validate_absolute_path($undefined)
+* `loadyaml`: Load a YAML file containing an array, string, or hash, and return the data in the corresponding native data type. For example:
+ ```
+ $myhash = loadyaml('/etc/puppet/data/myhash.yaml')
+ ```
+ *Type*: rvalue
-- *Type*: statement
+* `lstrip`: Strips leading spaces to the left of a string. *Type*: rvalue
-validate_array
---------------
-Validate that all passed values are array data structures. Abort catalog
-compilation if any value fails this check.
+* `max`: Returns the highest value of all arguments. Requires at least one argument. *Type*: rvalue
-The following values will pass:
+* `member`: This function determines if a variable is a member of an array. For example, `member(['a','b'], 'b')` returns 'true', while `member(['a','b'], 'c')` returns 'false'. *Type*: rvalue
- $my_array = [ 'one', 'two' ]
- validate_array($my_array)
+* `merge`: Merges two or more hashes together and returns the resulting hash.
-The following values will fail, causing compilation to abort:
+ *Example*:
+
+ ```
+ $hash1 = {'one' => 1, 'two' => 2}
+ $hash2 = {'two' => 'dos', 'three' => 'tres'}
+ $merged_hash = merge($hash1, $hash2)
+ # The resulting hash is equivalent to:
+ # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'}
+ ```
+
+ When there is a duplicate key, the key in the rightmost hash "wins." *Type*: rvalue
- validate_array(true)
- validate_array('some_string')
- $undefined = undef
- validate_array($undefined)
+* `min`: Returns the lowest value of all arguments. Requires at least one argument. *Type*: rvalue
+* `num2bool`: This function converts a number or a string representation of a number into a true boolean. Zero or anything non-numeric becomes 'false'. Numbers greater than 0 become 'true'. *Type*: rvalue
+* `parsejson`: This function accepts JSON as a string and converts into the correct Puppet structure. *Type*: rvalue
-- *Type*: statement
+* `parseyaml`: This function accepts YAML as a string and converts it into the correct Puppet structure. *Type*: rvalue
-validate_augeas
----------------
-Perform validation of a string using an Augeas lens
-The first argument of this function should be a string to
-test, and the second argument should be the name of the Augeas lens to use.
-If Augeas fails to parse the string with the lens, the compilation will
-abort with a parse error.
+* `pick`: From a list of values, returns the first value that is not undefined or an empty string. Takes any number of arguments, and raises an error if all values are undefined or empty.
-A third argument can be specified, listing paths which should
-not be found in the file. The `$file` variable points to the location
-of the temporary file being tested in the Augeas tree.
+ ```
+ $real_jenkins_version = pick($::jenkins_version, '1.449')
+ ```
+
+ *Type*: rvalue
-For example, if you want to make sure your passwd content never contains
-a user `foo`, you could write:
+* `prefix`: This function applies a prefix to all elements in an array. For example, `prefix(['a','b','c'], 'p')` returns ['pa','pb','pc']. *Type*: rvalue
- validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo'])
-Or if you wanted to ensure that no users used the '/bin/barsh' shell,
-you could use:
+* `private`: This function sets the current class or definition as private.
+Calling the class or definition from outside the current module will fail. For example, `private()` called in class `foo::bar` outputs the following message if class is called from outside module `foo`:
- validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]']
+ ```
+ Class foo::bar is private
+ ```
+
+ You can specify the error message you want to use:
+
+ ```
+ private("You're not supposed to do that!")
+ ```
-If a fourth argument is specified, this will be the error message raised and
-seen by the user.
+ *Type*: statement
-A helpful error message can be returned like this:
+* `range`: When given range in the form of '(start, stop)', `range` extrapolates a range as an array. For example, `range("0", "9")` returns [0,1,2,3,4,5,6,7,8,9]. Zero-padded strings are converted to integers automatically, so `range("00", "09")` returns [0,1,2,3,4,5,6,7,8,9].
- validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas')
+ Non-integer strings are accepted; `range("a", "c")` returns ["a","b","c"], and `range("host01", "host10")` returns ["host01", "host02", ..., "host09", "host10"].
+
+ *Type*: rvalue
+* `reject`: This function searches through an array and rejects all elements that match the provided regular expression. For example, `reject(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['bbb','ccc']. *Type*: rvalue
+* `reverse`: Reverses the order of a string or array. *Type*: rvalue
-- *Type*: statement
+* `rstrip`: Strips leading spaces to the right of the string.*Type*: rvalue
-validate_bool
--------------
-Validate that all passed values are either true or false. Abort catalog
-compilation if any value fails this check.
+* `shuffle`: Randomizes the order of a string or array elements. *Type*: rvalue
-The following values will pass:
+* `size`: Returns the number of elements in a string or array. *Type*: rvalue
- $iamtrue = true
- validate_bool(true)
- validate_bool(true, true, false, $iamtrue)
+* `sort`: Sorts strings and arrays lexically. *Type*: rvalue
-The following values will fail, causing compilation to abort:
+* `squeeze`: Returns a new string where runs of the same character that occur in this set are replaced by a single character. *Type*: rvalue
- $some_array = [ true ]
- validate_bool("false")
- validate_bool("true")
- validate_bool($some_array)
+* `str2bool`: This converts a string to a boolean. This attempts to convert strings that contain values such as '1', 't', 'y', and 'yes' to 'true' and strings that contain values such as '0', 'f', 'n', and 'no' to 'false'. *Type*: rvalue
+* `str2saltedsha512`: This converts a string to a salted-SHA512 password hash, used for OS X versions >= 10.7. Given any string, this function returns a hex version of a salted-SHA512 password hash, which can be inserted into your Puppet
+manifests as a valid password attribute. *Type*: rvalue
+* `strftime`: This function returns formatted time. For example, `strftime("%s")` returns the time since epoch, and `strftime("%Y=%m-%d")` returns the date. *Type*: rvalue
-- *Type*: statement
+ *Format:*
+
+ * `%a`: The abbreviated weekday name ('Sun')
+ * `%A`: The full weekday name ('Sunday')
+ * `%b`: The abbreviated month name ('Jan')
+ * `%B`: The full month name ('January')
+ * `%c`: The preferred local date and time representation
+ * `%C`: Century (20 in 2009)
+ * `%d`: Day of the month (01..31)
+ * `%D`: Date (%m/%d/%y)
+ * `%e`: Day of the month, blank-padded ( 1..31)
+ * `%F`: Equivalent to %Y-%m-%d (the ISO 8601 date format)
+ * `%h`: Equivalent to %b
+ * `%H`: Hour of the day, 24-hour clock (00..23)
+ * `%I`: Hour of the day, 12-hour clock (01..12)
+ * `%j`: Day of the year (001..366)
+ * `%k`: Hour, 24-hour clock, blank-padded ( 0..23)
+ * `%l`: Hour, 12-hour clock, blank-padded ( 0..12)
+ * `%L`: Millisecond of the second (000..999)
+ * `%m`: Month of the year (01..12)
+ * `%M`: Minute of the hour (00..59)
+ * `%n`: Newline (\n)
+ * `%N`: Fractional seconds digits, default is 9 digits (nanosecond)
+ * `%3N`: Millisecond (3 digits)
+ * `%6N`: Microsecond (6 digits)
+ * `%9N`: Nanosecond (9 digits)
+ * `%p`: Meridian indicator ('AM' or 'PM')
+ * `%P`: Meridian indicator ('am' or 'pm')
+ * `%r`: Time, 12-hour (same as %I:%M:%S %p)
+ * `%R`: Time, 24-hour (%H:%M)
+ * `%s`: Number of seconds since 1970-01-01 00:00:00 UTC.
+ * `%S`: Second of the minute (00..60)
+ * `%t`: Tab character ( )
+ * `%T`: Time, 24-hour (%H:%M:%S)
+ * `%u`: Day of the week as a decimal, Monday being 1. (1..7)
+ * `%U`: Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
+ * `%v`: VMS date (%e-%b-%Y)
+ * `%V`: Week number of year according to ISO 8601 (01..53)
+ * `%W`: Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
+ * `%w`: Day of the week (Sunday is 0, 0..6)
+ * `%x`: Preferred representation for the date alone, no time
+ * `%X`: Preferred representation for the time alone, no date
+ * `%y`: Year without a century (00..99)
+ * `%Y`: Year with century
+ * `%z`: Time zone as hour offset from UTC (e.g. +0900)
+ * `%Z`: Time zone name
+ * `%%`: Literal '%' character
-validate_cmd
-------------
-Perform validation of a string with an external command.
-The first argument of this function should be a string to
-test, and the second argument should be a path to a test command
-taking a file as last argument. If the command, launched against
-a tempfile containing the passed string, returns a non-null value,
-compilation will abort with a parse error.
-If a third argument is specified, this will be the error message raised and
-seen by the user.
+* `strip`: This function removes leading and trailing whitespace from a string or from every string inside an array. For example, `strip(" aaa ")` results in "aaa". *Type*: rvalue
-A helpful error message can be returned like this:
+* `suffix`: This function applies a suffix to all elements in an array. For example, `suffix(['a','b','c'], 'p')` returns ['ap','bp','cp']. *Type*: rvalue
-Example:
+* `swapcase`: This function swaps the existing case of a string. For example, `swapcase("aBcD")` results in "AbCd". *Type*: rvalue
- validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
+* `time`: This function returns the current time since epoch as an integer. For example, `time()` returns something like '1311972653'. *Type*: rvalue
+
+* `to_bytes`: Converts the argument into bytes, for example 4 kB becomes 4096.
+Takes a single string value as an argument. *Type*: rvalue
+
+* `type`: Returns the type when passed a variable. Type can be a string, array, hash, float, integer, or boolean. *Type*: rvalue
+
+* `union`: This function returns a union of two arrays. For example, `union(["a","b","c"],["b","c","d"])` returns ["a","b","c","d"].
+* `unique`: This function removes duplicates from strings and arrays. For example, `unique("aabbcc")` returns 'abc'.
+You can also use this with arrays. For example, `unique(["a","a","b","b","c","c"])` returns ["a","b","c"]. *Type*: rvalue
-- *Type*: statement
+* `upcase`: Converts a string or an array of strings to uppercase. For example, `upcase("abcd")` returns 'ABCD'. *Type*: rvalue
-validate_hash
--------------
-Validate that all passed values are hash data structures. Abort catalog
-compilation if any value fails this check.
+* `uriescape`: Urlencodes a string or array of strings. Requires either a single string or an array as an input. *Type*: rvalue
-The following values will pass:
+* `validate_absolute_path`: Validate that the string represents an absolute path in the filesystem. This function works for Windows and Unix-style paths.
+ The following values will pass:
- $my_hash = { 'one' => 'two' }
- validate_hash($my_hash)
+ ```
+ $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet"
+ validate_absolute_path($my_path)
+ $my_path2 = "/var/lib/puppet"
+ validate_absolute_path($my_path2)
+ ```
-The following values will fail, causing compilation to abort:
+ The following values will fail, causing compilation to abort:
+
+ ```
+ validate_absolute_path(true)
+ validate_absolute_path([ 'var/lib/puppet', '/var/foo' ])
+ validate_absolute_path([ '/var/lib/puppet', 'var/foo' ])
+ $undefined = undef
+ validate_absolute_path($undefined)
+ ```
+
+ *Type*: statement
+
+* `validate_array`: Validate that all passed values are array data structures. Abort catalog compilation if any value fails this check.
+
+ The following values will pass:
+
+ ```
+ $my_array = [ 'one', 'two' ]
+ validate_array($my_array)
+ ```
+
+ The following values will fail, causing compilation to abort:
+
+ ```
+ validate_array(true)
+ validate_array('some_string')
+ $undefined = undef
+ validate_array($undefined)
+ ```
+
+ *Type*: statement
+
+* `validate_augeas`: Performs validation of a string using an Augeas lens.
+The first argument of this function should be the string to test, and the second argument should be the name of the Augeas lens to use. If Augeas fails to parse the string with the lens, the compilation aborts with a parse error.
+
+ A third optional argument lists paths which should **not** be found in the file. The `$file` variable points to the location of the temporary file being tested in the Augeas tree.
+
+ For example, to make sure your passwd content never contains user `foo`:
- validate_hash(true)
- validate_hash('some_string')
- $undefined = undef
- validate_hash($undefined)
+ ```
+ validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo'])
+ ```
+
+ To ensure that no users use the '/bin/barsh' shell:
+ ```
+ validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]']
+ ```
+
+ You can pass a fourth argument as the error message raised and shown to the user:
+ ```
+ validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas')
+ ```
-- *Type*: statement
+ *Type*: statement
-validate_ipv4_address
----------------------
-Validate that all values passed are valid IPv4 addresses.
-Fail compilation if any value fails this check.
+* `validate_bool`: Validate that all passed values are either true or false. Abort catalog compilation if any value fails this check.
-The following values will pass:
+ The following values will pass:
+
+ ```
+ $iamtrue = true
+ validate_bool(true)
+ validate_bool(true, true, false, $iamtrue)
+ ```
+
+ The following values will fail, causing compilation to abort:
- $my_ip = "1.2.3.4"
- validate_ipv4_address($my_ip)
- validate_bool("8.8.8.8", "172.16.0.1", $my_ip)
+ ```
+ $some_array = [ true ]
+ validate_bool("false")
+ validate_bool("true")
+ validate_bool($some_array)
+ ```
-The following values will fail, causing compilation to abort:
+ *Type*: statement
- $some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ]
- validate_ipv4_address($some_array)
+* `validate_cmd`: Performs validation of a string with an external command. The first argument of this function should be the string to test, and the second argument should be the path to a test command taking a file as last argument. If the command, launched against a tempfile containing the passed string, returns a non-null value, compilation aborts with a parse error.
-- *Type*: statement
+ You can pass a third argument as the error message raised and shown to the user:
-validate_ipv6_address
----------------------
- Validate that all values passed are valid IPv6 addresses.
-Fail compilation if any value fails this check.
+ ```
+ validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
+ ```
+
+ *Type*: statement
-The following values will pass:
+* `validate_hash`: Validates that all passed values are hash data structures. Abort catalog compilation if any value fails this check.
- $my_ip = "3ffe:505:2"
- validate_ipv6_address(1)
- validate_ipv6_address($my_ip)
- validate_bool("fe80::baf6:b1ff:fe19:7507", $my_ip)
+ The following values will pass:
-The following values will fail, causing compilation to abort:
+ ```
+ $my_hash = { 'one' => 'two' }
+ validate_hash($my_hash)
+ ```
- $some_array = [ true, false, "garbage string", "1.2.3.4" ]
- validate_ipv6_address($some_array)
+ The following values will fail, causing compilation to abort:
-- *Type*: statement
+ ```
+ validate_hash(true)
+ validate_hash('some_string')
+ $undefined = undef
+ validate_hash($undefined)
+ ```
+
+ *Type*: statement
-validate_re
------------
-Perform simple validation of a string against one or more regular
-expressions. The first argument of this function should be a string to
+* `validate_re`: Performs simple validation of a string against one or more regular expressions. The first argument of this function should be the string to
test, and the second argument should be a stringified regular expression
-(without the // delimiters) or an array of regular expressions. If none
-of the regular expressions match the string passed in, compilation will
-abort with a parse error.
-
-If a third argument is specified, this will be the error message raised and
-seen by the user.
+(without the // delimiters) or an array of regular expressions. If none
+of the regular expressions match the string passed in, compilation aborts with a parse error.
-The following strings will validate against the regular expressions:
+ You can pass a third argument as the error message raised and shown to the user.
- validate_re('one', '^one$')
- validate_re('one', [ '^one', '^two' ])
+ The following strings validate against the regular expressions:
-The following strings will fail to validate, causing compilation to abort:
+ ```
+ validate_re('one', '^one$')
+ validate_re('one', [ '^one', '^two' ])
+ ```
- validate_re('one', [ '^two', '^three' ])
+ The following string fails to validate, causing compilation to abort:
-A helpful error message can be returned like this:
+ ```
+ validate_re('one', [ '^two', '^three' ])
+ ```
- validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
+ To set the error message:
+
+ ```
+ validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
+ ```
+ *Type*: statement
+* `validate_slength`: Validates that the first argument is a string (or an array of strings), and is less than or equal to the length of the second argument. It fails if the first argument is not a string or array of strings, or if arg 2 is not convertable to a number.
-- *Type*: statement
+ The following values pass:
+
+ ```
+ validate_slength("discombobulate",17)
+ validate_slength(["discombobulate","moo"],17)
+ ```
+
+ The following values fail:
-validate_slength
-----------------
-Validate that the first argument is a string (or an array of strings), and
-less/equal to than the length of the second argument. An optional third
-parameter can be given a the minimum length. It fails if the first
-argument is not a string or array of strings, and if arg 2 and arg 3 are
-not convertable to a number.
+ ```
+ validate_slength("discombobulate",1)
+ validate_slength(["discombobulate","thermometer"],5)
+ ```
+
+ *Type*: statement
-The following values will pass:
+* `validate_string`: Validates that all passed values are string data structures. Aborts catalog compilation if any value fails this check.
- validate_slength("discombobulate",17)
- validate_slength(["discombobulate","moo"],17)
- validate_slength(["discombobulate","moo"],17,3)
+ The following values pass:
-The following values will not:
+ ```
+ $my_string = "one two"
+ validate_string($my_string, 'three')
+ ```
- validate_slength("discombobulate",1)
- validate_slength(["discombobulate","thermometer"],5)
- validate_slength(["discombobulate","moo"],17,10)
+ The following values fail, causing compilation to abort:
-- *Type*: statement
+ ```
+ validate_string(true)
+ validate_string([ 'some', 'array' ])
+ $undefined = undef
+ validate_string($undefined)
+ ```
-validate_string
----------------
-Validate that all passed values are string data structures. Abort catalog
-compilation if any value fails this check.
+ *Type*: statement
-The following values will pass:
+* `values`: When given a hash, this function returns the values of that hash.
- $my_string = "one two"
- validate_string($my_string, 'three')
+ *Examples:*
-The following values will fail, causing compilation to abort:
+ ```
+ $hash = {
+ 'a' => 1,
+ 'b' => 2,
+ 'c' => 3,
+ }
+ values($hash)
+ ```
- validate_string(true)
- validate_string([ 'some', 'array' ])
- $undefined = undef
- validate_string($undefined)
+ The example above returns [1,2,3].
+ *Type*: rvalue
-- *Type*: statement
+* `values_at`: Finds value inside an array based on location. The first argument is the array you want to analyze, and the second element can be a combination of:
-values
-------
-When given a hash this function will return the values of that hash.
+ * A single numeric index
+ * A range in the form of 'start-stop' (eg. 4-9)
+ * An array combining the above
-*Examples:*
+ For example, `values_at(['a','b','c'], 2)` returns ['c']; `values_at(['a','b','c'], ["0-1"])` returns ['a','b']; and `values_at(['a','b','c','d','e'], [0, "2-3"])` returns ['a','c','d'].
- $hash = {
- 'a' => 1,
- 'b' => 2,
- 'c' => 3,
- }
- values($hash)
+ *Type*: rvalue
-This example would return:
+* `zip`: Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments. For example, `zip(['1','2','3'],['4','5','6'])` results in ["1", "4"], ["2", "5"], ["3", "6"]. *Type*: rvalue
- [1,2,3]
+##Limitations
+###Version Compatibility
-- *Type*: rvalue
-
-values_at
----------
-Finds value inside an array based on location.
-
-The first argument is the array you want to analyze, and the second element can
-be a combination of:
-
-* A single numeric index
-* A range in the form of 'start-stop' (eg. 4-9)
-* An array combining the above
-
-*Examples*:
-
- values_at(['a','b','c'], 2)
-
-Would return ['c'].
-
- values_at(['a','b','c'], ["0-1"])
-
-Would return ['a','b'].
+Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x |
+:---------------|:-----:|:---:|:---:|:----:
+**stdlib 2.x** | **yes** | **yes** | no | no
+**stdlib 3.x** | no | **yes** | **yes** | no
+**stdlib 4.x** | no | **yes** | **yes** | no
+**stdlib 5.x** | no | no | **yes** | **yes**
- values_at(['a','b','c','d','e'], [0, "2-3"])
+**stdlib 5.x**: When released, stdlib 5.x will drop support for Puppet 2.7.x. Please see [this discussion](https://github.com/puppetlabs/puppetlabs-stdlib/pull/176#issuecomment-30251414).
-Would return ['a','c','d'].
+##Development
+Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve.
-- *Type*: rvalue
+We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
-zip
----
-Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments.
+You can read the complete module contribution guide on the [Puppet Labs wiki](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing).
-*Example:*
+To report or research a bug with any part of this module, please go to
+[http://tickets.puppetlabs.com/browse/PUP](http://tickets.puppetlabs.com/browse/PUP).
- zip(['1','2','3'],['4','5','6'])
+##Contributors
-Would result in:
+The list of contributors can be found at: https://github.com/puppetlabs/puppetlabs-stdlib/graphs/contributors
- ["1", "4"], ["2", "5"], ["3", "6"]
-- *Type*: rvalue
-*This page autogenerated on 2013-04-11 13:54:25 -0700*
diff --git a/lib/puppet/parser/functions/bool2num.rb b/lib/puppet/parser/functions/bool2num.rb
index 9a07a8a..6ad6cf4 100644
--- a/lib/puppet/parser/functions/bool2num.rb
+++ b/lib/puppet/parser/functions/bool2num.rb
@@ -14,30 +14,7 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
- value = arguments[0]
- klass = value.class
-
- # We can have either true or false, or string which resembles boolean ...
- unless [FalseClass, TrueClass, String].include?(klass)
- raise(Puppet::ParseError, 'bool2num(): Requires either ' +
- 'boolean or string to work with')
- end
-
- if value.is_a?(String)
- # We consider all the yes, no, y, n and so on too ...
- value = case value
- #
- # This is how undef looks like in Puppet ...
- # We yield 0 (or false if you wish) in this case.
- #
- when /^$/, '' then false # Empty string will be false ...
- when /^(1|t|y|true|yes)$/ then true
- when /^(0|f|n|false|no)$/ then false
- when /^(undef|undefined)$/ then false # This is not likely to happen ...
- else
- raise(Puppet::ParseError, 'bool2num(): Unknown type of boolean given')
- end
- end
+ value = function_str2bool([arguments[0]])
# We have real boolean values as well ...
result = value ? 1 : 0
diff --git a/lib/puppet/parser/functions/capitalize.rb b/lib/puppet/parser/functions/capitalize.rb
index 640d00b..98b2d16 100644
--- a/lib/puppet/parser/functions/capitalize.rb
+++ b/lib/puppet/parser/functions/capitalize.rb
@@ -13,9 +13,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'capitalize(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/chomp.rb b/lib/puppet/parser/functions/chomp.rb
index 4564a00..c55841e 100644
--- a/lib/puppet/parser/functions/chomp.rb
+++ b/lib/puppet/parser/functions/chomp.rb
@@ -14,9 +14,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'chomp(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/chop.rb b/lib/puppet/parser/functions/chop.rb
index f242af3..b24ab78 100644
--- a/lib/puppet/parser/functions/chop.rb
+++ b/lib/puppet/parser/functions/chop.rb
@@ -16,9 +16,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'chop(): Requires either an ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb
index 6c86382..0d35b07 100644
--- a/lib/puppet/parser/functions/concat.rb
+++ b/lib/puppet/parser/functions/concat.rb
@@ -28,11 +28,7 @@ Would result in:
raise(Puppet::ParseError, 'concat(): Requires array to work with')
end
- if b.is_a?(Array)
- result = a.concat(b)
- else
- result = a << b
- end
+ result = a + Array(b)
return result
end
diff --git a/lib/puppet/parser/functions/downcase.rb b/lib/puppet/parser/functions/downcase.rb
index 4066d21..040b84f 100644
--- a/lib/puppet/parser/functions/downcase.rb
+++ b/lib/puppet/parser/functions/downcase.rb
@@ -12,9 +12,8 @@ Converts the case of a string or all strings in an array to lower case.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'downcase(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb
index 80ebb86..cca620f 100644
--- a/lib/puppet/parser/functions/empty.rb
+++ b/lib/puppet/parser/functions/empty.rb
@@ -12,9 +12,8 @@ Returns true if the variable is empty.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, Hash, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String)
raise(Puppet::ParseError, 'empty(): Requires either ' +
'array, hash or string to work with')
end
diff --git a/lib/puppet/parser/functions/fqdn_rotate.rb b/lib/puppet/parser/functions/fqdn_rotate.rb
index 6558206..7f4d37d 100644
--- a/lib/puppet/parser/functions/fqdn_rotate.rb
+++ b/lib/puppet/parser/functions/fqdn_rotate.rb
@@ -12,10 +12,9 @@ Rotates an array a random number of times based on a nodes fqdn.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
require 'digest/md5'
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/getvar.rb b/lib/puppet/parser/functions/getvar.rb
index 1621149..fb336b6 100644
--- a/lib/puppet/parser/functions/getvar.rb
+++ b/lib/puppet/parser/functions/getvar.rb
@@ -19,7 +19,10 @@ module Puppet::Parser::Functions
raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)")
end
- self.lookupvar("#{args[0]}")
+ begin
+ self.lookupvar("#{args[0]}")
+ rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
+ end
end
diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb
index d5dbe47..00e405d 100644
--- a/lib/puppet/parser/functions/has_interface_with.rb
+++ b/lib/puppet/parser/functions/has_interface_with.rb
@@ -34,8 +34,7 @@ has_interface_with("lo") => true
end
kind, value = args
- kind.downcase!
-
+
if lookupvar(kind) == value
return true
end
@@ -43,7 +42,12 @@ has_interface_with("lo") => true
result = false
interfaces.each do |iface|
iface.downcase!
- if value == lookupvar("#{kind}_#{iface}")
+ factval = nil
+ begin
+ factval = lookupvar("#{kind}_#{iface}")
+ rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
+ end
+ if value == factval
result = true
break
end
diff --git a/lib/puppet/parser/functions/lstrip.rb b/lib/puppet/parser/functions/lstrip.rb
index 3a64de3..624e4c8 100644
--- a/lib/puppet/parser/functions/lstrip.rb
+++ b/lib/puppet/parser/functions/lstrip.rb
@@ -12,9 +12,8 @@ Strips leading spaces to the left of a string.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'lstrip(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/private.rb b/lib/puppet/parser/functions/private.rb
new file mode 100644
index 0000000..60210d3
--- /dev/null
+++ b/lib/puppet/parser/functions/private.rb
@@ -0,0 +1,29 @@
+#
+# private.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:private, :doc => <<-'EOS'
+ Sets the current class or definition as private.
+ Calling the class or definition from outside the current module will fail.
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "private(): Wrong number of arguments "+
+ "given (#{args.size}}) for 0 or 1)") if args.size > 1
+
+ scope = self
+ if scope.lookupvar('module_name') != scope.lookupvar('caller_module_name')
+ message = nil
+ if args[0] and args[0].is_a? String
+ message = args[0]
+ else
+ manifest_name = scope.source.name
+ manifest_type = scope.source.type
+ message = (manifest_type.to_s == 'hostclass') ? 'Class' : 'Definition'
+ message += " #{manifest_name} is private"
+ end
+ raise(Puppet::ParseError, message)
+ end
+ end
+end
diff --git a/lib/puppet/parser/functions/reverse.rb b/lib/puppet/parser/functions/reverse.rb
index fe04869..7f1018f 100644
--- a/lib/puppet/parser/functions/reverse.rb
+++ b/lib/puppet/parser/functions/reverse.rb
@@ -12,9 +12,8 @@ Reverses the order of a string or array.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'reverse(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/rstrip.rb b/lib/puppet/parser/functions/rstrip.rb
index 29b0998..0cf8d22 100644
--- a/lib/puppet/parser/functions/rstrip.rb
+++ b/lib/puppet/parser/functions/rstrip.rb
@@ -12,9 +12,8 @@ Strips leading spaces to the right of the string.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'rstrip(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/shuffle.rb b/lib/puppet/parser/functions/shuffle.rb
index 18134ab..30c663d 100644
--- a/lib/puppet/parser/functions/shuffle.rb
+++ b/lib/puppet/parser/functions/shuffle.rb
@@ -12,9 +12,8 @@ Randomizes the order of a string or array elements.
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'shuffle(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/strip.rb b/lib/puppet/parser/functions/strip.rb
index 5f4630d..3fac47d 100644
--- a/lib/puppet/parser/functions/strip.rb
+++ b/lib/puppet/parser/functions/strip.rb
@@ -19,9 +19,8 @@ Would result in: "aaa"
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'strip(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/swapcase.rb b/lib/puppet/parser/functions/swapcase.rb
index b9e6632..eb7fe13 100644
--- a/lib/puppet/parser/functions/swapcase.rb
+++ b/lib/puppet/parser/functions/swapcase.rb
@@ -18,9 +18,8 @@ Would result in: "AbCd"
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'swapcase(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/unique.rb b/lib/puppet/parser/functions/unique.rb
index 8844a74..cf770f3 100644
--- a/lib/puppet/parser/functions/unique.rb
+++ b/lib/puppet/parser/functions/unique.rb
@@ -28,9 +28,8 @@ This returns:
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'unique(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb
index fe6cadc..4302b29 100644
--- a/lib/puppet/parser/functions/upcase.rb
+++ b/lib/puppet/parser/functions/upcase.rb
@@ -20,9 +20,8 @@ Will return:
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'upcase(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/uriescape.rb b/lib/puppet/parser/functions/uriescape.rb
index 0d81de5..a486eee 100644
--- a/lib/puppet/parser/functions/uriescape.rb
+++ b/lib/puppet/parser/functions/uriescape.rb
@@ -14,9 +14,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
- klass = value.class
- unless [Array, String].include?(klass)
+ unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'uriescape(): Requires either ' +
'array or string to work with')
end
diff --git a/lib/puppet/parser/functions/validate_string.rb b/lib/puppet/parser/functions/validate_string.rb
index e667794..c841f6a 100644
--- a/lib/puppet/parser/functions/validate_string.rb
+++ b/lib/puppet/parser/functions/validate_string.rb
@@ -13,9 +13,14 @@ module Puppet::Parser::Functions
validate_string(true)
validate_string([ 'some', 'array' ])
- $undefined = undef
- validate_string($undefined)
-
+
+ Note: validate_string(undef) will not fail in this version of the
+ functions API (incl. current and future parser). Instead, use:
+
+ if $var == undef {
+ fail('...')
+ }
+
ENDHEREDOC
unless args.length > 0 then
diff --git a/lib/puppet/parser/functions/zip.rb b/lib/puppet/parser/functions/zip.rb
index 2b56e9c..3074f28 100644
--- a/lib/puppet/parser/functions/zip.rb
+++ b/lib/puppet/parser/functions/zip.rb
@@ -27,33 +27,7 @@ Would result in:
raise(Puppet::ParseError, 'zip(): Requires array to work with')
end
- flatten = arguments[2] if arguments[2]
-
- if flatten
- klass = flatten.class
-
- # We can have either true or false, or string which resembles boolean ...
- unless [FalseClass, TrueClass, String].include?(klass)
- raise(Puppet::ParseError, 'zip(): Requires either ' +
- 'boolean or string to work with')
- end
-
- if flatten.is_a?(String)
- # We consider all the yes, no, y, n and so on too ...
- flatten = case flatten
- #
- # This is how undef looks like in Puppet ...
- # We yield false in this case.
- #
- when /^$/, '' then false # Empty string will be false ...
- when /^(1|t|y|true|yes)$/ then true
- when /^(0|f|n|false|no)$/ then false
- when /^(undef|undefined)$/ then false # This is not likely to happen ...
- else
- raise(Puppet::ParseError, 'zip(): Unknown type of boolean given')
- end
- end
- end
+ flatten = function_str2bool([arguments[2]]) if arguments[2]
result = a.zip(b)
result = flatten ? result.flatten : result
diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb
index 323fc4c..9dbe43c 100644
--- a/lib/puppet/type/file_line.rb
+++ b/lib/puppet/type/file_line.rb
@@ -21,6 +21,9 @@ Puppet::Type.newtype(:file_line) do
In this example, Puppet will ensure both of the specified lines are
contained in the file /etc/sudoers.
+ **Autorequires:** If Puppet is managing the file that will contain the line
+ being managed, the file_line resource will autorequire that file.
+
EOT
ensurable do
diff --git a/spec/acceptance/nodesets/centos-59-x64.yml b/spec/acceptance/nodesets/centos-59-x64.yml
new file mode 100644
index 0000000..2ad90b8
--- /dev/null
+++ b/spec/acceptance/nodesets/centos-59-x64.yml
@@ -0,0 +1,10 @@
+HOSTS:
+ centos-59-x64:
+ roles:
+ - master
+ platform: el-5-x86_64
+ box : centos-59-x64-vbox4210-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: git
diff --git a/spec/acceptance/nodesets/centos-65-x64.yml b/spec/acceptance/nodesets/centos-65-x64.yml
new file mode 100644
index 0000000..4e2cb80
--- /dev/null
+++ b/spec/acceptance/nodesets/centos-65-x64.yml
@@ -0,0 +1,10 @@
+HOSTS:
+ centos-65-x64:
+ roles:
+ - master
+ platform: el-6-x86_64
+ box : centos-65-x64-vbox436-nocm
+ box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box
+ hypervisor : vagrant
+CONFIG:
+ type: foss
diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml
new file mode 100644
index 0000000..cba1cd0
--- /dev/null
+++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml
@@ -0,0 +1,11 @@
+HOSTS:
+ ubuntu-server-1404-x64:
+ roles:
+ - master
+ platform: ubuntu-14.04-amd64
+ box : puppetlabs/ubuntu-14.04-64-nocm
+ box_url : https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm
+ hypervisor : vagrant
+CONFIG:
+ log_level : debug
+ type: git
diff --git a/spec/functions/bool2num_spec.rb b/spec/functions/bool2num_spec.rb
index fbf461b..3904d7e 100755
--- a/spec/functions/bool2num_spec.rb
+++ b/spec/functions/bool2num_spec.rb
@@ -17,8 +17,22 @@ describe "the bool2num function" do
expect(result).to(eq(1))
end
- it "should convert false to 0" do
- result = scope.function_bool2num([false])
+ it "should convert 'true' to 1" do
+ result = scope.function_bool2num(['true'])
+ result.should(eq(1))
+ end
+
+ it "should convert 'false' to 0" do
+ result = scope.function_bool2num(['false'])
expect(result).to(eq(0))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('true')
+ result = scope.function_bool2num([value])
+ result.should(eq(1))
+ end
end
diff --git a/spec/functions/capitalize_spec.rb b/spec/functions/capitalize_spec.rb
index 0cc2d76..fd0e92b 100755
--- a/spec/functions/capitalize_spec.rb
+++ b/spec/functions/capitalize_spec.rb
@@ -16,4 +16,13 @@ describe "the capitalize function" do
result = scope.function_capitalize(["abc"])
expect(result).to(eq("Abc"))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('abc')
+ result = scope.function_capitalize([value])
+ result.should(eq('Abc'))
+ end
end
diff --git a/spec/functions/chomp_spec.rb b/spec/functions/chomp_spec.rb
index d2ae287..b1e1e60 100755
--- a/spec/functions/chomp_spec.rb
+++ b/spec/functions/chomp_spec.rb
@@ -16,4 +16,13 @@ describe "the chomp function" do
result = scope.function_chomp(["abc\n"])
expect(result).to(eq("abc"))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new("abc\n")
+ result = scope.function_chomp([value])
+ result.should(eq("abc"))
+ end
end
diff --git a/spec/functions/chop_spec.rb b/spec/functions/chop_spec.rb
index d9dbb88..c8a1951 100755
--- a/spec/functions/chop_spec.rb
+++ b/spec/functions/chop_spec.rb
@@ -16,4 +16,13 @@ describe "the chop function" do
result = scope.function_chop(["asdf\n"])
expect(result).to(eq("asdf"))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new("abc\n")
+ result = scope.function_chop([value])
+ result.should(eq('abc'))
+ end
end
diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb
index b853b4c..49cb2ad 100755
--- a/spec/functions/concat_spec.rb
+++ b/spec/functions/concat_spec.rb
@@ -27,4 +27,9 @@ describe "the concat function" do
expect(result).to(eq(['1','2','3',['4','5'],'6']))
end
+ it "should leave the original array intact" do
+ array_original = ['1','2','3']
+ result = scope.function_concat([array_original,['4','5','6']])
+ array_original.should(eq(['1','2','3']))
+ end
end
diff --git a/spec/functions/downcase_spec.rb b/spec/functions/downcase_spec.rb
index a844780..edebc44 100755
--- a/spec/functions/downcase_spec.rb
+++ b/spec/functions/downcase_spec.rb
@@ -21,4 +21,13 @@ describe "the downcase function" do
result = scope.function_downcase(["asdf asdf"])
expect(result).to(eq("asdf asdf"))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new("ASFD")
+ result = scope.function_downcase([value])
+ result.should(eq('asfd'))
+ end
end
diff --git a/spec/functions/empty_spec.rb b/spec/functions/empty_spec.rb
index 1f2ace4..6a97c4c 100755
--- a/spec/functions/empty_spec.rb
+++ b/spec/functions/empty_spec.rb
@@ -20,4 +20,13 @@ describe "the empty function" do
result = scope.function_empty(['asdf'])
expect(result).to(eq(false))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new()
+ result = scope.function_empty([value])
+ result.should(eq(true))
+ end
end
diff --git a/spec/functions/fqdn_rotate_spec.rb b/spec/functions/fqdn_rotate_spec.rb
index b2dc1f5..40057d4 100755
--- a/spec/functions/fqdn_rotate_spec.rb
+++ b/spec/functions/fqdn_rotate_spec.rb
@@ -30,4 +30,14 @@ describe "the fqdn_rotate function" do
val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
expect(val1).not_to eql(val2)
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
+ value = AlsoString.new("asdf")
+ result = scope.function_fqdn_rotate([value])
+ result.size.should(eq(4))
+ end
end
diff --git a/spec/functions/lstrip_spec.rb b/spec/functions/lstrip_spec.rb
index 7025f97..68cca1c 100755
--- a/spec/functions/lstrip_spec.rb
+++ b/spec/functions/lstrip_spec.rb
@@ -16,4 +16,13 @@ describe "the lstrip function" do
result = scope.function_lstrip([" asdf"])
expect(result).to(eq('asdf'))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new(" asdf")
+ result = scope.function_lstrip([value])
+ result.should(eq("asdf"))
+ end
end
diff --git a/spec/functions/private_spec.rb b/spec/functions/private_spec.rb
new file mode 100755
index 0000000..c70759f
--- /dev/null
+++ b/spec/functions/private_spec.rb
@@ -0,0 +1,55 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:private) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ subject do
+ function_name = Puppet::Parser::Functions.function(:private)
+ scope.method(function_name)
+ end
+
+ context "when called from inside module" do
+ it "should not fail" do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('foo')
+ expect {
+ subject.call []
+ }.not_to raise_error
+ end
+ end
+
+ context "with an explicit failure message" do
+ it "prints the failure message on error" do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ expect {
+ subject.call ['failure message!']
+ }.to raise_error Puppet::ParseError, /failure message!/
+ end
+ end
+
+ context "when called from private class" do
+ it "should fail with a class error message" do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ scope.source.expects(:name).returns('foo::baz')
+ scope.source.expects(:type).returns('hostclass')
+ expect {
+ subject.call []
+ }.to raise_error Puppet::ParseError, /Class foo::baz is private/
+ end
+ end
+
+ context "when called from private definition" do
+ it "should fail with a class error message" do
+ scope.expects(:lookupvar).with('module_name').returns('foo')
+ scope.expects(:lookupvar).with('caller_module_name').returns('bar')
+ scope.source.expects(:name).returns('foo::baz')
+ scope.source.expects(:type).returns('definition')
+ expect {
+ subject.call []
+ }.to raise_error Puppet::ParseError, /Definition foo::baz is private/
+ end
+ end
+end
diff --git a/spec/functions/reverse_spec.rb b/spec/functions/reverse_spec.rb
index bfeabfb..1f04794 100755
--- a/spec/functions/reverse_spec.rb
+++ b/spec/functions/reverse_spec.rb
@@ -16,4 +16,13 @@ describe "the reverse function" do
result = scope.function_reverse(["asdfghijkl"])
expect(result).to(eq('lkjihgfdsa'))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('asdfghjkl')
+ result = scope.function_reverse([value])
+ result.should(eq('lkjhgfdsa'))
+ end
end
diff --git a/spec/functions/rstrip_spec.rb b/spec/functions/rstrip_spec.rb
index 81321d7..f6b4838 100755
--- a/spec/functions/rstrip_spec.rb
+++ b/spec/functions/rstrip_spec.rb
@@ -21,4 +21,13 @@ describe "the rstrip function" do
result = scope.function_rstrip([["a ","b ", "c "]])
expect(result).to(eq(['a','b','c']))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('asdf ')
+ result = scope.function_rstrip([value])
+ result.should(eq('asdf'))
+ end
end
diff --git a/spec/functions/shuffle_spec.rb b/spec/functions/shuffle_spec.rb
index ee0e2ff..a62c1fb 100755
--- a/spec/functions/shuffle_spec.rb
+++ b/spec/functions/shuffle_spec.rb
@@ -21,4 +21,13 @@ describe "the shuffle function" do
result = scope.function_shuffle(["adfs"])
expect(result.split("").sort.join("")).to(eq("adfs"))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('asdf')
+ result = scope.function_shuffle([value])
+ result.size.should(eq(4))
+ end
end
diff --git a/spec/functions/strip_spec.rb b/spec/functions/strip_spec.rb
index e228761..4ac8daf 100755
--- a/spec/functions/strip_spec.rb
+++ b/spec/functions/strip_spec.rb
@@ -15,4 +15,13 @@ describe "the strip function" do
result = scope.function_strip([" ab cd "])
expect(result).to(eq('ab cd'))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new(' as df ')
+ result = scope.function_strip([value])
+ result.should(eq('as df'))
+ end
end
diff --git a/spec/functions/swapcase_spec.rb b/spec/functions/swapcase_spec.rb
index c6838ab..791d1df 100755
--- a/spec/functions/swapcase_spec.rb
+++ b/spec/functions/swapcase_spec.rb
@@ -16,4 +16,13 @@ describe "the swapcase function" do
result = scope.function_swapcase(["aaBBccDD"])
expect(result).to(eq('AAbbCCdd'))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new("aaBBccDD")
+ result = scope.function_swapcase([value])
+ result.should(eq("AAbbCCdd"))
+ end
end
diff --git a/spec/functions/unique_spec.rb b/spec/functions/unique_spec.rb
index 8ec1464..7cd3a56 100755
--- a/spec/functions/unique_spec.rb
+++ b/spec/functions/unique_spec.rb
@@ -21,4 +21,13 @@ describe "the unique function" do
result = scope.function_unique([["a","a","b","b","c"]])
expect(result).to(eq(['a','b','c']))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('aabbc')
+ result = scope.function_unique([value])
+ result.should(eq('abc'))
+ end
end
diff --git a/spec/functions/upcase_spec.rb b/spec/functions/upcase_spec.rb
index 78e55dd..3cf8b05 100755
--- a/spec/functions/upcase_spec.rb
+++ b/spec/functions/upcase_spec.rb
@@ -21,4 +21,13 @@ describe "the upcase function" do
result = scope.function_upcase(["ABC"])
expect(result).to(eq('ABC'))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('abc')
+ result = scope.function_upcase([value])
+ result.should(eq('ABC'))
+ end
end
diff --git a/spec/functions/uriescape_spec.rb b/spec/functions/uriescape_spec.rb
index c44e9c1..2321e5a 100755
--- a/spec/functions/uriescape_spec.rb
+++ b/spec/functions/uriescape_spec.rb
@@ -21,4 +21,13 @@ describe "the uriescape function" do
result = scope.function_uriescape(["ABCdef"])
expect(result).to(eq('ABCdef'))
end
+
+ it "should accept objects which extend String" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('abc')
+ result = scope.function_uriescape([value])
+ result.should(eq('abc'))
+ end
end
diff --git a/spec/functions/zip_spec.rb b/spec/functions/zip_spec.rb
index 744bdd7..f265fce 100755
--- a/spec/functions/zip_spec.rb
+++ b/spec/functions/zip_spec.rb
@@ -11,5 +11,21 @@ describe "the zip function" do
it "should be able to zip an array" do
result = scope.function_zip([['1','2','3'],['4','5','6']])
expect(result).to(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
+ result = scope.function_zip([['1','2','3'],['4','5','6'], false])
+ result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
+ end
+
+ it "should be able to zip an array and flatten" do
+ result = scope.function_zip([['1','2','3'],['4','5','6'], true])
+ result.should(eq(["1", "4", "2", "5", "3", "6"]))
+ end
+
+ it "should accept objects which extend String for the second argument" do
+ class AlsoString < String
+ end
+
+ value = AlsoString.new('false')
+ result = scope.function_zip([['1','2','3'],['4','5','6'],value])
+ result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
end
end
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
index e9ccc68..53c1661 100755
--- a/spec/spec_helper_acceptance.rb
+++ b/spec/spec_helper_acceptance.rb
@@ -4,16 +4,15 @@ require 'beaker-rspec'
UNSUPPORTED_PLATFORMS = []
unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
- if hosts.first.is_pe?
- install_pe
- on hosts, 'mkdir -p /etc/puppetlabs/facter/facts.d'
- else
- install_puppet
- on hosts, 'mkdir -p /etc/facter/facts.d'
- on hosts, '/bin/touch /etc/puppet/hiera.yaml'
- end
+ # This will install the latest available package on el and deb based
+ # systems fail on windows and osx, and install via gem on other *nixes
+ foss_opts = { :default_action => 'gem_install' }
+
+ if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end
+
hosts.each do |host|
on host, "mkdir -p #{host['distmoduledir']}"
+ on host, "/bin/touch #{default['puppetpath']}/hiera.yaml"
end
end