Skip to content

Instantly share code, notes, and snippets.

@ajgarlag
Created November 16, 2013 11:37
Show Gist options
  • Save ajgarlag/7499227 to your computer and use it in GitHub Desktop.
Save ajgarlag/7499227 to your computer and use it in GitHub Desktop.
Adds Vagrant support to any standard Symfony 2 Framework app.
diff --git a/.gitignore b/.gitignore
index fa563fa..9a1a0a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/.vagrant/
/web/bundles/
/app/bootstrap.php.cache
/app/cache/*
diff --git a/Vagrantfile b/Vagrantfile
new file mode 100644
index 0000000..db22094
--- /dev/null
+++ b/Vagrantfile
@@ -0,0 +1,22 @@
+Vagrant.configure("2") do |config|
+
+ config.vm.box = "debian-wheezy"
+ config.vm.box_url = "https://dl.dropboxusercontent.com/u/2275072/vagrant-debian-wheezy-amd64-es.box"
+
+ config.vm.network :private_network, ip: "192.168.33.10"
+ config.ssh.forward_agent = true
+ config.vm.synced_folder "./", "/home/vagrant/sf2", :nfs => true
+
+ config.vm.provider :virtualbox do |v|
+ v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
+ v.customize ["modifyvm", :id, "--cpus", "2"]
+ v.customize ["modifyvm", :id, "--memory", 1024]
+ end
+
+ config.vm.provision :puppet do |puppet|
+ puppet.manifests_path = "puppet/manifests"
+ puppet.manifest_file = "init.pp"
+ puppet.module_path = "puppet/modules"
+ #puppet.options = "--verbose --debug"
+ end
+end
diff --git a/app/AppKernel.php b/app/AppKernel.php
index c5c9eb6..b1a67b8 100644
--- a/app/AppKernel.php
+++ b/app/AppKernel.php
@@ -32,4 +32,23 @@ class AppKernel extends Kernel
{
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
}
+
+ public function getCacheDir()
+ {
+ if (in_array($this->getEnvironment(), array('dev', 'test'))) {
+ return sys_get_temp_dir() . '/sf2/cache/' . $this->getEnvironment();
+ }
+
+ return parent::getCacheDir();
+ }
+
+ public function getLogDir()
+ {
+ if (in_array($this->environment, array('dev', 'test'))) {
+ return sys_get_temp_dir() . '/sf2/logs/' . $this->getEnvironment();
+ }
+
+ return parent::getLogDir();
+ }
+
}
diff --git a/puppet/manifests/init.pp b/puppet/manifests/init.pp
new file mode 100644
index 0000000..3b80093
--- /dev/null
+++ b/puppet/manifests/init.pp
@@ -0,0 +1,67 @@
+class { 'apt':
+ always_apt_update => true
+}
+
+class { 'apache':
+ mpm_module => 'prefork',
+ default_vhost => false,
+ require => Class['apt']
+}
+
+class {'apache::mod::php':
+ require => Class['apt']
+}
+
+class {'apache::mod::rewrite':}
+
+package { ['php-apc', 'php5-cli', 'php5-sqlite', 'php5-intl', 'php5-xdebug', 'acl']:
+ ensure => present,
+ require => Class['apt']
+}
+
+file {'/etc/php5/conf.d/99-custom.ini':
+ content => "display_errors=On\ndisplay_startup_errors=On\nerror_reporting = E_ALL\nlog_errors=On\nxdebug.remote_enable = On\nxdebug.remote_connect_back = On\nxdebug.max_nesting_level=250\nmemory_limit = -1\ndate.timezone = 'Europe/Madrid'",
+ require => Class['apache::mod::php']
+}
+
+exec { '/bin/mount -o remount,acl /':
+ require => Package['acl']
+}->
+exec { '/bin/setfacl -R -m www-data:rwX -m u:vagrant:rwX /home/vagrant/sf2/app/cache /home/vagrant/sf2/app/logs':
+}->
+exec { '/bin/setfacl -dR -m www-data:rwX -m u:vagrant:rwX /home/vagrant/sf2/app/cache /home/vagrant/sf2/app/logs':
+}
+
+file { "/tmp/sf2":
+ ensure => "directory",
+ owner => "vagrant"
+}->
+file { "/tmp/sf2/cache":
+ ensure => "directory",
+ owner => "vagrant"
+}->
+file { "/tmp/sf2/logs":
+ ensure => "directory",
+ owner => "vagrant"
+}->
+exec { '/bin/setfacl -R -m www-data:rwX -m u:vagrant:rwX /tmp/sf2/cache /tmp/sf2/logs':
+ require => Package['acl']
+}->
+exec { '/bin/setfacl -dR -m www-data:rwX -m u:vagrant:rwX /tmp/sf2/cache /tmp/sf2/logs':
+ require => Package['acl']
+}
+
+apache::vhost { 'sf2.localdomain':
+ port => '80',
+ docroot => '/home/vagrant/sf2/web',
+ docroot_owner => 'vagrant',
+ docroot_group => 'vagrant',
+ directories => [ { path => '/home/vagrant/sf2/web', allow_override => ['All'] } ]
+}
+
+class { 'composer':
+ command_name => 'composer',
+ target_dir => '/usr/local/bin',
+ auto_update => true,
+ require => Package['php5-cli']
+}
\ No newline at end of file
diff --git a/puppet/modules/apache/.bundle/config b/puppet/modules/apache/.bundle/config
new file mode 100644
index 0000000..0981b95
--- /dev/null
+++ b/puppet/modules/apache/.bundle/config
@@ -0,0 +1,2 @@
+---
+BUNDLE_WITHOUT: development
diff --git a/puppet/modules/apache/.fixtures.yml b/puppet/modules/apache/.fixtures.yml
new file mode 100644
index 0000000..b5f76c0
--- /dev/null
+++ b/puppet/modules/apache/.fixtures.yml
@@ -0,0 +1,6 @@
+fixtures:
+ repositories:
+ stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
+ concat: "git://github.com/puppetlabs/puppetlabs-concat.git"
+ symlinks:
+ apache: "#{source_dir}"
diff --git a/puppet/modules/apache/.nodeset.yml b/puppet/modules/apache/.nodeset.yml
new file mode 100644
index 0000000..767f9cd
--- /dev/null
+++ b/puppet/modules/apache/.nodeset.yml
@@ -0,0 +1,31 @@
+---
+default_set: 'centos-64-x64'
+sets:
+ 'centos-59-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'centos-59-x64'
+ 'centos-64-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'centos-64-x64'
+ 'fedora-18-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'fedora-18-x64'
+ 'debian-607-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'debian-607-x64'
+ 'debian-70rc1-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'debian-70rc1-x64'
+ 'ubuntu-server-10044-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'ubuntu-server-10044-x64'
+ 'ubuntu-server-12042-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'ubuntu-server-12042-x64'
diff --git a/puppet/modules/apache/.travis.yml b/puppet/modules/apache/.travis.yml
new file mode 100644
index 0000000..b885627
--- /dev/null
+++ b/puppet/modules/apache/.travis.yml
@@ -0,0 +1,39 @@
+---
+branches:
+ only:
+ - master
+language: ruby
+bundler_args: --without development
+script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
+after_success:
+ - git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-releng
+ - .forge-releng/publish
+rvm:
+ - 1.8.7
+ - 1.9.3
+ - 2.0.0
+env:
+ matrix:
+ - PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
+ - PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
+ - PUPPET_GEM_VERSION="~> 3.0"
+ global:
+ - PUBLISHER_LOGIN=puppetlabs
+ - secure: |-
+ MO4pB4bqBQJjm2yFHf3Mgho+y0Qv4GmMxTMhzI02tGy1V0HMtruZbR7EBN0i
+ n2CiR7V9V0mNR7/ymzDMF9yVBcgqyXMsp/C6u992Dd0U63ZwFpbRWkxuAeEY
+ ioupWBkiczjVEo+sxn+gVOnx28pcH/X8kDWbr6wFOMIjO03K66Y=
+matrix:
+ exclude:
+ - rvm: 1.9.3
+ env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
+ - rvm: 1.9.3
+ env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
+ - rvm: 1.8.7
+ env: PUPPET_GEM_VERSION="~> 3.2.0"
+notifications:
+ email: false
diff --git a/puppet/modules/apache/CHANGELOG.md b/puppet/modules/apache/CHANGELOG.md
new file mode 100644
index 0000000..c4686ab
--- /dev/null
+++ b/puppet/modules/apache/CHANGELOG.md
@@ -0,0 +1,133 @@
+## 2013-09-06 Release 0.9.0
+### Summary:
+This release adds more parameters to the base apache class and apache defined
+resource to make the module more flexible. It also adds or enhances SuPHP,
+WSGI, and Passenger mod support, and support for the ITK mpm module.
+
+### Backwards-incompatible Changes:
+- Remove many default mods that are not normally needed.
+- Remove `rewrite_base` `apache::vhost` parameter; did not work anyway.
+- Specify dependencies on stdlib >=2.4.0 (this was already the case, but
+making explicit)
+- Deprecate `a2mod` in favor of the `apache::mod::*` classes and `apache::mod`
+defined resource.
+
+### Features:
+- `apache` class
+ - Add `httpd_dir` parameter to change the location of the configuration
+ files.
+ - Add `logroot` parameter to change the logroot
+ - Add `ports_file` parameter to changes the `ports.conf` file location
+ - Add `keepalive` parameter to enable persistent connections
+ - Add `keepalive_timeout` parameter to change the timeout
+ - Update `default_mods` to be able to take an array of mods to enable.
+- `apache::vhost`
+ - Add `wsgi_daemon_process`, `wsgi_daemon_process_options`,
+ `wsgi_process_group`, and `wsgi_script_aliases` parameters for per-vhost
+ WSGI configuration.
+ - Add `access_log_syslog` parameter to enable syslogging.
+ - Add `error_log_syslog` parameter to enable syslogging of errors.
+ - Add `directories` hash parameter. Please see README for documentation.
+ - Add `sslproxyengine` parameter to enable SSLProxyEngine
+ - Add `suphp_addhandler`, `suphp_engine`, and `suphp_configpath` for
+ configuring SuPHP.
+ - Add `custom_fragment` parameter to allow for arbitrary apache
+ configuration injection. (Feature pull requests are prefered over using
+ this, but it is available in a pinch.)
+- Add `apache::mod::suphp` class for configuring SuPHP.
+- Add `apache::mod::itk` class for configuring ITK mpm module.
+- Update `apache::mod::wsgi` class for global WSGI configuration with
+`wsgi_socket_prefix` and `wsgi_python_home` parameters.
+- Add README.passenger.md to document the `apache::mod::passenger` usage.
+Added `passenger_high_performance`, `passenger_pool_idle_time`,
+`passenger_max_requests`, `passenger_stat_throttle_rate`, `rack_autodetect`,
+and `rails_autodetect` parameters.
+- Separate the httpd service resource into a new `apache::service` class for
+dependency chaining of `Class['apache'] -> <resource> ~>
+Class['apache::service']`
+- Added `apache::mod::proxy_balancer` class for `apache::balancer`
+
+### Bugfixes:
+- Change dependency to puppetlabs-concat
+- Fix ruby 1.9 bug for `a2mod`
+- Change servername to be `$::hostname` if there is no `$::fqdn`
+- Make `/etc/ssl/certs` the default ssl certs directory for RedHat non-5.
+- Make `php` the default php package for RedHat non-5.
+- Made `aliases` able to take a single alias hash instead of requiring an
+array.
+
+## 2013-07-26 Release 0.8.1
+### Bugfixes:
+- Update `apache::mpm_module` detection for worker/prefork
+- Update `apache::mod::cgi` and `apache::mod::cgid` detection for
+worker/prefork
+
+## 2013-07-16 Release 0.8.0
+### Features:
+- Add `servername` parameter to `apache` class
+- Add `proxy_set` parameter to `apache::balancer` define
+
+### Bugfixes:
+- Fix ordering for multiple `apache::balancer` clusters
+- Fix symlinking for sites-available on Debian-based OSs
+- Fix dependency ordering for recursive confdir management
+- Fix `apache::mod::*` to notify the service on config change
+- Documentation updates
+
+## 2013-07-09 Release 0.7.0
+### Changes:
+- Essentially rewrite the module -- too many to list
+- `apache::vhost` has many abilities -- see README.md for details
+- `apache::mod::*` classes provide httpd mod-loading capabilities
+- `apache` base class is much more configurable
+
+### Bugfixes:
+- Many. And many more to come
+
+## 2013-03-2 Release 0.6.0
+- update travis tests (add more supported versions)
+- add access log_parameter
+- make purging of vhost dir configurable
+
+## 2012-08-24 Release 0.4.0
+### Changes:
+- `include apache` is now required when using `apache::mod::*`
+
+### Bugfixes:
+- Fix syntax for validate_re
+- Fix formatting in vhost template
+- Fix spec tests such that they pass
+
+ 2012-05-08 Puppet Labs <info@puppetlabs.com> - 0.0.4
+ e62e362 Fix broken tests for ssl, vhost, vhost::*
+ 42c6363 Changes to match style guide and pass puppet-lint without error
+ 42bc8ba changed name => path for file resources in order to name namevar by it's name
+ 72e13de One end too much
+ 0739641 style guide fixes: 'true' <> true, $operatingsystem needs to be $::operatingsystem, etc.
+ 273f94d fix tests
+ a35ede5 (#13860) Make a2enmod/a2dismo commands optional
+ 98d774e (#13860) Autorequire Package['httpd']
+ 05fcec5 (#13073) Add missing puppet spec tests
+ 541afda (#6899) Remove virtual a2mod definition
+ 976cb69 (#13072) Move mod python and wsgi package names to params
+ 323915a (#13060) Add .gitignore to repo
+ fdf40af (#13060) Remove pkg directory from source tree
+ fd90015 Add LICENSE file and update the ModuleFile
+ d3d0d23 Re-enable local php class
+ d7516c7 Make management of firewalls configurable for vhosts
+ 60f83ba Explicitly lookup scope of apache_name in templates.
+ f4d287f (#12581) Add explicit ordering for vdir directory
+ 88a2ac6 (#11706) puppetlabs-apache depends on puppetlabs-firewall
+ a776a8b (#11071) Fix to work with latest firewall module
+ 2b79e8b (#11070) Add support for Scientific Linux
+ 405b3e9 Fix for a2mod
+ 57b9048 Commit apache::vhost::redirect Manifest
+ 8862d01 Commit apache::vhost::proxy Manifest
+ d5c1fd0 Commit apache::mod::wsgi Manifest
+ a825ac7 Commit apache::mod::python Manifest
+ b77062f Commit Templates
+ 9a51b4a Vhost File Declarations
+ 6cf7312 Defaults for Parameters
+ 6a5b11a Ensure installed
+ f672e46 a2mod fix
+ 8a56ee9 add pthon support to apache
diff --git a/puppet/modules/apache/Gemfile b/puppet/modules/apache/Gemfile
new file mode 100644
index 0000000..7c8ea9e
--- /dev/null
+++ b/puppet/modules/apache/Gemfile
@@ -0,0 +1,26 @@
+source 'https://rubygems.org'
+
+group :development, :test do
+ gem 'rake', :require => false
+ gem 'rspec-puppet', :require => false
+ gem 'puppetlabs_spec_helper', :require => false
+ gem 'serverspec', :require => false
+ gem 'rspec-system', :require => false
+ gem 'rspec-system-puppet', :require => false
+ gem 'rspec-system-serverspec', :require => false
+ gem 'puppet-lint', :require => false
+end
+
+if facterversion = ENV['FACTER_GEM_VERSION']
+ gem 'facter', facterversion, :require => false
+else
+ gem 'facter', :require => false
+end
+
+if puppetversion = ENV['PUPPET_GEM_VERSION']
+ gem 'puppet', puppetversion, :require => false
+else
+ gem 'puppet', :require => false
+end
+
+# vim:ft=ruby
diff --git a/puppet/modules/apache/Gemfile.lock b/puppet/modules/apache/Gemfile.lock
new file mode 100644
index 0000000..9ca14cf
--- /dev/null
+++ b/puppet/modules/apache/Gemfile.lock
@@ -0,0 +1,78 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ builder (3.2.2)
+ diff-lcs (1.2.4)
+ facter (1.7.2)
+ hiera (1.2.1)
+ json_pure
+ highline (1.6.19)
+ json_pure (1.8.0)
+ kwalify (0.7.2)
+ metaclass (0.0.1)
+ mocha (0.14.0)
+ metaclass (~> 0.0.1)
+ net-scp (1.1.2)
+ net-ssh (>= 2.6.5)
+ net-ssh (2.6.8)
+ nokogiri (1.5.10)
+ puppet (3.2.4)
+ facter (~> 1.6)
+ hiera (~> 1.0)
+ rgen (~> 0.6.5)
+ puppet-lint (0.3.2)
+ puppetlabs_spec_helper (0.4.1)
+ mocha (>= 0.10.5)
+ rake
+ rspec (>= 2.9.0)
+ rspec-puppet (>= 0.1.1)
+ rake (10.1.0)
+ rbvmomi (1.6.0)
+ builder
+ nokogiri (>= 1.4.1)
+ trollop
+ rgen (0.6.6)
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.5)
+ rspec-expectations (2.14.2)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.3)
+ rspec-puppet (0.1.6)
+ rspec
+ rspec-system (2.2.0)
+ kwalify (~> 0.7.2)
+ net-scp (~> 1.1)
+ net-ssh (~> 2.6)
+ nokogiri (~> 1.5.9)
+ rbvmomi (~> 1.6)
+ rspec (~> 2.13)
+ systemu (~> 2.5)
+ rspec-system-puppet (2.2.0)
+ rspec-system (~> 2.0)
+ rspec-system-serverspec (1.0.0)
+ rspec-system (~> 2.0)
+ serverspec (~> 0.6.0)
+ serverspec (0.6.3)
+ highline
+ net-ssh
+ rspec (~> 2.0)
+ systemu (2.5.2)
+ trollop (2.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ facter
+ puppet (~> 3.0)
+ puppet-lint
+ puppetlabs_spec_helper
+ rake
+ rspec-puppet
+ rspec-system
+ rspec-system-puppet
+ rspec-system-serverspec
+ serverspec
diff --git a/puppet/modules/apache/LICENSE b/puppet/modules/apache/LICENSE
new file mode 100644
index 0000000..8961ce8
--- /dev/null
+++ b/puppet/modules/apache/LICENSE
@@ -0,0 +1,15 @@
+Copyright (C) 2012 Puppet Labs Inc
+
+Puppet Labs can be contacted at: info@puppetlabs.com
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/puppet/modules/apache/Modulefile b/puppet/modules/apache/Modulefile
new file mode 100644
index 0000000..800ccf5
--- /dev/null
+++ b/puppet/modules/apache/Modulefile
@@ -0,0 +1,12 @@
+name 'puppetlabs-apache'
+version '0.9.0'
+source 'git://github.com/puppetlabs/puppetlabs-apache.git'
+author 'puppetlabs'
+license 'Apache 2.0'
+summary 'Puppet module for Apache'
+description 'Module for Apache configuration'
+project_page 'https://github.com/puppetlabs/puppetlabs-apache'
+
+## Add dependencies, if any:
+dependency 'puppetlabs/stdlib', '>= 2.4.0'
+dependency 'puppetlabs/concat', '>= 1.0.0'
diff --git a/puppet/modules/apache/README.md b/puppet/modules/apache/README.md
new file mode 100644
index 0000000..1e949d1
--- /dev/null
+++ b/puppet/modules/apache/README.md
@@ -0,0 +1,1168 @@
+#apache
+
+[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-apache.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-apache)
+
+####Table of Contents
+
+1. [Overview - What is the Apache module?](#overview)
+2. [Module Description - What does the module do?](#module-description)
+3. [Setup - The basics of getting started with Apache](#setup)
+ * [Beginning with Apache - Installation](#beginning-with-apache)
+ * [Configure a Virtual Host - Basic options for getting started](#configure-a-virtual-host)
+4. [Usage - The classes, defined types, and their parameters available for configuration](#usage)
+ * [Classes and Defined Types](#classes-and-defined-types)
+ * [Class: apache](#class-apache)
+ * [Classes: apache::mod::*](#classes-apachemodname)
+ * [Defined Type: apache::vhost](#defined-type-apachevhost)
+ * [Virtual Host Examples - Demonstrations of some configuration options](#virtual-host-examples)
+5. [Implementation - An under-the-hood peek at what the module is doing](#implementation)
+ * [Classes and Defined Types](#classes-and-defined-types)
+ * [Templates](#templates)
+6. [Limitations - OS compatibility, etc.](#limitations)
+7. [Development - Guide for contributing to the module](#development)
+8. [Release Notes - Notes on the most recent updates to the module](#release-notes)
+
+##Overview
+
+The Apache module allows you to set up virtual hosts and manage web services with minimal effort.
+
+##Module Description
+
+Apache is a widely-used web server, and this module provides a simplified way of creating configurations to manage your infrastructure. This includes the ability to configure and manage a range of different virtual host setups, as well as a streamlined way to install and configure Apache modules.
+
+##Setup
+
+**What Apache affects:**
+
+* configuration files and directories (created and written to)
+ * **NOTE**: Configurations that are *not* managed by Puppet will be purged.
+* package/service/configuration files for Apache
+* Apache modules
+* virtual hosts
+* listened-to ports
+
+###Beginning with Apache
+
+To install Apache with the default parameters
+
+```puppet
+ class { 'apache': }
+```
+
+The defaults are determined by your operating system (e.g. Debian systems have one set of defaults, RedHat systems have another). These defaults will work well in a testing environment, but are not suggested for production. To establish customized parameters
+
+```puppet
+ class { 'apache':
+ default_mods => false,
+ }
+```
+
+###Configure a virtual host
+
+Declaring the `apache` class will create a default virtual host by setting up a vhost on port 80, listening on all interfaces and serving `$apache::docroot`.
+
+```puppet
+ class { 'apache': }
+```
+
+To configure a very basic, name-based virtual host
+
+```puppet
+ apache::vhost { 'first.example.com':
+ port => '80',
+ docroot => '/var/www/first',
+ }
+```
+
+*Note:* The default priority is 15. If nothing matches this priority, the alphabetically first name-based vhost will be used. This is also true if you pass a higher priority and no names match anything else.
+
+A slightly more complicated example, which moves the docroot owner/group
+
+```puppet
+ apache::vhost { 'second.example.com':
+ port => '80',
+ docroot => '/var/www/second',
+ docroot_owner => 'third',
+ docroot_group => 'third',
+ }
+```
+
+To set up a virtual host with SSL and default SSL certificates
+
+```puppet
+ apache::vhost { 'ssl.example.com':
+ port => '443',
+ docroot => '/var/www/ssl',
+ ssl => true,
+ }
+```
+
+To set up a virtual host with SSL and specific SSL certificates
+
+```puppet
+ apache::vhost { 'fourth.example.com':
+ port => '443',
+ docroot => '/var/www/fourth',
+ ssl => true,
+ ssl_cert => '/etc/ssl/fourth.example.com.cert',
+ ssl_key => '/etc/ssl/fourth.example.com.key',
+ }
+```
+
+To set up a virtual host with wildcard alias for subdomain mapped to same named directory
+`http://examle.com.loc => /var/www/example.com`
+
+```puppet
+ apache::vhost { 'subdomain.loc':
+ vhost_name => '*',
+ port => '80',
+ virtual_docroot' => '/var/www/%-2+',
+ docroot => '/var/www',
+ serveraliases => ['*.loc',],
+ }
+```
+
+To set up a virtual host with suPHP
+
+```puppet
+ apache::vhost { 'suphp.example.com':
+ port => '80',
+ docroot => '/home/appuser/myphpapp',
+ suphp_addhandler => 'x-httpd-php',
+ suphp_engine => 'on',
+ suphp_configpath => '/etc/php5/apache2',
+ }
+```
+
+To set up a virtual host with WSGI
+
+```puppet
+ apache::vhost { 'wsgi.example.com':
+ port => '80',
+ docroot => '/var/www/pythonapp',
+ wsgi_daemon_process => 'wsgi',
+ wsgi_daemon_process_options =>
+ { processes => '2', threads => '15', display-name => '%{GROUP}' },
+ wsgi_process_group => 'wsgi',
+ wsgi_script_aliases => { '/' => '/var/www/demo.wsgi' },
+ }
+```
+
+To see a list of all virtual host parameters, [please go here](#defined-type-apachevhost). To see an extensive list of virtual host examples [please look here](#virtual-host-examples).
+
+##Usage
+
+###Classes and Defined Types
+
+This module modifies Apache configuration files and directories and will purge any configuration not managed by Puppet. Configuration of Apache should be managed by Puppet, as non-puppet configuration files can cause unexpected failures.
+
+It is possible to temporarily disable full Puppet management by setting the `purge_configs` parameter within the base `apache` class to 'false'. This option should only be used as a temporary means of saving and relocating customized configurations.
+
+####Class: `apache`
+
+The Apache module's primary class, `apache`, guides the basic setup of Apache on your system.
+
+You may establish a default vhost in this class, the `vhost` class, or both. You may add additional vhost configurations for specific virtual hosts using a declaration of the `vhost` type.
+
+**Parameters within `apache`:**
+
+#####`default_mods`
+
+Sets up Apache with default settings based on your OS. Defaults to 'true', set to 'false' for customized configuration.
+
+#####`default_vhost`
+
+Sets up a default virtual host. Defaults to 'true', set to 'false' to set up [customized virtual hosts](#configure-a-virtual-host).
+
+#####`default_ssl_vhost`
+
+Sets up a default SSL virtual host. Defaults to 'false'.
+
+```puppet
+ apache::vhost { 'default-ssl':
+ port => 443,
+ ssl => true,
+ docroot => $docroot,
+ scriptalias => $scriptalias,
+ serveradmin => $serveradmin,
+ access_log_file => "ssl_${access_log_file}",
+ }
+```
+
+SSL vhosts only respond to HTTPS queries.
+
+#####`default_ssl_cert`
+
+The default SSL certification, which is automatically set based on your operating system (`/etc/pki/tls/certs/localhost.crt` for RedHat, `/etc/ssl/certs/ssl-cert-snakeoil.pem` for Debian). This default will work out of the box but must be updated with your specific certificate information before being used in production.
+
+#####`default_ssl_key`
+
+The default SSL key, which is automatically set based on your operating system (`/etc/pki/tls/private/localhost.key` for RedHat, `/etc/ssl/private/ssl-cert-snakeoil.key` for Debian). This default will work out of the box but must be updated with your specific certificate information before being used in production.
+
+#####`default_ssl_chain`
+
+The default SSL chain, which is automatically set to 'undef'. This default will work out of the box but must be updated with your specific certificate information before being used in production.
+
+#####`default_ssl_ca`
+
+The default certificate authority, which is automatically set to 'undef'. This default will work out of the box but must be updated with your specific certificate information before being used in production.
+
+#####`default_ssl_crl_path`
+
+The default certificate revocation list path, which is automatically set to 'undef'. This default will work out of the box but must be updated with your specific certificate information before being used in production.
+
+#####`default_ssl_crl`
+
+The default certificate revocation list to use, which is automatically set to 'undef'. This default will work out of the box but must be updated with your specific certificate information before being used in production.
+
+#####`service_enable`
+
+Determines whether the 'httpd' service is enabled when the machine is booted, meaning Puppet will check the service status to start/stop it. Defaults to 'true', meaning the service is enabled/running.
+
+#####`serveradmin`
+
+Sets the server administrator. Defaults to 'root@localhost'.
+
+#####`servername`
+
+Sets the servername. Defaults to fqdn provided by facter.
+
+#####`sendfile`
+
+Makes Apache use the Linux kernel 'sendfile' to serve static files. Defaults to 'false'.
+
+#####`error_documents`
+
+Enables custom error documents. Defaults to 'false'.
+
+#####`httpd_dir`
+
+Changes the base location of the configuration directories used for the service. This is useful for specially repackaged HTTPD builds but may have unintended concequences when used in combination with the default distribution packages. Default is based on your OS.
+
+#####`confd_dir`
+
+Changes the location of the configuration directory your custom configuration files are placed in. Default is based on your OS.
+
+#####`vhost_dir`
+
+Changes the location of the configuration directory your virtual host configuration files are placed in. Default is based on your OS.
+
+#####`mod_dir`
+
+Changes the location of the configuration directory your Apache modules configuration files are placed in. Default is based on your OS.
+
+#####`mpm_module`
+
+Configures which mpm module is loaded and configured for the httpd process by the `apache::mod::prefork`, `apache::mod::worker` and `apache::mod::itk` classes. Must be set to `false` to explicitly declare `apache::mod::worker`, `apache::mod::worker` or `apache::mod::itk` classes with parameters. Valid values are `worker`, `prefork`, `itk` (Debian), or the boolean `false`. Defaults to `prefork` on RedHat and `worker` on Debian.
+
+#####`conf_template`
+
+Setting this allows you to override the template used for the main apache configuration file. This is a potentially risky thing to do as this module has been built around the concept of a minimal configuration file with most of the configuration coming in the form of conf.d/ entries. Defaults to 'apache/httpd.conf.erb'.
+
+#####`keepalive`
+
+Setting this allows you to enable persistent connections.
+
+#####`keepalive_timeout`
+
+Amount of time the server will wait for subsequent requests on a persistent connection. Defaults to '15'.
+
+#####`logroot`
+
+Changes the location of the directory Apache log files are placed in. Defaut is based on your OS.
+
+#####`ports_file`
+
+Changes the name of the file containing Apache ports configuration. Default is `${conf_dir}/ports.conf`.
+
+####Class: `apache::default_mods`
+
+Installs default Apache modules based on what OS you are running
+
+```puppet
+ class { 'apache::default_mods': }
+```
+
+####Defined Type: `apache::mod`
+
+Used to enable arbitrary Apache httpd modules for which there is no specific `apache::mod::[name]` class. The `apache::mod` defined type will also install the required packages to enable the module, if any.
+
+```puppet
+ apache::mod { 'rewrite': }
+ apache::mod { 'ldap': }
+```
+
+####Classes: `apache::mod::[name]`
+
+There are many `apache::mod::[name]` classes within this module that can be declared using `include`:
+
+* `alias`
+* `auth_basic`
+* `auth_kerb`
+* `autoindex`
+* `cache`
+* `cgi`
+* `cgid`
+* `dav`
+* `dav_fs`
+* `deflate`
+* `dir`*
+* `disk_cache`
+* `fcgid`
+* `info`
+* `ldap`
+* `mime`
+* `mime_magic`
+* `mpm_event`
+* `negotiation`
+* `passenger`*
+* `perl`
+* `php` (requires [`mpm_module`](#mpm_module) set to `prefork`)
+* `prefork`*
+* `proxy`*
+* `proxy_html`
+* `proxy_http`
+* `python`
+* `reqtimeout`
+* `setenvif`
+* `ssl`* (see [apache::mod::ssl](#class-apachemodssl) below)
+* `status`
+* `suphp`
+* `userdir`*
+* `worker`*
+* `wsgi` (see [apache::mod::wsgi](#class-apachemodwsgi) below)
+* `xsendfile`
+
+Modules noted with a * indicate that the module has settings and, thus, a template that includes parameters. These parameters control the module's configuration. Most of the time, these parameters will not require any configuration or attention.
+
+The modules mentioned above, and other Apache modules that have templates, will cause template files to be dropped along with the mod install, and the module will not work without the template. Any mod without a template will install package but drop no files.
+
+####Class: `apache::mod::ssl`
+
+Installs Apache SSL capabilities and utilizes `ssl.conf.erb` template
+
+```puppet
+ class { 'apache::mod::ssl': }
+```
+
+To *use* SSL with a virtual host, you must either set the`default_ssl_vhost` parameter in `apache` to 'true' or set the `ssl` parameter in `apache::vhost` to 'true'.
+
+####Class: `apache::mod::wsgi`
+
+```puppet
+ class { 'apache::mod::wsgi':
+ wsgi_socket_prefix => "\${APACHE_RUN_DIR}WSGI",
+ wsgi_python_home => '/path/to/virtenv',
+ }
+```
+####Defined Type: `apache::vhost`
+
+The Apache module allows a lot of flexibility in the set up and configuration of virtual hosts. This flexibility is due, in part, to `vhost`'s setup as a defined resource type, which allows it to be evaluated multiple times with different parameters.
+
+The `vhost` defined type allows you to have specialized configurations for virtual hosts that have requirements outside of the defaults. You can set up a default vhost within the base `apache` class as well as set a customized vhost setup as default. Your customized vhost (priority 10) will be privileged over the base class vhost (15).
+
+If you have a series of specific configurations and do not want a base `apache` class default vhost, make sure to set the base class default host to 'false'.
+
+```puppet
+ class { 'apache':
+ default_vhost => false,
+ }
+```
+
+**Parameters within `apache::vhost`:**
+
+The default values for each parameter will vary based on operating system and type of virtual host.
+
+#####`access_log`
+
+Specifies whether `*_access.log` directives should be configured. Valid values are 'true' and 'false'. Defaults to 'true'.
+
+#####`access_log_file`
+
+Points to the `*_access.log` file. Defaults to 'undef'.
+
+#####`access_log_pipe`
+
+Specifies a pipe to send access log messages to. Defaults to 'undef'.
+
+#####`access_log_syslog`
+
+Sends all access log messages to syslog. Defaults to 'undef'.
+
+#####`access_log_format`
+
+Specifies either a LogFormat nickname or custom format string for access log. Defaults to 'undef'.
+
+#####`add_listen`
+
+Determines whether the vhost creates a listen statement. The default value is 'true'.
+
+Setting `add_listen` to 'false' stops the vhost from creating a listen statement, and this is important when you combine vhosts that are not passed an `ip` parameter with vhosts that *are* passed the `ip` parameter.
+
+#####`aliases`
+
+Passes a list of hashes to the vhost to create `Alias` statements as per the [`mod_alias` documentation](http://httpd.apache.org/docs/current/mod/mod_alias.html). Each hash is expected to be of the form:
+
+```puppet
+aliases => [ { alias => '/alias', path => '/path/to/directory' } ],
+```
+
+For `Alias` to work, each will need a corresponding `<Directory /path/to/directory>` or `<Location /path/to/directory>` block.
+
+**Note:** If `apache::mod::passenger` is loaded and `PassengerHighPerformance true` is set, then `Alias` may have issues honouring the `PassengerEnabled off` statement. See [this article](http://www.conandalton.net/2010/06/passengerenabled-off-not-working.html) for details.
+
+#####`block`
+
+Specifies the list of things Apache will block access to. The default is an empty set, '[]'. Currently, the only option is 'scm', which blocks web access to .svn, .git and .bzr directories. To add to this, please see the [Development](#development) section.
+
+#####`custom_fragment`
+
+Pass a string of custom configuration directives to be placed at the end of the vhost configuration.
+
+#####`default_vhost`
+
+Sets a given `apache::vhost` as the default to serve requests that do not match any other `apache::vhost` definitions. The default value is 'false'.
+
+#####`directories`
+
+Passes a list of hashes to the vhost to create `<Directory /path/to/directory>...</Directory>` directive blocks as per the [Apache core documentation](http://httpd.apache.org/docs/2.2/mod/core.html#directory). The `path` key is required in these hashes. Usage will typically look like:
+
+```puppet
+ apache::vhost { 'sample.example.net':
+ docroot => '/path/to/directory',
+ directories => [
+ { path => '/path/to/directory', <directive> => <value> },
+ { path => '/path/to/another/directory', <directive> => <value> },
+ ],
+ }
+```
+
+*Note:* At least one directory should match `docroot` parameter, once you start declaring directories `apache::vhost` assumes that all required `<Directory>` blocks will be declared.
+
+*Note:* If not defined a single default `<Directory>` block will be created that matches the `docroot` parameter.
+
+The directives will be embedded within the `Directory` directive block, missing directives should be undefined and not be added, resulting in their default vaules in Apache. Currently this is the list of supported directives:
+
+######`addhandlers`
+
+Sets `AddHandler` directives as per the [Apache Core documentation](http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addhandler). Accepts a list of hashes of the form `{ handler => 'handler-name', extensions => ['extension']}`. Note that `extensions` is a list of extenstions being handled by the handler.
+An example:
+
+```puppet
+ apache::vhost { 'sample.example.net':
+ docroot => '/path/to/directory',
+ directories => [ { path => '/path/to/directory',
+ addhandlers => [ { handler => 'cgi-script', extensions => ['.cgi']} ],
+ } ],
+ }
+```
+
+######`allow`
+
+Sets an `Allow` directive as per the [Apache Core documentation](http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#allow). An example:
+
+```puppet
+ apache::vhost { 'sample.example.net':
+ docroot => '/path/to/directory',
+ directories => [ { path => '/path/to/directory', allow => 'from example.org' } ],
+ }
+```
+
+######`allow_override`
+
+Sets the usage of `.htaccess` files as per the [Apache core documentation](http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride). Should accept in the form of a list or a string. An example:
+
+```puppet
+ apache::vhost { 'sample.example.net':
+ docroot => '/path/to/directory',
+ directories => [ { path => '/path/to/directory', allow_override => ['AuthConfig', 'Indexes'] } ],
+ }
+```
+
+######`deny`
+
+Sets an `Deny` directive as per the [Apache Core documentation](http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#deny). An example:
+
+```puppet
+ apache::vhost { 'sample.example.net':
+ docroot => '/path/to/directory',
+ directories => [ { path => '/path/to/directory', deny => 'from example.org' } ],
+ }
+```
+
+######`headers`
+
+Adds lines for `Header` directives as per the [Apache Header documentation](http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header). An example:
+
+```puppet
+ apache::vhost { 'sample.example.net':
+ docroot => '/path/to/directory',
+ directories => {
+ path => '/path/to/directory',
+ headers => 'Set X-Robots-Tag "noindex, noarchive, nosnippet"',
+ },
+ }
+```
+
+######`options`
+
+Lists the options for the given `<Directory>` block
+
+```puppet
+ apache::vhost { 'sample.example.net':
+ docroot => '/path/to/directory',
+ directories => [ { path => '/path/to/directory', options => ['Indexes','FollowSymLinks','MultiViews'] }],
+ }
+```
+
+######`order`
+Sets the order of processing `Allow` and `Deny` statements as per [Apache core documentation](http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order). An example:
+
+```puppet
+ apache::vhost { 'sample.example.net':
+ docroot => '/path/to/directory',
+ directories => [ { path => '/path/to/directory', order => 'Allow, Deny' } ],
+ }
+```
+
+
+######`auth_type`
+
+Sets the value for `AuthType` as per the [Apache AuthType
+documentation](https://httpd.apache.org/docs/2.2/mod/core.html#authtype).
+
+######`auth_name`
+
+Sets the value for `AuthName` as per the [Apache AuthName
+documentation](https://httpd.apache.org/docs/2.2/mod/core.html#authname).
+
+######`auth_digest_algorithm`
+
+Sets the value for `AuthDigestAlgorithm` as per the [Apache
+AuthDigestAlgorithm
+documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestalgorithm)
+
+######`auth_digest_domain`
+
+Sets the value for `AuthDigestDomain` as per the [Apache AuthDigestDomain
+documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestdomain).
+
+######`auth_digest_nonce_lifetime`
+
+Sets the value for `AuthDigestNonceLifetime` as per the [Apache
+AuthDigestNonceLifetime
+documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestnoncelifetime)
+
+######`auth_digest_provider`
+
+Sets the value for `AuthDigestProvider` as per the [Apache AuthDigestProvider
+documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestprovider).
+
+######`auth_digest_qop`
+
+Sets the value for `AuthDigestQop` as per the [Apache AuthDigestQop
+documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestqop).
+
+######`auth_digest_shmem_size`
+
+Sets the value for `AuthAuthDigestShmemSize` as per the [Apache AuthDigestShmemSize
+documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestshmemsize).
+
+######`auth_basic_authoritative`
+
+Sets the value for `AuthBasicAuthoritative` as per the [Apache
+AuthBasicAuthoritative
+documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html#authbasicauthoritative).
+
+######`auth_basic_fake`
+
+Sets the value for `AuthBasicFake` as per the [Apache AuthBasicFake
+documentation](https://httpd.apache.org/docs/trunk/mod/mod_auth_basic.html#authbasicfake).
+
+######`auth_basic_provider`
+
+Sets the value for `AuthBasicProvider` as per the [Apache AuthBasicProvider
+documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html#authbasicprovider).
+
+######`auth_user_file`
+
+Sets the value for `AuthUserFile` as per the [Apache AuthUserFile
+documentation](https://httpd.apache.org/docs/2.2/mod/mod_authn_file.html#authuserfile).
+
+######`auth_require`
+
+Sets the value for `AuthName` as per the [Apache Require
+documentation](https://httpd.apache.org/docs/2.2/mod/core.html#require)
+
+
+######`passenger_enabled`
+
+Sets the value for the `PassengerEnabled` directory to `on` or `off` as per the [Passenger documentation](http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerEnabled).
+
+```puppet
+ apache::vhost { 'sample.example.net':
+ docroot => '/path/to/directory',
+ directories => [ { path => '/path/to/directory', passenger_enabled => 'off' } ],
+ }
+```
+
+**Note:** This directive requires `apache::mod::passenger` to be active, Apache may not start with an unrecognised directive without it.
+
+**Note:** Be aware that there is an [issue](http://www.conandalton.net/2010/06/passengerenabled-off-not-working.html) using the `PassengerEnabled` directive with the `PassengerHighPerformance` directive.
+
+######`custom_fragment`
+
+Pass a string of custom configuration directives to be placed at the end of the
+directory configuration.
+
+#####`docroot`
+
+Provides the DocumentRoot directive, identifying the directory Apache serves files from.
+
+#####`docroot_group`
+
+Sets group access to the docroot directory. Defaults to 'root'.
+
+#####`docroot_owner`
+
+Sets individual user access to the docroot directory. Defaults to 'root'.
+
+#####`error_log`
+
+Specifies whether `*_error.log` directives should be configured. Defaults to 'true'.
+
+#####`error_log_file`
+
+Points to the `*_error.log` file. Defaults to 'undef'.
+
+#####`error_log_pipe`
+
+Specifies a pipe to send error log messages to. Defaults to 'undef'.
+
+#####`error_log_syslog`
+
+Sends all error log messages to syslog. Defaults to 'undef'.
+
+#####`ensure`
+
+Specifies if the vhost file is present or absent.
+
+#####`ip`
+
+The IP address the vhost listens on. Defaults to 'undef'.
+
+#####`ip_based`
+
+Enables an IP-based vhost. This parameter inhibits the creation of a NameVirtualHost directive, since those are used to funnel requests to name-based vhosts. Defaults to 'false'.
+
+#####`logroot`
+
+Specifies the location of the virtual host's logfiles. Defaults to `/var/log/<apache log location>/`.
+
+#####`no_proxy_uris`
+
+Specifies URLs you do not want to proxy. This parameter is meant to be used in combination with `proxy_dest`.
+
+#####`options`
+
+Lists the options for the given virtual host
+
+```puppet
+ apache::vhost { 'site.name.fdqn':
+ …
+ options => ['Indexes','FollowSymLinks','MultiViews'],
+ }
+```
+
+#####`override`
+
+Sets the overrides for the given virtual host. Accepts an array of AllowOverride arguments.
+
+#####`port`
+
+Sets the port the host is configured on.
+
+#####`priority`
+
+Sets the relative load-order for Apache httpd VirtualHost configuration files. Defaults to '25'.
+
+If nothing matches the priority, the first name-based vhost will be used. Likewise, passing a higher priority will cause the alphabetically first name-based vhost to be used if no other names match.
+
+*Note*: You should not need to use this parameter. However, if you do use it, be aware that the `default_vhost` parameter for `apache::vhost` passes a priority of '15'.
+
+#####`proxy_dest`
+
+Specifies the destination address of a proxypass configuration. Defaults to 'undef'.
+
+#####`proxy_pass`
+
+Specifies an array of path => uri for a proxypass configuration. Defaults to 'undef'.
+
+Example:
+
+```puppet
+$proxy_pass = [
+ { 'path' => '/a', 'url' => 'http://backend-a/' },
+ { 'path' => '/b', 'url' => 'http://backend-b/' },
+ { 'path' => '/c', 'url' => 'http://backend-a/c' }
+]
+
+apache::vhost { 'site.name.fdqn':
+ …
+ proxy_pass => $proxy_pass,
+}
+```
+
+#####`rack_base_uris`
+
+Specifies the resource identifiers for a rack configuration. The file paths specified will be listed as rack application roots for passenger/rack in the `_rack.erb` template. Defaults to 'undef'.
+
+#####`redirect_dest`
+
+Specifies the address to redirect to. Defaults to 'undef'.
+
+#####`redirect_source`
+
+Specifies the source items? that will redirect to the destination specified in `redirect_dest`. If more than one item for redirect is supplied, the source and destination must be the same length, and the items are order-dependent.
+
+```puppet
+ apache::vhost { 'site.name.fdqn':
+ …
+ redirect_source => ['/images','/downloads'],
+ redirect_dest => ['http://img.example.com/','http://downloads.example.com/'],
+ }
+```
+
+#####`redirect_status`
+
+Specifies the status to append to the redirect. Defaults to 'undef'.
+
+```puppet
+ apache::vhost { 'site.name.fdqn':
+ …
+ redirect_status => ['temp','permanent'],
+ }
+```
+
+#####`request_headers`
+
+Specifies additional request headers.
+
+```puppet
+ apache::vhost { 'site.name.fdqn':
+ …
+ request_headers => [
+ 'append MirrorID "mirror 12"',
+ 'unset MirrorID',
+ ],
+ }
+```
+
+#####`rewrite_base`
+
+Limits the `rewrite_rule` to the specified base URL. Defaults to 'undef'.
+
+```puppet
+ apache::vhost { 'site.name.fdqn':
+ …
+ rewrite_rule => '^index\.html$ welcome.html',
+ rewrite_base => '/blog/',
+ }
+```
+
+The above example would limit the index.html -> welcome.html rewrite to only something inside of http://example.com/blog/.
+
+#####`rewrite_cond`
+
+Rewrites a URL via `rewrite_rule` based on the truth of specified conditions. For example
+
+```puppet
+ apache::vhost { 'site.name.fdqn':
+ …
+ rewrite_cond => '%{HTTP_USER_AGENT} ^MSIE',
+ }
+```
+
+will rewrite URLs only if the visitor is using IE. Defaults to 'undef'.
+
+*Note*: At the moment, each vhost is limited to a single list of rewrite conditions. In the future, you will be able to specify multiple `rewrite_cond` and `rewrite_rules` per vhost, so that different conditions get different rewrites.
+
+#####`rewrite_rule`
+
+Creates URL rewrite rules. Defaults to 'undef'. This parameter allows you to specify, for example, that anyone trying to access index.html will be served welcome.html.
+
+```puppet
+ apache::vhost { 'site.name.fdqn':
+ …
+ rewrite_rule => '^index\.html$ welcome.html',
+ }
+```
+
+#####`scriptalias`
+
+Defines a directory of CGI scripts to be aliased to the path '/cgi-bin'
+
+#####`serveradmin`
+
+Specifies the email address Apache will display when it renders one of its error pages.
+
+#####`serveraliases`
+
+Sets the server aliases of the site.
+
+#####`servername`
+
+Sets the primary name of the virtual host.
+
+#####`setenv`
+
+Used by HTTPD to set environment variables for vhosts. Defaults to '[]'.
+
+#####`setenvif`
+
+Used by HTTPD to conditionally set environment variables for vhosts. Defaults to '[]'.
+
+#####`ssl`
+
+Enables SSL for the virtual host. SSL vhosts only respond to HTTPS queries. Valid values are 'true' or 'false'.
+
+#####`ssl_ca`
+
+Specifies the certificate authority.
+
+#####`ssl_cert`
+
+Specifies the SSL certification.
+
+#####`ssl_certs_dir`
+
+Specifies the location of the SSL certification directory. Defaults to `/etc/ssl/certs`.
+
+#####`ssl_chain`
+
+Specifies the SSL chain.
+
+#####`ssl_crl`
+
+Specifies the certificate revocation list to use.
+
+#####`ssl_crl_path`
+
+Specifies the location of the certificate revocation list.
+
+#####`ssl_key`
+
+Specifies the SSL key.
+
+#####`sslproxyengine`
+
+Specifies whether to use `SSLProxyEngine` or not. Defaults to `false`.
+
+#####`vhost_name`
+
+This parameter is for use with name-based virtual hosting. Defaults to '*'.
+
+#####`itk`
+
+Hash containing infos to configure itk as per the [ITK documentation](http://mpm-itk.sesse.net/).
+
+Keys could be:
+* user + group
+* assignuseridexpr
+* assigngroupidexpr
+* maxclientvhost
+* nice
+* limituidrange (Linux 3.5.0 or newer)
+* limitgidrange (Linux 3.5.0 or newer)
+
+Usage will typically look like:
+
+```puppet
+ apache::vhost { 'sample.example.net':
+ docroot => '/path/to/directory',
+ itk => {
+ user => 'someuser',
+ group => 'somegroup',
+ },
+ }
+```
+
+###Virtual Host Examples
+
+The Apache module allows you to set up pretty much any configuration of virtual host you might desire. This section will address some common configurations. Please see the [Tests section](https://github.com/puppetlabs/puppetlabs-apache/tree/master/tests) for even more examples.
+
+Configure a vhost with a server administrator
+
+```puppet
+ apache::vhost { 'third.example.com':
+ port => '80',
+ docroot => '/var/www/third',
+ serveradmin => 'admin@example.com',
+ }
+```
+
+- - -
+
+Set up a vhost with aliased servers
+
+```puppet
+ apache::vhost { 'sixth.example.com':
+ serveraliases => [
+ 'sixth.example.org',
+ 'sixth.example.net',
+ ],
+ port => '80',
+ docroot => '/var/www/fifth',
+ }
+```
+
+- - -
+
+Configure a vhost with a cgi-bin
+
+```puppet
+ apache::vhost { 'eleventh.example.com':
+ port => '80',
+ docroot => '/var/www/eleventh',
+ scriptalias => '/usr/lib/cgi-bin',
+ }
+```
+
+- - -
+
+Set up a vhost with a rack configuration
+
+```puppet
+ apache::vhost { 'fifteenth.example.com':
+ port => '80',
+ docroot => '/var/www/fifteenth',
+ rack_base_uris => ['/rackapp1', '/rackapp2'],
+ }
+```
+
+- - -
+
+Set up a mix of SSL and non-SSL vhosts at the same domain
+
+```puppet
+ #The non-ssl vhost
+ apache::vhost { 'first.example.com non-ssl':
+ servername => 'first.example.com',
+ port => '80',
+ docroot => '/var/www/first',
+ }
+
+ #The SSL vhost at the same domain
+ apache::vhost { 'first.example.com ssl':
+ servername => 'first.example.com',
+ port => '443',
+ docroot => '/var/www/first',
+ ssl => true,
+ }
+```
+
+- - -
+
+Configure a vhost to redirect non-SSL connections to SSL
+
+```puppet
+ apache::vhost { 'sixteenth.example.com non-ssl':
+ servername => 'sixteenth.example.com',
+ port => '80',
+ docroot => '/var/www/sixteenth',
+ redirect_status => 'permanent'
+ redirect_dest => 'https://sixteenth.example.com/'
+ }
+ apache::vhost { 'sixteenth.example.com ssl':
+ servername => 'sixteenth.example.com',
+ port => '443',
+ docroot => '/var/www/sixteenth',
+ ssl => true,
+ }
+```
+
+- - -
+
+Set up IP-based vhosts on any listen port and have them respond to requests on specific IP addresses. In this example, we will set listening on ports 80 and 81. This is required because the example vhosts are not declared with a port parameter.
+
+```puppet
+ apache::listen { '80': }
+ apache::listen { '81': }
+```
+
+Then we will set up the IP-based vhosts
+
+```puppet
+ apache::vhost { 'first.example.com':
+ ip => '10.0.0.10',
+ docroot => '/var/www/first',
+ ip_based => true,
+ }
+ apache::vhost { 'second.example.com':
+ ip => '10.0.0.11',
+ docroot => '/var/www/second',
+ ip_based => true,
+ }
+```
+
+- - -
+
+Configure a mix of name-based and IP-based vhosts. First, we will add two IP-based vhosts on 10.0.0.10, one SSL and one non-SSL
+
+```puppet
+ apache::vhost { 'The first IP-based vhost, non-ssl':
+ servername => 'first.example.com',
+ ip => '10.0.0.10',
+ port => '80',
+ ip_based => true,
+ docroot => '/var/www/first',
+ }
+ apache::vhost { 'The first IP-based vhost, ssl':
+ servername => 'first.example.com',
+ ip => '10.0.0.10',
+ port => '443',
+ ip_based => true,
+ docroot => '/var/www/first-ssl',
+ ssl => true,
+ }
+```
+
+Then, we will add two name-based vhosts listening on 10.0.0.20
+
+```puppet
+ apache::vhost { 'second.example.com':
+ ip => '10.0.0.20',
+ port => '80',
+ docroot => '/var/www/second',
+ }
+ apache::vhost { 'third.example.com':
+ ip => '10.0.0.20',
+ port => '80',
+ docroot => '/var/www/third',
+ }
+```
+
+If you want to add two name-based vhosts so that they will answer on either 10.0.0.10 or 10.0.0.20, you **MUST** declare `add_listen => 'false'` to disable the otherwise automatic 'Listen 80', as it will conflict with the preceding IP-based vhosts.
+
+```puppet
+ apache::vhost { 'fourth.example.com':
+ port => '80',
+ docroot => '/var/www/fourth',
+ add_listen => false,
+ }
+ apache::vhost { 'fifth.example.com':
+ port => '80',
+ docroot => '/var/www/fifth',
+ add_listen => false,
+ }
+```
+
+##Implementation
+
+###Classes and Defined Types
+
+####Class: `apache::dev`
+
+Installs Apache development libraries
+
+```puppet
+ class { 'apache::dev': }
+```
+
+####Defined Type: `apache::listen`
+
+Controls which ports Apache binds to for listening based on the title:
+
+```puppet
+ apache::listen { '80': }
+ apache::listen { '443': }
+```
+
+Declaring this defined type will add all `Listen` directives to the `ports.conf` file in the Apache httpd configuration directory. `apache::listen` titles should always take the form of: `<port>`, `<ipv4>:<port>`, or `[<ipv6>]:<port>`
+
+Apache httpd requires that `Listen` directives must be added for every port. The `apache::vhost` defined type will automatically add `Listen` directives unless the `apache::vhost` is passed `add_listen => false`.
+
+####Defined Type: `apache::namevirtualhost`
+
+Enables named-based hosting of a virtual host
+
+```puppet
+ class { 'apache::namevirtualhost`: }
+```
+
+Declaring this defined type will add all `NameVirtualHost` directives to the `ports.conf` file in the Apache https configuration directory. `apache::namevirtualhost` titles should always take the form of: `*`, `*:<port>`, `_default_:<port>`, `<ip>`, or `<ip>:<port>`.
+
+####Defined Type: `apache::balancermember`
+
+Define members of a proxy_balancer set (mod_proxy_balancer). Very useful when using exported resources.
+
+On every app server you can export a balancermember like this:
+
+```puppet
+ @@apache::balancermember { "${::fqdn}-puppet00":
+ balancer_cluster => 'puppet00',
+ url => "ajp://${::fqdn}:8009"
+ options => ['ping=5', 'disablereuse=on', 'retry=5', 'ttl=120'],
+ }
+```
+
+And on the proxy itself you create the balancer cluster using the defined type apache::balancer:
+
+```puppet
+ apache::balancer { 'puppet00': }
+```
+
+If you need to use ProxySet in the balncer config you can do as so:
+
+```puppet
+ apache::balancer { 'puppet01':
+ proxy_set => {'stickysession' => 'JSESSIONID'},
+ }
+```
+
+###Templates
+
+The Apache module relies heavily on templates to enable the `vhost` and `apache::mod` defined types. These templates are built based on Facter facts around your operating system. Unless explicitly called out, most templates are not meant for configuration.
+
+##Limitations
+
+This has been tested on Ubuntu Precise, Debian Wheezy, and CentOS 5.8.
+
+##Development
+
+### Overview
+
+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.
+
+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.
+
+You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing)
+
+### Running tests
+
+This project contains tests for both [rspec-puppet](http://rspec-puppet.com/) and [rspec-system](https://github.com/puppetlabs/rspec-system) to verify functionality. For in-depth information please see their respective documentation.
+
+Quickstart:
+
+ gem install bundler
+ bundle install
+ bundle exec rake spec
+ bundle exec rake spec:system
+
+##Copyright and License
+
+Copyright (C) 2012 [Puppet Labs](https://www.puppetlabs.com/) Inc
+
+Puppet Labs can be contacted at: info@puppetlabs.com
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/puppet/modules/apache/README.passenger.md b/puppet/modules/apache/README.passenger.md
new file mode 100644
index 0000000..80dbfe0
--- /dev/null
+++ b/puppet/modules/apache/README.passenger.md
@@ -0,0 +1,89 @@
+# Passenger
+
+Just enabling the Passenger module is insufficient for the use of Passenger in production. Passenger should be tunable to better fit the environment in which it is run while being aware of the resources it required.
+
+To this end the Apache passenger module has been modified to apply system wide Passenger tuning declarations to `passenger.conf`. Declarations specific to a virtual host should be passed through when defining a `vhost` (e.g. `rack_base_uris' parameter on the `apache::vhost` class, check `README.md`).
+
+# Parameters for `apache::mod::passenger`
+
+The following declarations are supported and can be passed to `apache::mod::passenger` as parameters, for example:
+
+```
+class {'apache::mod::passenger':
+ passenger_high_performance => 'on',
+ rails_autodetect => 'off',
+}
+```
+
+The general form is using the all lower case version of the declaration.
+
+If you pass a default value to `apache::mod::passenger` it will be ignored and not passed through to the configuration file.
+
+## passenger_high_performance
+
+Default is `off`, when turned `on` Passenger runs in a higher performance mode that can be less compatible with other Apache modules.
+
+http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerHighPerformance
+
+## passenger_max_pool_size
+
+Set's the maximum number of Passenger application processes that may simultaneously run. The default value is 6.
+
+http://www.modrails.com/documentation/Users%20guide%20Apache.html#_passengermaxpoolsize_lt_integer_gt
+
+## passenger_pool_idle_time
+
+The maximum number of seconds a Passenger Application process will be allowed to remain idle before being shut down. The default value is 300.
+
+http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerPoolIdleTime
+
+## passenger_max_requests
+
+The maximum number of request a Passenger application will process before being restarted. The default value is 0, which indicates that a process will only shut down if the Pool Idle Time (see above) expires.
+
+http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerMaxRequests
+
+## passenger_stat_throttle_rate
+
+Sets how often Passenger performs file system checks, at most once every _x_ seconds. Default is 0, which means the checks are performed with every request.
+
+http://www.modrails.com/documentation/Users%20guide%20Apache.html#_passengerstatthrottlerate_lt_integer_gt
+
+## rack_auto_detect
+
+Should Passenger automatically detect if the document root of a virtual host is a Rack application. The default is `on`
+
+http://www.modrails.com/documentation/Users%20guide%20Apache.html#_rackautodetect_lt_on_off_gt
+
+## rails_auto_detect
+
+Should Passenger automatically detect if the document root of a virtual host is a Rails application. The default is on.
+
+http://www.modrails.com/documentation/Users%20guide%20Apache.html#_railsautodetect_lt_on_off_gt
+
+# Attribution
+
+The Passenger tuning parameters for the `apache::mod::puppet` Puppet class was modified by Aaron Hicks (hicksa@landcareresearch.co.nz) for work on the NeSI Project and the Tuakiri New Zealand Access Federation as a fork from the PuppetLabs Apache module on GitHub.
+
+* https://github.com/puppetlabs/puppetlabs-apache
+* https://github.com/nesi/puppetlabs-apache
+* http://www.nesi.org.nz//
+* https://tuakiri.ac.nz/confluence/display/Tuakiri/Home
+
+# Copyright and License
+
+Copyright (C) 2012 [Puppet Labs](https://www.puppetlabs.com/) Inc
+
+Puppet Labs can be contacted at: info@puppetlabs.com
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/puppet/modules/apache/Rakefile b/puppet/modules/apache/Rakefile
new file mode 100644
index 0000000..bb60173
--- /dev/null
+++ b/puppet/modules/apache/Rakefile
@@ -0,0 +1,2 @@
+require 'puppetlabs_spec_helper/rake_tasks'
+require 'rspec-system/rake_task'
diff --git a/puppet/modules/apache/files/httpd b/puppet/modules/apache/files/httpd
new file mode 100644
index 0000000..d65a8d4
--- /dev/null
+++ b/puppet/modules/apache/files/httpd
@@ -0,0 +1,24 @@
+# Configuration file for the httpd service.
+
+#
+# The default processing model (MPM) is the process-based
+# 'prefork' model. A thread-based model, 'worker', is also
+# available, but does not work with some modules (such as PHP).
+# The service must be stopped before changing this variable.
+#
+#HTTPD=/usr/sbin/httpd.worker
+
+#
+# To pass additional options (for instance, -D definitions) to the
+# httpd binary at startup, set OPTIONS here.
+#
+#OPTIONS=
+#OPTIONS=-DDOWN
+
+#
+# By default, the httpd process is started in the C locale; to
+# change the locale in which the server runs, the HTTPD_LANG
+# variable can be set.
+#
+#HTTPD_LANG=C
+export SHORTHOST=`hostname -s`
diff --git a/puppet/modules/apache/lib/puppet/provider/a2mod.rb b/puppet/modules/apache/lib/puppet/provider/a2mod.rb
new file mode 100644
index 0000000..670aca3
--- /dev/null
+++ b/puppet/modules/apache/lib/puppet/provider/a2mod.rb
@@ -0,0 +1,34 @@
+class Puppet::Provider::A2mod < Puppet::Provider
+ def self.prefetch(mods)
+ instances.each do |prov|
+ if mod = mods[prov.name]
+ mod.provider = prov
+ end
+ end
+ end
+
+ def flush
+ @property_hash.clear
+ end
+
+ def properties
+ if @property_hash.empty?
+ @property_hash = query || {:ensure => :absent}
+ @property_hash[:ensure] = :absent if @property_hash.empty?
+ end
+ @property_hash.dup
+ end
+
+ def query
+ self.class.instances.each do |mod|
+ if mod.name == self.name or mod.name.downcase == self.name
+ return mod.properties
+ end
+ end
+ nil
+ end
+
+ def exists?
+ properties[:ensure] != :absent
+ end
+end
diff --git a/puppet/modules/apache/lib/puppet/provider/a2mod/a2mod.rb b/puppet/modules/apache/lib/puppet/provider/a2mod/a2mod.rb
new file mode 100644
index 0000000..e257a57
--- /dev/null
+++ b/puppet/modules/apache/lib/puppet/provider/a2mod/a2mod.rb
@@ -0,0 +1,35 @@
+require 'puppet/provider/a2mod'
+
+Puppet::Type.type(:a2mod).provide(:a2mod, :parent => Puppet::Provider::A2mod) do
+ desc "Manage Apache 2 modules on Debian and Ubuntu"
+
+ optional_commands :encmd => "a2enmod"
+ optional_commands :discmd => "a2dismod"
+ commands :apache2ctl => "apache2ctl"
+
+ confine :osfamily => :debian
+ defaultfor :operatingsystem => [:debian, :ubuntu]
+
+ def self.instances
+ modules = apache2ctl("-M").lines.collect { |line|
+ m = line.match(/(\w+)_module \(shared\)$/)
+ m[1] if m
+ }.compact
+
+ modules.map do |mod|
+ new(
+ :name => mod,
+ :ensure => :present,
+ :provider => :a2mod
+ )
+ end
+ end
+
+ def create
+ encmd resource[:name]
+ end
+
+ def destroy
+ discmd resource[:name]
+ end
+end
diff --git a/puppet/modules/apache/lib/puppet/provider/a2mod/gentoo.rb b/puppet/modules/apache/lib/puppet/provider/a2mod/gentoo.rb
new file mode 100644
index 0000000..07319df
--- /dev/null
+++ b/puppet/modules/apache/lib/puppet/provider/a2mod/gentoo.rb
@@ -0,0 +1,116 @@
+require 'puppet/util/filetype'
+Puppet::Type.type(:a2mod).provide(:gentoo, :parent => Puppet::Provider) do
+ desc "Manage Apache 2 modules on Gentoo"
+
+ confine :operatingsystem => :gentoo
+ defaultfor :operatingsystem => :gentoo
+
+ attr_accessor :property_hash
+
+ def create
+ @property_hash[:ensure] = :present
+ end
+
+ def exists?
+ (!(@property_hash[:ensure].nil?) and @property_hash[:ensure] == :present)
+ end
+
+ def destroy
+ @property_hash[:ensure] = :absent
+ end
+
+ def flush
+ self.class.flush
+ end
+
+ class << self
+ attr_reader :conf_file
+ end
+
+ def self.clear
+ @mod_resources = []
+ @modules = []
+ @other_args = ""
+ end
+
+ def self.initvars
+ @conf_file = "/etc/conf.d/apache2"
+ @filetype = Puppet::Util::FileType.filetype(:flat).new(conf_file)
+ @mod_resources = []
+ @modules = []
+ @other_args = ""
+ end
+
+ self.initvars
+
+ # Retrieve an array of all existing modules
+ def self.modules
+ if @modules.length <= 0
+ # Locate the APACHE_OPTS variable
+ records = filetype.read.split(/\n/)
+ apache2_opts = records.grep(/^\s*APACHE2_OPTS=/).first
+
+ # Extract all defines
+ while apache2_opts.sub!(/-D\s+(\w+)/, '')
+ @modules << $1.downcase
+ end
+
+ # Hang on to any remaining options.
+ if apache2_opts.match(/APACHE2_OPTS="(.+)"/)
+ @other_args = $1.strip
+ end
+
+ @modules.sort!.uniq!
+ end
+
+ @modules
+ end
+
+ def self.prefetch(resources={})
+ # Match resources with existing providers
+ instances.each do |provider|
+ if resource = resources[provider.name]
+ resource.provider = provider
+ end
+ end
+
+ # Store all resources using this provider for flushing
+ resources.each do |name, resource|
+ @mod_resources << resource
+ end
+ end
+
+ def self.instances
+ modules.map {|mod| new(:name => mod, :provider => :gentoo, :ensure => :present)}
+ end
+
+ def self.flush
+
+ mod_list = modules
+ mods_to_remove = @mod_resources.select {|mod| mod.should(:ensure) == :absent}.map {|mod| mod[:name]}
+ mods_to_add = @mod_resources.select {|mod| mod.should(:ensure) == :present}.map {|mod| mod[:name]}
+
+ mod_list -= mods_to_remove
+ mod_list += mods_to_add
+ mod_list.sort!.uniq!
+
+ if modules != mod_list
+ opts = @other_args + " "
+ opts << mod_list.map {|mod| "-D #{mod.upcase}"}.join(" ")
+ opts.strip!
+ opts.gsub!(/\s+/, ' ')
+
+ apache2_opts = %Q{APACHE2_OPTS="#{opts}"}
+ Puppet.debug("Writing back \"#{apache2_opts}\" to #{conf_file}")
+
+ records = filetype.read.split(/\n/)
+
+ opts_index = records.find_index {|i| i.match(/^\s*APACHE2_OPTS/)}
+ records[opts_index] = apache2_opts
+
+ filetype.backup
+ filetype.write(records.join("\n"))
+ @modules = mod_list
+ end
+ end
+end
diff --git a/puppet/modules/apache/lib/puppet/provider/a2mod/modfix.rb b/puppet/modules/apache/lib/puppet/provider/a2mod/modfix.rb
new file mode 100644
index 0000000..8f35b2e
--- /dev/null
+++ b/puppet/modules/apache/lib/puppet/provider/a2mod/modfix.rb
@@ -0,0 +1,12 @@
+Puppet::Type.type(:a2mod).provide :modfix do
+ desc "Dummy provider for A2mod.
+
+ Fake nil resources when there is no crontab binary available. Allows
+ puppetd to run on a bootstrapped machine before a Cron package has been
+ installed. Workaround for: http://projects.puppetlabs.com/issues/2384
+ "
+
+ def self.instances
+ []
+ end
+end
\ No newline at end of file
diff --git a/puppet/modules/apache/lib/puppet/provider/a2mod/redhat.rb b/puppet/modules/apache/lib/puppet/provider/a2mod/redhat.rb
new file mode 100644
index 0000000..ea5494c
--- /dev/null
+++ b/puppet/modules/apache/lib/puppet/provider/a2mod/redhat.rb
@@ -0,0 +1,60 @@
+require 'puppet/provider/a2mod'
+
+Puppet::Type.type(:a2mod).provide(:redhat, :parent => Puppet::Provider::A2mod) do
+ desc "Manage Apache 2 modules on RedHat family OSs"
+
+ commands :apachectl => "apachectl"
+
+ confine :osfamily => :redhat
+ defaultfor :osfamily => :redhat
+
+ require 'pathname'
+
+ # modpath: Path to default apache modules directory /etc/httpd/mod.d
+ # modfile: Path to module load configuration file; Default: resides under modpath directory
+ # libfile: Path to actual apache module library. Added in modfile LoadModule
+
+ attr_accessor :modfile, :libfile
+ class << self
+ attr_accessor :modpath
+ def preinit
+ @modpath = "/etc/httpd/mod.d"
+ end
+ end
+
+ self.preinit
+
+ def create
+ File.open(modfile,'w') do |f|
+ f.puts "LoadModule #{resource[:identifier]} #{libfile}"
+ end
+ end
+
+ def destroy
+ File.delete(modfile)
+ end
+
+ def self.instances
+ modules = apachectl("-M").lines.collect { |line|
+ m = line.match(/(\w+)_module \(shared\)$/)
+ m[1] if m
+ }.compact
+
+ modules.map do |mod|
+ new(
+ :name => mod,
+ :ensure => :present,
+ :provider => :redhat
+ )
+ end
+ end
+
+ def modfile
+ modfile ||= "#{self.class.modpath}/#{resource[:name]}.load"
+ end
+
+ # Set libfile path: If absolute path is passed, then maintain it. Else, make it default from 'modules' dir.
+ def libfile
+ libfile = Pathname.new(resource[:lib]).absolute? ? resource[:lib] : "modules/#{resource[:lib]}"
+ end
+end
diff --git a/puppet/modules/apache/lib/puppet/type/a2mod.rb b/puppet/modules/apache/lib/puppet/type/a2mod.rb
new file mode 100644
index 0000000..07a911e
--- /dev/null
+++ b/puppet/modules/apache/lib/puppet/type/a2mod.rb
@@ -0,0 +1,30 @@
+Puppet::Type.newtype(:a2mod) do
+ @doc = "Manage Apache 2 modules"
+
+ ensurable
+
+ newparam(:name) do
+ Puppet.warning "The a2mod provider is deprecated, please use apache::mod instead"
+ desc "The name of the module to be managed"
+
+ isnamevar
+
+ end
+
+ newparam(:lib) do
+ desc "The name of the .so library to be loaded"
+
+ defaultto { "mod_#{@resource[:name]}.so" }
+ end
+
+ newparam(:identifier) do
+ desc "Module identifier string used by LoadModule. Default: module-name_module"
+
+ # http://httpd.apache.org/docs/2.2/mod/module-dict.html#ModuleIdentifier
+
+ defaultto { "#{resource[:name]}_module" }
+ end
+
+ autorequire(:package) { catalog.resource(:package, 'httpd')}
+
+end
diff --git a/puppet/modules/apache/manifests/balancer.pp b/puppet/modules/apache/manifests/balancer.pp
new file mode 100644
index 0000000..1e4130f
--- /dev/null
+++ b/puppet/modules/apache/manifests/balancer.pp
@@ -0,0 +1,80 @@
+# == Define Resource Type: apache::balancer
+#
+# This type will create an apache balancer cluster file inside the conf.d
+# directory. Each balancer cluster needs one or more balancer members (that can
+# be declared with the apache::balancermember defined resource type). Using
+# storeconfigs, you can export the apache::balancermember resources on all
+# balancer members, and then collect them on a single apache load balancer
+# server.
+#
+# === Requirement/Dependencies:
+#
+# Currently requires the puppetlabs/concat module on the Puppet Forge and uses
+# storeconfigs on the Puppet Master to export/collect resources from all
+# balancer members.
+#
+# === Parameters
+#
+# [*name*]
+# The namevar of the defined resource type is the balancer clusters name.
+# This name is also used in the name of the conf.d file
+#
+# [*proxy_set*]
+# Hash, default empty. If given, each key-value pair will be used as a ProxySet
+# line in the configuration.
+#
+# [*collect_exported*]
+# Boolean, default 'true'. True means 'collect exported @@balancermember
+# resources' (for the case when every balancermember node exports itself),
+# false means 'rely on the existing declared balancermember resources' (for the
+# case when you know the full set of balancermembers in advance and use
+# apache::balancermember with array arguments, which allows you to deploy
+# everything in 1 run)
+#
+#
+# === Examples
+#
+# Exporting the resource for a balancer member:
+#
+# apache::balancer { 'puppet00': }
+#
+define apache::balancer (
+ $proxy_set = {},
+ $collect_exported = true,
+) {
+ include concat::setup
+ include apache::mod::proxy_balancer
+
+ $target = "${::apache::params::confd_dir}/balancer_${name}.conf"
+
+ concat { $target:
+ owner => '0',
+ group => '0',
+ mode => '0644',
+ notify => Service['httpd'],
+ }
+
+ concat::fragment { "00-${name}-header":
+ target => $target,
+ order => '01',
+ content => "<Proxy balancer://${name}>\n",
+ }
+
+ if $collect_exported {
+ Apache::Balancermember <<| balancer_cluster == $name |>>
+ }
+ # else: the resources have been created and they introduced their
+ # concat fragments. We don't have to do anything about them.
+
+ concat::fragment { "01-${name}-proxyset":
+ target => $target,
+ order => '19',
+ content => inline_template("<% proxy_set.each do |key, value| %> Proxyset <%= key %>=<%= value %>\n<% end %>"),
+ }
+
+ concat::fragment { "01-${name}-footer":
+ target => $target,
+ order => '20',
+ content => "</Proxy>\n",
+ }
+}
diff --git a/puppet/modules/apache/manifests/balancermember.pp b/puppet/modules/apache/manifests/balancermember.pp
new file mode 100644
index 0000000..c48cb1e
--- /dev/null
+++ b/puppet/modules/apache/manifests/balancermember.pp
@@ -0,0 +1,52 @@
+# == Define Resource Type: apache::balancermember
+#
+# This type will setup a balancer member inside a listening service
+# configuration block in /etc/apache/apache.cfg on the load balancer.
+# currently it only has the ability to specify the instance name, url and an
+# array of options. More features can be added as needed. The best way to
+# implement this is to export this resource for all apache balancer member
+# servers, and then collect them on the main apache load balancer.
+#
+# === Requirement/Dependencies:
+#
+# Currently requires the puppetlabs/concat module on the Puppet Forge and
+# uses storeconfigs on the Puppet Master to export/collect resources
+# from all balancer members.
+#
+# === Parameters
+#
+# [*name*]
+# The title of the resource is arbitrary and only utilized in the concat
+# fragment name.
+#
+# [*balancer_cluster*]
+# The apache service's instance name (or, the title of the apache::balancer
+# resource). This must match up with a declared apache::balancer resource.
+#
+# [*url*]
+# The url used to contact the balancer member server.
+#
+# [*options*]
+# An array of options to be specified after the url.
+#
+# === Examples
+#
+# Exporting the resource for a balancer member:
+#
+# @@apache::balancermember { 'apache':
+# balancer_cluster => 'puppet00',
+# url => "ajp://${::fqdn}:8009"
+# options => ['ping=5', 'disablereuse=on', 'retry=5', 'ttl=120'],
+# }
+#
+define apache::balancermember(
+ $balancer_cluster,
+ $url = "http://${::fqdn}/",
+ $options = [],
+) {
+
+ concat::fragment { "BalancerMember ${url}":
+ target => "${::apache::params::confd_dir}/balancer_${balancer_cluster}.conf",
+ content => inline_template(" BalancerMember ${url} <%= @options.join ' ' %>\n"),
+ }
+}
diff --git a/puppet/modules/apache/manifests/default_mods.pp b/puppet/modules/apache/manifests/default_mods.pp
new file mode 100644
index 0000000..3d4b22c
--- /dev/null
+++ b/puppet/modules/apache/manifests/default_mods.pp
@@ -0,0 +1,73 @@
+class apache::default_mods (
+ $all = true,
+ $mods = undef,
+) {
+ # These are modules required to run the default configuration.
+ # They are not configurable at this time, so we just include
+ # them to make sure it works.
+ case $::osfamily {
+ 'redhat': {
+ apache::mod { 'log_config': }
+ }
+ default: {}
+ }
+ apache::mod { 'authz_host': }
+
+ # The rest of the modules only get loaded if we want all modules enabled
+ if $all {
+ case $::osfamily {
+ 'debian': {
+ include apache::mod::reqtimeout
+ }
+ 'redhat': {
+ include apache::mod::cache
+ include apache::mod::mime_magic
+ include apache::mod::vhost_alias
+ apache::mod { 'actions': }
+ apache::mod { 'auth_digest': }
+ apache::mod { 'authn_alias': }
+ apache::mod { 'authn_anon': }
+ apache::mod { 'authn_dbm': }
+ apache::mod { 'authn_default': }
+ apache::mod { 'authz_dbm': }
+ apache::mod { 'authz_owner': }
+ apache::mod { 'expires': }
+ apache::mod { 'ext_filter': }
+ apache::mod { 'include': }
+ apache::mod { 'logio': }
+ apache::mod { 'rewrite': }
+ apache::mod { 'speling': }
+ apache::mod { 'substitute': }
+ apache::mod { 'suexec': }
+ apache::mod { 'usertrack': }
+ apache::mod { 'version': }
+ }
+ default: {}
+ }
+ case $apache::mpm_module {
+ 'prefork': {
+ include apache::mod::cgi
+ }
+ 'worker': {
+ include apache::mod::cgid
+ }
+ }
+ include apache::mod::alias
+ include apache::mod::autoindex
+ include apache::mod::dav
+ include apache::mod::dav_fs
+ include apache::mod::deflate
+ include apache::mod::dir
+ include apache::mod::mime
+ include apache::mod::negotiation
+ include apache::mod::setenvif
+ apache::mod { 'auth_basic': }
+ apache::mod { 'authn_file': }
+ apache::mod { 'authz_default': }
+ apache::mod { 'authz_groupfile': }
+ apache::mod { 'authz_user': }
+ apache::mod { 'env': }
+ } elsif $mods {
+ apache::default_mods::load { $mods: }
+ }
+}
diff --git a/puppet/modules/apache/manifests/default_mods/load.pp b/puppet/modules/apache/manifests/default_mods/load.pp
new file mode 100644
index 0000000..ae2f76e
--- /dev/null
+++ b/puppet/modules/apache/manifests/default_mods/load.pp
@@ -0,0 +1,8 @@
+# private define
+define apache::default_mods::load ($module = $title) {
+ if defined("apache::mod::${module}") {
+ include "apache::mod::${module}"
+ } else {
+ apache::mod { $module: }
+ }
+}
diff --git a/puppet/modules/apache/manifests/dev.pp b/puppet/modules/apache/manifests/dev.pp
new file mode 100644
index 0000000..ea86ada
--- /dev/null
+++ b/puppet/modules/apache/manifests/dev.pp
@@ -0,0 +1,8 @@
+class apache::dev {
+ include apache::params
+ $packages = $apache::params::dev_packages
+ package { $packages:
+ ensure => present,
+ require => Package['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/init.pp b/puppet/modules/apache/manifests/init.pp
new file mode 100644
index 0000000..d0cb314
--- /dev/null
+++ b/puppet/modules/apache/manifests/init.pp
@@ -0,0 +1,258 @@
+# Class: apache
+#
+# This class installs Apache
+#
+# Parameters:
+#
+# Actions:
+# - Install Apache
+# - Manage Apache service
+#
+# Requires:
+#
+# Sample Usage:
+#
+class apache (
+ $default_mods = true,
+ $default_vhost = true,
+ $default_ssl_vhost = false,
+ $default_ssl_cert = $apache::params::default_ssl_cert,
+ $default_ssl_key = $apache::params::default_ssl_key,
+ $default_ssl_chain = undef,
+ $default_ssl_ca = undef,
+ $default_ssl_crl_path = undef,
+ $default_ssl_crl = undef,
+ $service_enable = true,
+ $purge_configs = true,
+ $purge_vdir = false,
+ $serveradmin = 'root@localhost',
+ $sendfile = false,
+ $error_documents = false,
+ $httpd_dir = $apache::params::httpd_dir,
+ $confd_dir = $apache::params::confd_dir,
+ $vhost_dir = $apache::params::vhost_dir,
+ $vhost_enable_dir = $apache::params::vhost_enable_dir,
+ $mod_dir = $apache::params::mod_dir,
+ $mod_enable_dir = $apache::params::mod_enable_dir,
+ $mpm_module = $apache::params::mpm_module,
+ $conf_template = $apache::params::conf_template,
+ $servername = $apache::params::servername,
+ $user = $apache::params::user,
+ $group = $apache::params::group,
+ $keepalive = $apache::params::keepalive,
+ $keepalive_timeout = $apache::params::keepalive_timeout,
+ $logroot = $apache::params::logroot,
+ $ports_file = $apache::params::ports_file,
+) inherits apache::params {
+
+ package { 'httpd':
+ ensure => installed,
+ name => $apache::params::apache_name,
+ notify => Class['Apache::Service'],
+ }
+
+ validate_bool($default_vhost)
+ # true/false is sufficient for both ensure and enable
+ validate_bool($service_enable)
+ if $mpm_module {
+ validate_re($mpm_module, '(prefork|worker|itk)')
+ }
+
+ # declare the web server user and group
+ # Note: requiring the package means the package ought to create them and not puppet
+ group { $group:
+ ensure => present,
+ require => Package['httpd']
+ }
+
+ user { $user:
+ ensure => present,
+ gid => $group,
+ require => Package['httpd'],
+ }
+
+ class { 'apache::service':
+ service_enable => $service_enable,
+ }
+
+ # Deprecated backwards-compatibility
+ if $purge_vdir {
+ warning('Class[\'apache\'] parameter purge_vdir is deprecated in favor of purge_configs')
+ $purge_confd = $purge_vdir
+ } else {
+ $purge_confd = $purge_configs
+ }
+
+ Exec {
+ path => '/bin:/sbin:/usr/bin:/usr/sbin',
+ }
+
+ exec { "mkdir ${confd_dir}":
+ creates => $confd_dir,
+ require => Package['httpd'],
+ }
+ file { $confd_dir:
+ ensure => directory,
+ recurse => true,
+ purge => $purge_confd,
+ notify => Class['Apache::Service'],
+ require => Package['httpd'],
+ }
+
+ if ! defined(File[$mod_dir]) {
+ exec { "mkdir ${mod_dir}":
+ creates => $mod_dir,
+ require => Package['httpd'],
+ }
+ file { $mod_dir:
+ ensure => directory,
+ recurse => true,
+ purge => $purge_configs,
+ notify => Class['Apache::Service'],
+ require => Package['httpd'],
+ }
+ }
+
+ if $mod_enable_dir and ! defined(File[$mod_enable_dir]) {
+ $mod_load_dir = $mod_enable_dir
+ exec { "mkdir ${mod_enable_dir}":
+ creates => $mod_enable_dir,
+ require => Package['httpd'],
+ }
+ file { $mod_enable_dir:
+ ensure => directory,
+ recurse => true,
+ purge => $purge_configs,
+ notify => Class['Apache::Service'],
+ require => Package['httpd'],
+ }
+ } else {
+ $mod_load_dir = $mod_dir
+ }
+
+ if ! defined(File[$vhost_dir]) {
+ exec { "mkdir ${vhost_dir}":
+ creates => $vhost_dir,
+ require => Package['httpd'],
+ }
+ file { $vhost_dir:
+ ensure => directory,
+ recurse => true,
+ purge => $purge_configs,
+ notify => Class['Apache::Service'],
+ require => Package['httpd'],
+ }
+ }
+
+ if $vhost_enable_dir and ! defined(File[$vhost_enable_dir]) {
+ $vhost_load_dir = $vhost_enable_dir
+ exec { "mkdir ${vhost_load_dir}":
+ creates => $vhost_load_dir,
+ require => Package['httpd'],
+ }
+ file { $vhost_enable_dir:
+ ensure => directory,
+ recurse => true,
+ purge => $purge_configs,
+ notify => Class['Apache::Service'],
+ require => Package['httpd'],
+ }
+ } else {
+ $vhost_load_dir = $vhost_dir
+ }
+
+ concat { $ports_file:
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ notify => Class['Apache::Service'],
+ require => Package['httpd'],
+ }
+ concat::fragment { 'Apache ports header':
+ target => $ports_file,
+ content => template('apache/ports_header.erb')
+ }
+
+ if $apache::params::conf_dir and $apache::params::conf_file {
+ case $::osfamily {
+ 'debian': {
+ $docroot = '/var/www'
+ $pidfile = '${APACHE_PID_FILE}'
+ $error_log = 'error.log'
+ $error_documents_path = '/usr/share/apache2/error'
+ $scriptalias = '/usr/lib/cgi-bin'
+ $access_log_file = 'access.log'
+ }
+ 'redhat': {
+ $docroot = '/var/www/html'
+ $pidfile = 'run/httpd.pid'
+ $error_log = 'error_log'
+ $error_documents_path = '/var/www/error'
+ $scriptalias = '/var/www/cgi-bin'
+ $access_log_file = 'access_log'
+ }
+ default: {
+ fail("Unsupported osfamily ${::osfamily}")
+ }
+ }
+ # Template uses:
+ # - $httpd_dir
+ # - $pidfile
+ # - $user
+ # - $group
+ # - $logroot
+ # - $error_log
+ # - $sendfile
+ # - $mod_dir
+ # - $ports_file
+ # - $confd_dir
+ # - $vhost_dir
+ # - $error_documents
+ # - $error_documents_path
+ # - $keepalive
+ # - $keepalive_timeout
+ file { "${apache::params::conf_dir}/${apache::params::conf_file}":
+ ensure => file,
+ content => template($conf_template),
+ notify => Class['Apache::Service'],
+ require => Package['httpd'],
+ }
+
+ # preserve back-wards compatibility to the times when default_mods was
+ # only a boolean value. Now it can be an array (too)
+ if is_array($default_mods) {
+ class { 'apache::default_mods':
+ all => false,
+ mods => $default_mods,
+ }
+ } else {
+ class { 'apache::default_mods':
+ all => $default_mods,
+ }
+ }
+ if $mpm_module {
+ class { "apache::mod::${mpm_module}": }
+ }
+ if $default_vhost {
+ apache::vhost { 'default':
+ port => 80,
+ docroot => $docroot,
+ scriptalias => $scriptalias,
+ serveradmin => $serveradmin,
+ access_log_file => $access_log_file,
+ priority => '15',
+ }
+ }
+ if $default_ssl_vhost {
+ apache::vhost { 'default-ssl':
+ port => 443,
+ ssl => true,
+ docroot => $docroot,
+ scriptalias => $scriptalias,
+ serveradmin => $serveradmin,
+ access_log_file => "ssl_${access_log_file}",
+ priority => '15',
+ }
+ }
+ }
+}
diff --git a/puppet/modules/apache/manifests/listen.pp b/puppet/modules/apache/manifests/listen.pp
new file mode 100644
index 0000000..57982ba
--- /dev/null
+++ b/puppet/modules/apache/manifests/listen.pp
@@ -0,0 +1,10 @@
+define apache::listen {
+ $listen_addr_port = $name
+ include apache::params
+
+ # Template uses: $listen_addr_port
+ concat::fragment { "Listen ${listen_addr_port}":
+ target => $apache::params::ports_file,
+ content => template('apache/listen.erb'),
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod.pp b/puppet/modules/apache/manifests/mod.pp
new file mode 100644
index 0000000..ea9cc3c
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod.pp
@@ -0,0 +1,93 @@
+define apache::mod (
+ $package = undef,
+ $lib = undef
+) {
+ if ! defined(Class['apache']) {
+ fail('You must include the apache base class before using any apache defined resources')
+ }
+
+ $mod = $name
+ #include apache #This creates duplicate resources in rspec-puppet
+ $lib_path = $apache::params::lib_path
+ $mod_dir = $apache::mod_dir
+
+ # Determine if we have special lib
+ $mod_libs = $apache::params::mod_libs
+ $mod_lib = $mod_libs[$mod] # 2.6 compatibility hack
+ if $lib {
+ $lib_REAL = $lib
+ } elsif $mod_lib {
+ $lib_REAL = $mod_lib
+ } else {
+ $lib_REAL = "mod_${mod}.so"
+ }
+
+ # Determine if we have a package
+ $mod_packages = $apache::params::mod_packages
+ $mod_package = $mod_packages[$mod] # 2.6 compatibility hack
+ if $package {
+ $package_REAL = $package
+ } elsif "${mod_package}" {
+ $package_REAL = $mod_package
+ }
+ if $package_REAL {
+ # $package_REAL may be an array
+ package { $package_REAL:
+ ensure => present,
+ require => Package['httpd'],
+ before => File["${mod_dir}/${mod}.load"],
+ }
+ }
+
+ file { "${mod}.load":
+ ensure => file,
+ path => "${mod_dir}/${mod}.load",
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ content => "LoadModule ${mod}_module ${lib_path}/${lib_REAL}\n",
+ require => [
+ Package['httpd'],
+ Exec["mkdir ${mod_dir}"],
+ ],
+ before => File[$mod_dir],
+ notify => Service['httpd'],
+ }
+
+ if $::osfamily == 'Debian' {
+ $enable_dir = $apache::mod_enable_dir
+ file{ "${mod}.load symlink":
+ ensure => link,
+ path => "${enable_dir}/${mod}.load",
+ target => "${mod_dir}/${mod}.load",
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ require => [
+ File["${mod}.load"],
+ Exec["mkdir ${enable_dir}"],
+ ],
+ before => File[$enable_dir],
+ notify => Service['httpd'],
+ }
+ # Each module may have a .conf file as well, which should be
+ # defined in the class apache::mod::module
+ # Some modules do not require this file.
+ if defined(File["${mod}.conf"]) {
+ file{ "${mod}.conf symlink":
+ ensure => link,
+ path => "${enable_dir}/${mod}.conf",
+ target => "${mod_dir}/${mod}.conf",
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ require => [
+ File["${mod}.conf"],
+ Exec["mkdir ${enable_dir}"],
+ ],
+ before => File[$enable_dir],
+ notify => Service['httpd'],
+ }
+ }
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/alias.pp b/puppet/modules/apache/manifests/mod/alias.pp
new file mode 100644
index 0000000..2af7372
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/alias.pp
@@ -0,0 +1,16 @@
+class apache::mod::alias {
+ $icons_path = $::osfamily ? {
+ 'debian' => '/usr/share/apache2/icons',
+ 'redhat' => '/var/www/icons',
+ }
+ apache::mod { 'alias': }
+ # Template uses $icons_path
+ file { 'alias.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/alias.conf",
+ content => template('apache/mod/alias.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/auth_basic.pp b/puppet/modules/apache/manifests/mod/auth_basic.pp
new file mode 100644
index 0000000..8c613ee
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/auth_basic.pp
@@ -0,0 +1,3 @@
+class apache::mod::auth_basic {
+ apache::mod { 'auth_basic': }
+}
diff --git a/puppet/modules/apache/manifests/mod/auth_kerb.pp b/puppet/modules/apache/manifests/mod/auth_kerb.pp
new file mode 100644
index 0000000..76c2de5
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/auth_kerb.pp
@@ -0,0 +1,5 @@
+class apache::mod::auth_kerb {
+ apache::mod { 'auth_kerb': }
+}
+
+
diff --git a/puppet/modules/apache/manifests/mod/autoindex.pp b/puppet/modules/apache/manifests/mod/autoindex.pp
new file mode 100644
index 0000000..85b4278
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/autoindex.pp
@@ -0,0 +1,12 @@
+class apache::mod::autoindex {
+ apache::mod { 'autoindex': }
+ # Template uses no variables
+ file { 'autoindex.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/autoindex.conf",
+ content => template('apache/mod/autoindex.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/cache.pp b/puppet/modules/apache/manifests/mod/cache.pp
new file mode 100644
index 0000000..26d71bd
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/cache.pp
@@ -0,0 +1,3 @@
+class apache::mod::cache {
+ apache::mod { 'cache': }
+}
diff --git a/puppet/modules/apache/manifests/mod/cgi.pp b/puppet/modules/apache/manifests/mod/cgi.pp
new file mode 100644
index 0000000..2ad368a
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/cgi.pp
@@ -0,0 +1,4 @@
+class apache::mod::cgi {
+ Class['apache::mod::prefork'] -> Class['apache::mod::cgi']
+ apache::mod { 'cgi': }
+}
diff --git a/puppet/modules/apache/manifests/mod/cgid.pp b/puppet/modules/apache/manifests/mod/cgid.pp
new file mode 100644
index 0000000..1a0a082
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/cgid.pp
@@ -0,0 +1,22 @@
+class apache::mod::cgid {
+ Class['apache::mod::worker'] -> Class['apache::mod::cgid']
+
+ # Debian specifies it's cgid sock path, but RedHat uses the default value
+ # with no config file
+ $cgisock_path = $::osfamily ? {
+ 'debian' => '${APACHE_RUN_DIR}/cgisock',
+ default => undef,
+ }
+ apache::mod { 'cgid': }
+ if $cgisock_path {
+ # Template uses $cgisock_path
+ file { 'cgid.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/cgid.conf",
+ content => template('apache/mod/cgid.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/dav.pp b/puppet/modules/apache/manifests/mod/dav.pp
new file mode 100644
index 0000000..06aa087
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/dav.pp
@@ -0,0 +1,3 @@
+class apache::mod::dav {
+ apache::mod { 'dav': }
+}
diff --git a/puppet/modules/apache/manifests/mod/dav_fs.pp b/puppet/modules/apache/manifests/mod/dav_fs.pp
new file mode 100644
index 0000000..ab78408
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/dav_fs.pp
@@ -0,0 +1,19 @@
+class apache::mod::dav_fs {
+ $dav_lock = $::osfamily ? {
+ 'debian' => '${APACHE_LOCK_DIR}/DAVLock',
+ default => '/var/lib/dav/lockdb',
+ }
+
+ Class['apache::mod::dav'] -> Class['apache::mod::dav_fs']
+ apache::mod { 'dav_fs': }
+
+ # Template uses: $dav_lock
+ file { 'dav_fs.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/dav_fs.conf",
+ content => template('apache/mod/dav_fs.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/dav_svn.pp b/puppet/modules/apache/manifests/mod/dav_svn.pp
new file mode 100644
index 0000000..76e0d88
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/dav_svn.pp
@@ -0,0 +1,4 @@
+class apache::mod::dav_svn {
+ include apache::mod::dav
+ apache::mod { 'dav_svn': }
+}
diff --git a/puppet/modules/apache/manifests/mod/deflate.pp b/puppet/modules/apache/manifests/mod/deflate.pp
new file mode 100644
index 0000000..97d1fdd
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/deflate.pp
@@ -0,0 +1,12 @@
+class apache::mod::deflate {
+ apache::mod { 'deflate': }
+ # Template uses no variables
+ file { 'deflate.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/deflate.conf",
+ content => template('apache/mod/deflate.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/dev.pp b/puppet/modules/apache/manifests/mod/dev.pp
new file mode 100644
index 0000000..b5d146f
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/dev.pp
@@ -0,0 +1,5 @@
+class apache::mod::dev {
+ # Development packages are not apache modules
+ warning('apache::mod::dev is deprecated; please use apache::dev')
+ include apache::dev
+}
diff --git a/puppet/modules/apache/manifests/mod/dir.pp b/puppet/modules/apache/manifests/mod/dir.pp
new file mode 100644
index 0000000..39543e1
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/dir.pp
@@ -0,0 +1,21 @@
+# Note: this sets the global DirectoryIndex directive, it may be necessary to consider being able to modify the apache::vhost to declare DirectoryIndex statements in a vhost configuration
+# Parameters:
+# - $indexes provides a string for the DirectoryIndex directive http://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex
+class apache::mod::dir (
+ $dir = 'public_html',
+ $indexes = ['index.html','index.html.var','index.cgi','index.pl','index.php','index.xhtml'],
+) {
+ validate_array($indexes)
+ apache::mod { 'dir': }
+
+ # Template uses
+ # - $indexes
+ file { 'dir.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/dir.conf",
+ content => template('apache/mod/dir.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/disk_cache.pp b/puppet/modules/apache/manifests/mod/disk_cache.pp
new file mode 100644
index 0000000..dd3e0f0
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/disk_cache.pp
@@ -0,0 +1,19 @@
+class apache::mod::disk_cache {
+ $cache_root = $::osfamily ? {
+ 'debian' => '/var/cache/apache2/mod_disk_cache',
+ 'redhat' => '/var/cache/mod_proxy',
+ }
+ Class['apache::mod::proxy'] -> Class['apache::mod::disk_cache']
+ Class['apache::mod::cache'] -> Class['apache::mod::disk_cache']
+
+ apache::mod { 'disk_cache': }
+ # Template uses $cache_proxy
+ file { 'disk_cache.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/disk_cache.conf",
+ content => template('apache/mod/disk_cache.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/fcgid.pp b/puppet/modules/apache/manifests/mod/fcgid.pp
new file mode 100644
index 0000000..4c77770
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/fcgid.pp
@@ -0,0 +1,3 @@
+class apache::mod::fcgid {
+ apache::mod { 'fcgid': }
+}
diff --git a/puppet/modules/apache/manifests/mod/headers.pp b/puppet/modules/apache/manifests/mod/headers.pp
new file mode 100644
index 0000000..5ff9887
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/headers.pp
@@ -0,0 +1,3 @@
+class apache::mod::headers {
+ apache::mod { 'headers': }
+}
\ No newline at end of file
diff --git a/puppet/modules/apache/manifests/mod/info.pp b/puppet/modules/apache/manifests/mod/info.pp
new file mode 100644
index 0000000..b76e1ef
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/info.pp
@@ -0,0 +1,14 @@
+class apache::mod::info (
+ $allow_from = ['127.0.0.1','::1'],
+){
+ apache::mod { 'info': }
+ # Template uses $allow_from
+ file { 'info.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/info.conf",
+ content => template('apache/mod/info.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/itk.pp b/puppet/modules/apache/manifests/mod/itk.pp
new file mode 100644
index 0000000..a2f4b5c
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/itk.pp
@@ -0,0 +1,53 @@
+class apache::mod::itk (
+ $startservers = '8',
+ $minspareservers = '5',
+ $maxspareservers = '20',
+ $serverlimit = '256',
+ $maxclients = '256',
+ $maxrequestsperchild = '4000',
+) {
+ if defined(Class['apache::mod::prefork']) {
+ fail('May not include both apache::mod::itk and apache::mod::prefork on the same node')
+ }
+ if defined(Class['apache::mod::worker']) {
+ fail('May not include both apache::mod::itk and apache::mod::worker on the same node')
+ }
+ File {
+ owner => 'root',
+ group => $apache::params::root_group,
+ mode => '0644',
+ }
+
+ # Template uses:
+ # - $startservers
+ # - $minspareservers
+ # - $maxspareservers
+ # - $serverlimit
+ # - $maxclients
+ # - $maxrequestsperchild
+ file { "${apache::mod_dir}/itk.conf":
+ ensure => file,
+ content => template('apache/mod/itk.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+
+ case $::osfamily {
+ 'debian' : {
+ file { "${apache::mod_enable_dir}/itk.conf":
+ ensure => link,
+ target => "${apache::mod_dir}/itk.conf",
+ require => Exec["mkdir ${apache::mod_enable_dir}"],
+ before => File[$apache::mod_enable_dir],
+ notify => Service['httpd'],
+ }
+ package { 'apache2-mpm-itk':
+ ensure => present,
+ }
+ }
+ default: {
+ fail("Unsupported osfamily ${::osfamily}")
+ }
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/ldap.pp b/puppet/modules/apache/manifests/mod/ldap.pp
new file mode 100644
index 0000000..097622c
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/ldap.pp
@@ -0,0 +1,12 @@
+class apache::mod::ldap {
+ apache::mod { 'ldap': }
+ # Template uses no variables
+ file { 'ldap.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/ldap.conf",
+ content => template('apache/mod/ldap.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/mime.pp b/puppet/modules/apache/manifests/mod/mime.pp
new file mode 100644
index 0000000..ba62ebc
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/mime.pp
@@ -0,0 +1,12 @@
+class apache::mod::mime {
+ apache::mod { 'mime': }
+ # Template uses no variables
+ file { 'mime.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/mime.conf",
+ content => template('apache/mod/mime.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/mime_magic.pp b/puppet/modules/apache/manifests/mod/mime_magic.pp
new file mode 100644
index 0000000..c0ff0a7
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/mime_magic.pp
@@ -0,0 +1,12 @@
+class apache::mod::mime_magic {
+ apache::mod { 'mime_magic': }
+ # Template uses no variables
+ file { 'mime_magic.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/mime_magic.conf",
+ content => template('apache/mod/mime_magic.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/mpm_event.pp b/puppet/modules/apache/manifests/mod/mpm_event.pp
new file mode 100644
index 0000000..92e558e
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/mpm_event.pp
@@ -0,0 +1,11 @@
+class apache::mod::mpm_event {
+ # Template uses no variables
+ file { 'mpm_event.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/mpm_event.conf",
+ content => template('apache/mod/mpm_event.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/negotiation.pp b/puppet/modules/apache/manifests/mod/negotiation.pp
new file mode 100644
index 0000000..e10c492
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/negotiation.pp
@@ -0,0 +1,12 @@
+class apache::mod::negotiation {
+ apache::mod { 'negotiation': }
+ # Template uses no variables
+ file { 'negotiation.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/negotiation.conf",
+ content => template('apache/mod/negotiation.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/passenger.pp b/puppet/modules/apache/manifests/mod/passenger.pp
new file mode 100644
index 0000000..a002d13
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/passenger.pp
@@ -0,0 +1,30 @@
+class apache::mod::passenger (
+ $passenger_high_performance = undef,
+ $passenger_pool_idle_time = undef,
+ $passenger_max_requests = undef,
+ $passenger_stat_throttle_rate = undef,
+ $rack_autodetect = undef,
+ $rails_autodetect = undef,
+ $passenger_root = $apache::params::passenger_root,
+ $passenger_ruby = $apache::params::passenger_ruby,
+ $passenger_max_pool_size = undef,
+) {
+ apache::mod { 'passenger': }
+ # Template uses:
+ # - $passenger_root
+ # - $passenger_ruby
+ # - $passenger_max_pool_size
+ # - $passenger_high_performance
+ # - $passenger_max_requests
+ # - $passenger_stat_throttle_rate
+ # - $rack_autodetect
+ # - $rails_autodetect
+ file { 'passenger.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/passenger.conf",
+ content => template('apache/mod/passenger.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/perl.pp b/puppet/modules/apache/manifests/mod/perl.pp
new file mode 100644
index 0000000..65832a0
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/perl.pp
@@ -0,0 +1,3 @@
+class apache::mod::perl {
+ apache::mod { 'perl': }
+}
diff --git a/puppet/modules/apache/manifests/mod/php.pp b/puppet/modules/apache/manifests/mod/php.pp
new file mode 100644
index 0000000..f232753
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/php.pp
@@ -0,0 +1,17 @@
+class apache::mod::php {
+ if ! defined(Class['apache::mod::prefork']) {
+ fail('apache::mod::php requires apache::mod::prefork; please enable mpm_module => \'prefork\' on Class[\'apache\']')
+ }
+ apache::mod { 'php5': }
+ file { 'php5.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/php5.conf",
+ content => template('apache/mod/php5.conf.erb'),
+ require => [
+ Class['apache::mod::prefork'],
+ Exec["mkdir ${apache::mod_dir}"],
+ ],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/prefork.pp b/puppet/modules/apache/manifests/mod/prefork.pp
new file mode 100644
index 0000000..5c6a7de
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/prefork.pp
@@ -0,0 +1,63 @@
+class apache::mod::prefork (
+ $startservers = '8',
+ $minspareservers = '5',
+ $maxspareservers = '20',
+ $serverlimit = '256',
+ $maxclients = '256',
+ $maxrequestsperchild = '4000',
+) {
+ if defined(Class['apache::mod::itk']) {
+ fail('May not include both apache::mod::itk and apache::mod::prefork on the same node')
+ }
+ if defined(Class['apache::mod::worker']) {
+ fail('May not include both apache::mod::worker and apache::mod::prefork on the same node')
+ }
+ File {
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ }
+
+ # Template uses:
+ # - $startservers
+ # - $minspareservers
+ # - $maxspareservers
+ # - $serverlimit
+ # - $maxclients
+ # - $maxrequestsperchild
+ file { "${apache::mod_dir}/prefork.conf":
+ ensure => file,
+ content => template('apache/mod/prefork.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+
+ case $::osfamily {
+ 'redhat': {
+ file_line { '/etc/sysconfig/httpd prefork enable':
+ ensure => present,
+ path => '/etc/sysconfig/httpd',
+ line => '#HTTPD=/usr/sbin/httpd.worker',
+ match => '#?HTTPD=/usr/sbin/httpd.worker',
+ require => Package['httpd'],
+ notify => Service['httpd'],
+ }
+ }
+ 'debian': {
+ file { "${apache::mod_enable_dir}/prefork.conf":
+ ensure => link,
+ target => "${apache::mod_dir}/prefork.conf",
+ require => Exec["mkdir ${apache::mod_enable_dir}"],
+ before => File[$apache::mod_enable_dir],
+ notify => Service['httpd'],
+ }
+ package { 'apache2-mpm-prefork':
+ ensure => present,
+ }
+ }
+ default: {
+ fail("Unsupported osfamily ${::osfamily}")
+ }
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/proxy.pp b/puppet/modules/apache/manifests/mod/proxy.pp
new file mode 100644
index 0000000..71b766b
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/proxy.pp
@@ -0,0 +1,15 @@
+class apache::mod::proxy (
+ $proxy_requests = 'Off',
+ $allow_from = ['127.0.0.1','::1'],
+) {
+ apache::mod { 'proxy': }
+ # Template uses $proxy_requests
+ file { 'proxy.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/proxy.conf",
+ content => template('apache/mod/proxy.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/proxy_balancer.pp b/puppet/modules/apache/manifests/mod/proxy_balancer.pp
new file mode 100644
index 0000000..51d8e03
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/proxy_balancer.pp
@@ -0,0 +1,5 @@
+class apache::mod::proxy_balancer {
+ Class['apache::mod::proxy'] -> Class['apache::mod::proxy_balancer']
+ Class['apache::mod::proxy_http'] -> Class['apache::mod::proxy_balancer']
+ apache::mod { 'proxy_balancer': }
+}
diff --git a/puppet/modules/apache/manifests/mod/proxy_html.pp b/puppet/modules/apache/manifests/mod/proxy_html.pp
new file mode 100644
index 0000000..ab25757
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/proxy_html.pp
@@ -0,0 +1,25 @@
+class apache::mod::proxy_html {
+ Class['apache::mod::proxy'] -> Class['apache::mod::proxy_html']
+ Class['apache::mod::proxy_http'] -> Class['apache::mod::proxy_html']
+ apache::mod { 'proxy_html': }
+ case $::osfamily {
+ 'RedHat': {
+ apache::mod { 'xml2enc': }
+ }
+ 'Debian': {
+ $proxy_html_loadfiles = $apache::params::distrelease ? {
+ '6' => '/usr/lib/libxml2.so.2',
+ default => "/usr/lib/${::hardwaremodel}-linux-gnu/libxml2.so.2",
+ }
+ }
+ }
+ # Template uses $icons_path
+ file { 'proxy_html.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/proxy_html.conf",
+ content => template('apache/mod/proxy_html.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/proxy_http.pp b/puppet/modules/apache/manifests/mod/proxy_http.pp
new file mode 100644
index 0000000..5b83df2
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/proxy_http.pp
@@ -0,0 +1,4 @@
+class apache::mod::proxy_http {
+ Class['apache::mod::proxy'] -> Class['apache::mod::proxy_http']
+ apache::mod { 'proxy_http': }
+}
diff --git a/puppet/modules/apache/manifests/mod/python.pp b/puppet/modules/apache/manifests/mod/python.pp
new file mode 100644
index 0000000..8158b7e
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/python.pp
@@ -0,0 +1,5 @@
+class apache::mod::python {
+ apache::mod { 'python': }
+}
+
+
diff --git a/puppet/modules/apache/manifests/mod/reqtimeout.pp b/puppet/modules/apache/manifests/mod/reqtimeout.pp
new file mode 100644
index 0000000..b763b37
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/reqtimeout.pp
@@ -0,0 +1,12 @@
+class apache::mod::reqtimeout {
+ apache::mod { 'reqtimeout': }
+ # Template uses no variables
+ file { 'reqtimeout.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/reqtimeout.conf",
+ content => template('apache/mod/reqtimeout.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/rewrite.pp b/puppet/modules/apache/manifests/mod/rewrite.pp
new file mode 100644
index 0000000..147faab
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/rewrite.pp
@@ -0,0 +1,4 @@
+class apache::mod::rewrite {
+ include apache::params
+ apache::mod { 'rewrite': }
+}
diff --git a/puppet/modules/apache/manifests/mod/setenvif.pp b/puppet/modules/apache/manifests/mod/setenvif.pp
new file mode 100644
index 0000000..1b60edd
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/setenvif.pp
@@ -0,0 +1,12 @@
+class apache::mod::setenvif {
+ apache::mod { 'setenvif': }
+ # Template uses no variables
+ file { 'setenvif.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/setenvif.conf",
+ content => template('apache/mod/setenvif.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/ssl.pp b/puppet/modules/apache/manifests/mod/ssl.pp
new file mode 100644
index 0000000..ba183e1
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/ssl.pp
@@ -0,0 +1,23 @@
+class apache::mod::ssl (
+ $ssl_compression = false,
+) {
+ $session_cache = $::osfamily ? {
+ 'debian' => '${APACHE_RUN_DIR}/ssl_scache(512000)',
+ 'redhat' => '/var/cache/mod_ssl/scache(512000)',
+ }
+ $ssl_mutex = $::osfamily ? {
+ 'debian' => 'file:${APACHE_RUN_DIR}/ssl_mutex',
+ 'redhat' => 'default',
+ }
+ apache::mod { 'ssl': }
+
+ # Template uses $ssl_compression, $session_cache, $ssl_mutex
+ file { 'ssl.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/ssl.conf",
+ content => template('apache/mod/ssl.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/status.pp b/puppet/modules/apache/manifests/mod/status.pp
new file mode 100644
index 0000000..084d84e
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/status.pp
@@ -0,0 +1,12 @@
+class apache::mod::status {
+ apache::mod { 'status': }
+ # Template uses no variables
+ file { 'status.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/status.conf",
+ content => template('apache/mod/status.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/suphp.pp b/puppet/modules/apache/manifests/mod/suphp.pp
new file mode 100644
index 0000000..26473cf
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/suphp.pp
@@ -0,0 +1,14 @@
+class apache::mod::suphp (
+){
+ apache::mod { 'suphp': }
+
+ file {'suphp.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/suphp.conf",
+ content => template('apache/mod/suphp.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd']
+ }
+}
+
diff --git a/puppet/modules/apache/manifests/mod/userdir.pp b/puppet/modules/apache/manifests/mod/userdir.pp
new file mode 100644
index 0000000..69f4044
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/userdir.pp
@@ -0,0 +1,17 @@
+class apache::mod::userdir (
+ $home = '/home',
+ $dir = 'public_html',
+ $disable_root = true,
+) {
+ apache::mod { 'userdir': }
+
+ # Template uses $home, $dir, $disable_root
+ file { 'userdir.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/userdir.conf",
+ content => template('apache/mod/userdir.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/vhost_alias.pp b/puppet/modules/apache/manifests/mod/vhost_alias.pp
new file mode 100644
index 0000000..ec40447
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/vhost_alias.pp
@@ -0,0 +1,3 @@
+class apache::mod::vhost_alias {
+ apache::mod { 'vhost_alias': }
+}
diff --git a/puppet/modules/apache/manifests/mod/worker.pp b/puppet/modules/apache/manifests/mod/worker.pp
new file mode 100644
index 0000000..3966ed2
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/worker.pp
@@ -0,0 +1,64 @@
+class apache::mod::worker (
+ $startservers = '2',
+ $maxclients = '150',
+ $minsparethreads = '25',
+ $maxsparethreads = '75',
+ $threadsperchild = '25',
+ $maxrequestsperchild = '0',
+ $serverlimit = '25',
+) {
+ if defined(Class['apache::mod::itk']) {
+ fail('May not include both apache::mod::worker and apache::mod::itk on the same node')
+ }
+ if defined(Class['apache::mod::prefork']) {
+ fail('May not include both apache::mod::worker and apache::mod::prefork on the same node')
+ }
+ File {
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ }
+
+ # Template uses:
+ # - $startservers
+ # - $maxclients
+ # - $minsparethreads
+ # - $maxsparethreads
+ # - $threadsperchild
+ # - $maxrequestsperchild
+ # - $serverlimit
+ file { "${apache::mod_dir}/worker.conf":
+ ensure => file,
+ content => template('apache/mod/worker.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd'],
+ }
+
+ case $::osfamily {
+ 'redhat': {
+ file_line { '/etc/sysconfig/httpd worker enable':
+ ensure => present,
+ path => '/etc/sysconfig/httpd',
+ line => 'HTTPD=/usr/sbin/httpd.worker',
+ match => '#?HTTPD=/usr/sbin/httpd.worker',
+ notify => Service['httpd'],
+ }
+ }
+ 'debian': {
+ file { "${apache::mod_enable_dir}/worker.conf":
+ ensure => link,
+ target => "${apache::mod_dir}/worker.conf",
+ require => Exec["mkdir ${apache::mod_enable_dir}"],
+ before => File[$apache::mod_enable_dir],
+ notify => Service['httpd'],
+ }
+ package { 'apache2-mpm-worker':
+ ensure => present,
+ }
+ }
+ default: {
+ fail("Unsupported osfamily ${::osfamily}")
+ }
+ }
+}
diff --git a/puppet/modules/apache/manifests/mod/wsgi.pp b/puppet/modules/apache/manifests/mod/wsgi.pp
new file mode 100644
index 0000000..ff12fbf
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/wsgi.pp
@@ -0,0 +1,19 @@
+class apache::mod::wsgi (
+ $wsgi_socket_prefix = undef,
+ $wsgi_python_home = undef,
+){
+ apache::mod { 'wsgi': }
+
+ # Template uses:
+ # - $wsgi_socket_prefix
+ # - $wsgi_python_home
+ file {'wsgi.conf':
+ ensure => file,
+ path => "${apache::mod_dir}/wsgi.conf",
+ content => template('apache/mod/wsgi.conf.erb'),
+ require => Exec["mkdir ${apache::mod_dir}"],
+ before => File[$apache::mod_dir],
+ notify => Service['httpd']
+ }
+}
+
diff --git a/puppet/modules/apache/manifests/mod/xsendfile.pp b/puppet/modules/apache/manifests/mod/xsendfile.pp
new file mode 100644
index 0000000..571501a
--- /dev/null
+++ b/puppet/modules/apache/manifests/mod/xsendfile.pp
@@ -0,0 +1,4 @@
+class apache::mod::xsendfile {
+ include apache::params
+ apache::mod { 'xsendfile': }
+}
diff --git a/puppet/modules/apache/manifests/namevirtualhost.pp b/puppet/modules/apache/manifests/namevirtualhost.pp
new file mode 100644
index 0000000..edbbfe4
--- /dev/null
+++ b/puppet/modules/apache/manifests/namevirtualhost.pp
@@ -0,0 +1,10 @@
+define apache::namevirtualhost {
+ $addr_port = $name
+ include apache::params
+
+ # Template uses: $addr_port
+ concat::fragment { "NameVirtualHost ${addr_port}":
+ target => $apache::params::ports_file,
+ content => template('apache/namevirtualhost.erb'),
+ }
+}
diff --git a/puppet/modules/apache/manifests/params.pp b/puppet/modules/apache/manifests/params.pp
new file mode 100644
index 0000000..7bf4a5f
--- /dev/null
+++ b/puppet/modules/apache/manifests/params.pp
@@ -0,0 +1,132 @@
+# Class: apache::params
+#
+# This class manages Apache parameters
+#
+# Parameters:
+# - The $user that Apache runs as
+# - The $group that Apache runs as
+# - The $apache_name is the name of the package and service on the relevant
+# distribution
+# - The $php_package is the name of the package that provided PHP
+# - The $ssl_package is the name of the Apache SSL package
+# - The $apache_dev is the name of the Apache development libraries package
+# - The $conf_contents is the contents of the Apache configuration file
+#
+# Actions:
+#
+# Requires:
+#
+# Sample Usage:
+#
+class apache::params {
+ # This will be 5 or 6 on RedHat, 6 or wheezy on Debian, 12 or quantal on Ubuntu, 3 on Amazon, etc.
+ $osr_array = split($::operatingsystemrelease,'[\/\.]')
+ $distrelease = $osr_array[0]
+ if ! $distrelease {
+ fail("Class['apache::params']: Unparsable \$::operatingsystemrelease: ${::operatingsystemrelease}")
+ }
+
+ if($::fqdn) {
+ $servername = $::fqdn
+ } else {
+ $servername = $::hostname
+ }
+
+ if $::osfamily == 'RedHat' or $::operatingsystem == 'amazon' {
+ $user = 'apache'
+ $group = 'apache'
+ $apache_name = 'httpd'
+ $httpd_dir = '/etc/httpd'
+ $conf_dir = "${httpd_dir}/conf"
+ $confd_dir = "${httpd_dir}/conf.d"
+ $mod_dir = "${httpd_dir}/conf.d"
+ $vhost_dir = "${httpd_dir}/conf.d"
+ $conf_file = 'httpd.conf'
+ $ports_file = "${conf_dir}/ports.conf"
+ $logroot = '/var/log/httpd'
+ $lib_path = 'modules'
+ $mpm_module = 'prefork'
+ $dev_packages = 'httpd-devel'
+ $default_ssl_cert = '/etc/pki/tls/certs/localhost.crt'
+ $default_ssl_key = '/etc/pki/tls/private/localhost.key'
+ $ssl_certs_dir = $distrelease ? {
+ '5' => '/etc/pki/tls/certs',
+ default => '/etc/ssl/certs',
+ }
+ $passenger_root = '/usr/share/rubygems/gems/passenger-3.0.17'
+ $passenger_ruby = '/usr/bin/ruby'
+ $suphp_addhandler = 'php5-script'
+ $suphp_engine = 'off'
+ $suphp_configpath = undef
+ $mod_packages = {
+ 'auth_kerb' => 'mod_auth_kerb',
+ 'fcgid' => 'mod_fcgid',
+ 'passenger' => 'mod_passenger',
+ 'perl' => 'mod_perl',
+ 'php5' => $distrelease ? {
+ '5' => 'php53',
+ default => 'php',
+ },
+ 'proxy_html' => 'mod_proxy_html',
+ 'python' => 'mod_python',
+ 'shibboleth' => 'shibboleth',
+ 'ssl' => 'mod_ssl',
+ 'wsgi' => 'mod_wsgi',
+ 'dav_svn' => 'mod_dav_svn',
+ 'suphp' => 'mod_suphp',
+ 'xsendfile' => 'mod_xsendfile',
+ }
+ $mod_libs = {
+ 'php5' => 'libphp5.so',
+ }
+ $conf_template = 'apache/httpd.conf.erb'
+ $keepalive = 'Off'
+ $keepalive_timeout = 15
+ } elsif $::osfamily == 'Debian' {
+ $user = 'www-data'
+ $group = 'www-data'
+ $apache_name = 'apache2'
+ $httpd_dir = '/etc/apache2'
+ $conf_dir = $httpd_dir
+ $confd_dir = "${httpd_dir}/conf.d"
+ $mod_dir = "${httpd_dir}/mods-available"
+ $mod_enable_dir = "${httpd_dir}/mods-enabled"
+ $vhost_dir = "${httpd_dir}/sites-available"
+ $vhost_enable_dir = "${httpd_dir}/sites-enabled"
+ $conf_file = 'apache2.conf'
+ $ports_file = "${conf_dir}/ports.conf"
+ $logroot = '/var/log/apache2'
+ $lib_path = '/usr/lib/apache2/modules'
+ $mpm_module = 'worker'
+ $dev_packages = ['libaprutil1-dev', 'libapr1-dev', 'apache2-prefork-dev']
+ $default_ssl_cert = '/etc/ssl/certs/ssl-cert-snakeoil.pem'
+ $default_ssl_key = '/etc/ssl/private/ssl-cert-snakeoil.key'
+ $ssl_certs_dir = '/etc/ssl/certs'
+ $passenger_root = '/usr'
+ $passenger_ruby = '/usr/bin/ruby'
+ $suphp_addhandler = 'x-httpd-php'
+ $suphp_engine = 'off'
+ $suphp_configpath = '/etc/php5/apache2'
+ $mod_packages = {
+ 'auth_kerb' => 'libapache2-mod-auth-kerb',
+ 'fcgid' => 'libapache2-mod-fcgid',
+ 'passenger' => 'libapache2-mod-passenger',
+ 'perl' => 'libapache2-mod-perl2',
+ 'php5' => 'libapache2-mod-php5',
+ 'proxy_html' => 'libapache2-mod-proxy-html',
+ 'python' => 'libapache2-mod-python',
+ 'wsgi' => 'libapache2-mod-wsgi',
+ 'dav_svn' => 'libapache2-svn',
+ 'suphp' => 'libapache2-mod-suphp',
+ 'xsendfile' => 'libapache2-mod-xsendfile',
+ }
+ $mod_libs = {
+ 'php5' => 'libphp5.so',
+ }
+ $conf_template = 'apache/httpd.conf.erb'
+ $keepalive = 'Off'
+ $keepalive_timeout = 15
+ } else {
+ fail("Class['apache::params']: Unsupported osfamily: ${::osfamily}")
+ }
+}
diff --git a/puppet/modules/apache/manifests/php.pp b/puppet/modules/apache/manifests/php.pp
new file mode 100644
index 0000000..feb903e
--- /dev/null
+++ b/puppet/modules/apache/manifests/php.pp
@@ -0,0 +1,18 @@
+# Class: apache::php
+#
+# This class installs PHP for Apache
+#
+# Parameters:
+# - $php_package
+#
+# Actions:
+# - Install Apache PHP package
+#
+# Requires:
+#
+# Sample Usage:
+#
+class apache::php {
+ warning('apache::php is deprecated; please use apache::mod::php')
+ include apache::mod::php
+}
diff --git a/puppet/modules/apache/manifests/proxy.pp b/puppet/modules/apache/manifests/proxy.pp
new file mode 100644
index 0000000..0f4fde5
--- /dev/null
+++ b/puppet/modules/apache/manifests/proxy.pp
@@ -0,0 +1,15 @@
+# Class: apache::proxy
+#
+# This class enabled the proxy module for Apache
+#
+# Actions:
+# - Enables Apache Proxy module
+#
+# Requires:
+#
+# Sample Usage:
+#
+class apache::proxy {
+ warning('apache::proxy is deprecated; please use apache::mod::proxy')
+ include apache::mod::proxy
+}
diff --git a/puppet/modules/apache/manifests/python.pp b/puppet/modules/apache/manifests/python.pp
new file mode 100644
index 0000000..99ef289
--- /dev/null
+++ b/puppet/modules/apache/manifests/python.pp
@@ -0,0 +1,18 @@
+# Class: apache::python
+#
+# This class installs Python for Apache
+#
+# Parameters:
+# - $php_package
+#
+# Actions:
+# - Install Apache Python package
+#
+# Requires:
+#
+# Sample Usage:
+#
+class apache::python {
+ warning('apache::python is deprecated; please use apache::mod::python')
+ include apache::mod::python
+}
diff --git a/puppet/modules/apache/manifests/service.pp b/puppet/modules/apache/manifests/service.pp
new file mode 100644
index 0000000..e93b4a2
--- /dev/null
+++ b/puppet/modules/apache/manifests/service.pp
@@ -0,0 +1,29 @@
+# Class: apache::service
+#
+# Manages the Apache daemon
+#
+# Parameters:
+#
+# Actions:
+# - Manage Apache service
+#
+# Requires:
+#
+# Sample Usage:
+#
+# sometype { 'foo':
+# notify => Class['apache::service],
+# }
+#
+#
+class apache::service (
+ $service_enable = true,
+) {
+ validate_bool($service_enable)
+
+ service { 'httpd':
+ ensure => $service_enable,
+ name => $apache::apache_name,
+ enable => $service_enable,
+ }
+}
diff --git a/puppet/modules/apache/manifests/ssl.pp b/puppet/modules/apache/manifests/ssl.pp
new file mode 100644
index 0000000..21662e1
--- /dev/null
+++ b/puppet/modules/apache/manifests/ssl.pp
@@ -0,0 +1,18 @@
+# Class: apache::ssl
+#
+# This class installs Apache SSL capabilities
+#
+# Parameters:
+# - The $ssl_package name from the apache::params class
+#
+# Actions:
+# - Install Apache SSL capabilities
+#
+# Requires:
+#
+# Sample Usage:
+#
+class apache::ssl {
+ warning('apache::ssl is deprecated; please use apache::mod::ssl')
+ include apache::mod::ssl
+}
diff --git a/puppet/modules/apache/manifests/vhost.pp b/puppet/modules/apache/manifests/vhost.pp
new file mode 100644
index 0000000..1f6fb1f
--- /dev/null
+++ b/puppet/modules/apache/manifests/vhost.pp
@@ -0,0 +1,413 @@
+# Definition: apache::vhost
+#
+# This class installs Apache Virtual Hosts
+#
+# Parameters:
+# - The $port to configure the host on
+# - The $docroot provides the DocumentRoot variable
+# - The $virtual_docroot provides VirtualDocumentationRoot variable
+# - The $serveradmin will specify an email address for Apache that it will
+# display when it renders one of it's error pages
+# - The $ssl option is set true or false to enable SSL for this Virtual Host
+# - The $priority of the site
+# - The $servername is the primary name of the virtual host
+# - The $serveraliases of the site
+# - The $options for the given vhost
+# - The $override for the given vhost (list of AllowOverride arguments)
+# - The $vhost_name for name based virtualhosting, defaulting to *
+# - The $logroot specifies the location of the virtual hosts logfiles, default
+# to /var/log/<apache log location>/
+# - The $access_log specifies if *_access.log directives should be configured.
+# - The $ensure specifies if vhost file is present or absent.
+# - The $request_headers is a list of RequestHeader statement strings as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader
+# - $aliases is a list of Alias hashes for mod_alias as per http://httpd.apache.org/docs/current/mod/mod_alias.html
+# each statement is a hash in the form of { alias => '/alias', path => '/real/path/to/directory' }
+# - $directories is a lost of hashes for creating <Directory> statements as per http://httpd.apache.org/docs/2.2/mod/core.html#directory
+# each statement is a hash in the form of { path => '/path/to/directory', <directive> => <value>}
+# see README.md for list of supported directives.
+#
+# Actions:
+# - Install Apache Virtual Hosts
+#
+# Requires:
+# - The apache class
+#
+# Sample Usage:
+#
+# # Simple vhost definition:
+# apache::vhost { 'site.name.fqdn':
+# port => '80',
+# docroot => '/path/to/docroot',
+# }
+#
+# # SSL vhost with non-SSL rewrite:
+# apache::vhost { 'site.name.fqdn':
+# port => '443',
+# ssl => true,
+# docroot => '/path/to/docroot',
+# }
+# apache::vhost { 'site.name.fqdn':
+# port => '80',
+# rewrite_cond => '%{HTTPS} off',
+# rewrite_rule => '(.*) https://%{HTTPS_HOST}%{REQUEST_URI}',
+# }
+# apache::vhost { 'site.name.fqdn':
+# port => '80',
+# docroot => '/path/to/other_docroot',
+# custom_fragment => template("${module_name}/my_fragment.erb"),
+# }
+#
+define apache::vhost(
+ $docroot,
+ $virtual_docroot = false,
+ $port = undef,
+ $ip = undef,
+ $ip_based = false,
+ $add_listen = true,
+ $docroot_owner = 'root',
+ $docroot_group = 'root',
+ $serveradmin = false,
+ $ssl = false,
+ $ssl_cert = $apache::default_ssl_cert,
+ $ssl_key = $apache::default_ssl_key,
+ $ssl_chain = $apache::default_ssl_chain,
+ $ssl_ca = $apache::default_ssl_ca,
+ $ssl_crl_path = $apache::default_ssl_crl_path,
+ $ssl_crl = $apache::default_ssl_crl,
+ $ssl_certs_dir = $apache::params::ssl_certs_dir,
+ $priority = undef,
+ $default_vhost = false,
+ $servername = $name,
+ $serveraliases = [],
+ $options = ['Indexes','FollowSymLinks','MultiViews'],
+ $override = ['None'],
+ $vhost_name = '*',
+ $logroot = $apache::logroot,
+ $access_log = true,
+ $access_log_file = undef,
+ $access_log_pipe = undef,
+ $access_log_syslog = undef,
+ $access_log_format = undef,
+ $aliases = undef,
+ $directories = undef,
+ $error_log = true,
+ $error_log_file = undef,
+ $error_log_pipe = undef,
+ $error_log_syslog = undef,
+ $scriptalias = undef,
+ $proxy_dest = undef,
+ $proxy_pass = undef,
+ $sslproxyengine = false,
+ $suphp_addhandler = $apache::params::suphp_addhandler,
+ $suphp_engine = $apache::params::suphp_engine,
+ $suphp_configpath = $apache::params::suphp_configpath,
+ $no_proxy_uris = [],
+ $redirect_source = '/',
+ $redirect_dest = undef,
+ $redirect_status = undef,
+ $rack_base_uris = undef,
+ $request_headers = undef,
+ $rewrite_rule = undef,
+ $rewrite_cond = undef,
+ $setenv = [],
+ $setenvif = [],
+ $block = [],
+ $ensure = 'present',
+ $wsgi_daemon_process = undef,
+ $wsgi_daemon_process_options = undef,
+ $wsgi_process_group = undef,
+ $wsgi_script_aliases = undef,
+ $custom_fragment = undef,
+ $itk = undef
+ ) {
+ # The base class must be included first because it is used by parameter defaults
+ if ! defined(Class['apache']) {
+ fail('You must include the apache base class before using any apache defined resources')
+ }
+ $apache_name = $apache::params::apache_name
+
+ validate_re($ensure, '^(present|absent)$',
+ "${ensure} is not supported for ensure.
+ Allowed values are 'present' and 'absent'.")
+ validate_re($suphp_engine, '^(on|off)$',
+ "${suphp_engine} is not supported for suphp_engine.
+ Allowed values are 'on' and 'off'.")
+ validate_bool($ip_based)
+ validate_bool($access_log)
+ validate_bool($error_log)
+ validate_bool($ssl)
+ validate_bool($default_vhost)
+ validate_bool($sslproxyengine)
+ if $wsgi_script_aliases {
+ validate_hash($wsgi_script_aliases)
+ }
+ if $wsgi_daemon_process_options {
+ validate_hash($wsgi_daemon_process_options)
+ }
+ if $itk {
+ validate_hash($itk)
+ }
+
+ if $access_log_file and $access_log_pipe {
+ fail("Apache::Vhost[${name}]: 'access_log_file' and 'access_log_pipe' cannot be defined at the same time")
+ }
+
+ if $error_log_file and $error_log_pipe {
+ fail("Apache::Vhost[${name}]: 'error_log_file' and 'error_log_pipe' cannot be defined at the same time")
+ }
+
+ if $ssl {
+ include apache::mod::ssl
+ }
+
+ if $virtual_docroot {
+ include apache::mod::vhost_alias
+ }
+
+ # This ensures that the docroot exists
+ # But enables it to be specified across multiple vhost resources
+ if ! defined(File[$docroot]) {
+ file { $docroot:
+ ensure => directory,
+ owner => $docroot_owner,
+ group => $docroot_group,
+ require => Package['httpd'],
+ }
+ }
+
+ # Same as above, but for logroot
+ if ! defined(File[$logroot]) {
+ file { $logroot:
+ ensure => directory,
+ require => Package['httpd'],
+ }
+ }
+
+
+ # Is apache::mod::passenger enabled (or apache::mod['passenger'])
+ $passenger_enabled = defined(Apache::Mod['passenger'])
+
+ # Define log file names
+ if $access_log_file {
+ $access_log_destination = "${logroot}/${access_log_file}"
+ } elsif $access_log_pipe {
+ $access_log_destination = "\"${access_log_pipe}\""
+ } elsif $access_log_syslog {
+ $access_log_destination = "${access_log_syslog}"
+ } else {
+ if $ssl {
+ $access_log_destination = "${logroot}/${servername}_access_ssl.log"
+ } else {
+ $access_log_destination = "${logroot}/${servername}_access.log"
+ }
+ }
+
+ if $error_log_file {
+ $error_log_destination = "${logroot}/${error_log_file}"
+ } elsif $error_log_pipe {
+ $error_log_destination = "\"${error_log_pipe}\""
+ } elsif $error_log_syslog {
+ $error_log_destination = "${error_log_syslog}"
+ } else {
+ if $ssl {
+ $error_log_destination = "${logroot}/${servername}_error_ssl.log"
+ } else {
+ $error_log_destination = "${logroot}/${servername}_error.log"
+ }
+ }
+
+ # Set access log format
+ if $access_log_format {
+ $_access_log_format = "\"${access_log_format}\""
+ } else {
+ $_access_log_format = 'combined'
+ }
+
+
+ if $ip {
+ if $port {
+ $listen_addr_port = "${ip}:${port}"
+ $nvh_addr_port = "${ip}:${port}"
+ } else {
+ $nvh_addr_port = $ip
+ if ! $servername and ! $ip_based {
+ fail("Apache::Vhost[${name}]: must pass 'ip' and/or 'port' parameters for name-based vhosts")
+ }
+ }
+ } else {
+ if $port {
+ $listen_addr_port = $port
+ $nvh_addr_port = "${vhost_name}:${port}"
+ } else {
+ $nvh_addr_port = $name
+ if ! $servername {
+ fail("Apache::Vhost[${name}]: must pass 'ip' and/or 'port' parameters, and/or 'servername' parameter")
+ }
+ }
+ }
+ if $add_listen {
+ if $ip and defined(Apache::Listen[$port]) {
+ fail("Apache::Vhost[${name}]: Mixing IP and non-IP Listen directives is not possible; check the add_listen parameter of the apache::vhost define to disable this")
+ }
+ if ! defined(Apache::Listen[$listen_addr_port]) and $listen_addr_port {
+ apache::listen { $listen_addr_port: }
+ }
+ }
+ if ! $ip_based {
+ if ! defined(Apache::Namevirtualhost[$nvh_addr_port]) {
+ apache::namevirtualhost { $nvh_addr_port: }
+ }
+ }
+
+ # Load mod_rewrite if needed and not yet loaded
+ if $rewrite_rule {
+ if ! defined(Apache::Mod['rewrite']) {
+ apache::mod { 'rewrite': }
+ }
+ }
+
+ # Load mod_alias if needed and not yet loaded
+ if $scriptalias or ($redirect_source and $redirect_dest) {
+ if ! defined(Class['apache::mod::alias']) {
+ include apache::mod::alias
+ }
+ }
+
+ # Load mod_proxy if needed and not yet loaded
+ if ($proxy_dest or $proxy_pass) {
+ if ! defined(Class['apache::mod::proxy']) {
+ include apache::mod::proxy
+ }
+ }
+
+ # Load mod_passenger if needed and not yet loaded
+ if $rack_base_uris {
+ if ! defined(Class['apache::mod::passenger']) {
+ include apache::mod::passenger
+ }
+ }
+
+ # Configure the defaultness of a vhost
+ if $priority {
+ $priority_real = $priority
+ } elsif $default_vhost {
+ $priority_real = '10'
+ } else {
+ $priority_real = '25'
+ }
+
+ # Check if mod_headers is required to process $request_headers
+ if $request_headers {
+ if ! defined(Class['apache::mod::headers']) {
+ include apache::mod::headers
+ }
+ }
+
+ ## Apache include does not always work with spaces in the filename
+ $filename = regsubst($name, ' ', '_', 'G')
+
+ ## Create a default directory list if none defined
+ if $directories {
+ $_directories = $directories
+ } else {
+ $_directories = [ {
+ provider => 'directory',
+ path => $docroot,
+ options => $options,
+ allow_override => $override,
+ order => 'allow,deny',
+ allow => 'from all',
+ } ]
+ }
+
+ # Template uses:
+ # - $nvh_addr_port
+ # - $servername
+ # - $serveradmin
+ # - $docroot
+ # - $virtual_docroot
+ # - $options
+ # - $override
+ # - $logroot
+ # - $name
+ # - $aliases
+ # - $_directories
+ # - $access_log
+ # - $access_log_destination
+ # - $_access_log_format
+ # - $error_log
+ # - $error_log_destination
+ # - $custom_fragment
+ # block fragment:
+ # - $block
+ # directories fragment:
+ # - $passenger_enabled
+ # - $directories (a list of key-value hashes is expected)
+ # proxy fragment:
+ # - $proxy_dest
+ # - $no_proxy_uris
+ # rack fragment:
+ # - $rack_base_uris
+ # redirect fragment:
+ # - $redirect_source
+ # - $redirect_dest
+ # - $redirect_status
+ # requestheader fragment:
+ # - $request_headers
+ # rewrite fragment:
+ # - $rewrite_rule
+ # - $rewrite_cond
+ # scriptalias fragment:
+ # - $scriptalias
+ # - $ssl
+ # serveralias fragment:
+ # - $serveraliases
+ # setenv fragment:
+ # - $setenv
+ # - $setenvif
+ # ssl fragment:
+ # - $ssl
+ # - $ssl_cert
+ # - $ssl_key
+ # - $ssl_chain
+ # - $ssl_certs_dir
+ # - $ssl_ca
+ # - $ssl_crl
+ # - $ssl_crl_path
+ # suphp fragment:
+ # - $suphp_addhandler
+ # - $suphp_engine
+ # - $suphp_configpath
+ # wsgi fragment:
+ # - $wsgi_daemon_process
+ # - $wsgi_process_group
+ # - $wsgi_script_aliases
+ file { "${priority_real}-${filename}.conf":
+ ensure => $ensure,
+ path => "${apache::vhost_dir}/${priority_real}-${filename}.conf",
+ content => template('apache/vhost.conf.erb'),
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ require => [
+ Package['httpd'],
+ File[$docroot],
+ File[$logroot],
+ ],
+ notify => Service['httpd'],
+ }
+ if $::osfamily == 'Debian' {
+ $vhost_enable_dir = $apache::vhost_enable_dir
+ file{ "${priority_real}-${filename}.conf symlink":
+ ensure => link,
+ path => "${vhost_enable_dir}/${priority_real}-${filename}.conf",
+ target => "${apache::vhost_dir}/${priority_real}-${filename}.conf",
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ require => File["${priority_real}-${filename}.conf"],
+ notify => Service['httpd'],
+ }
+ }
+}
+
diff --git a/puppet/modules/apache/metadata.json b/puppet/modules/apache/metadata.json
new file mode 100644
index 0000000..ce4c2be
--- /dev/null
+++ b/puppet/modules/apache/metadata.json
@@ -0,0 +1,234 @@
+{
+ "name": "puppetlabs-apache",
+ "version": "0.9.0",
+ "summary": "Puppet module for Apache",
+ "author": "puppetlabs",
+ "description": "Module for Apache configuration",
+ "dependencies": [
+ {
+ "name": "puppetlabs/stdlib",
+ "version_requirement": "\u003e\u003d 2.4.0"
+ },
+ {
+ "name": "puppetlabs/concat",
+ "version_requirement": "\u003e\u003d 1.0.0"
+ }
+ ],
+ "types": [
+ {
+ "parameters": [
+ {
+ "name": "name",
+ "doc": "The name of the module to be managed"
+ },
+ {
+ "name": "lib",
+ "doc": "The name of the .so library to be loaded"
+ },
+ {
+ "name": "identifier",
+ "doc": "Module identifier string used by LoadModule. Default: module-name_module"
+ }
+ ],
+ "providers": [
+ {
+ "name": "gentoo",
+ "doc": "Manage Apache 2 modules on Gentoo"
+ },
+ {
+ "name": "modfix",
+ "doc": "Dummy provider for A2mod.\n\n Fake nil resources when there is no crontab binary available. Allows\n puppetd to run on a bootstrapped machine before a Cron package has been\n installed. Workaround for: http://projects.puppetlabs.com/issues/2384\n "
+ },
+ {
+ "name": "redhat",
+ "doc": "Manage Apache 2 modules on RedHat family OSs"
+ },
+ {
+ "name": "a2mod",
+ "doc": "Manage Apache 2 modules on Debian and Ubuntu"
+ }
+ ],
+ "name": "a2mod",
+ "doc": "Manage Apache 2 modules"
+ }
+ ],
+ "checksums": {
+ ".bundle/config": "b898efea5e8783d6593fcdabec67e925",
+ ".fixtures.yml": "b67781fff881cf708d92df4851cf0e70",
+ ".nodeset.yml": "f2b857f9fc7a701ff118e28591c12925",
+ ".travis.yml": "d0bd592680200f18b2ef4088c2569701",
+ "CHANGELOG.md": "483202a1f4f08294d798c0685c518108",
+ "Gemfile": "c1cd7b0477f1a99e0156a471aac6cd58",
+ "Gemfile.lock": "74613ef355389b668fc4b51a0f9eac39",
+ "LICENSE": "b3f8a01d8699078d82e8c3c992307517",
+ "Modulefile": "fef4b236b7d7885250ca64dbe6074e0a",
+ "README.md": "d3cb59220928734b6d41a6f3a0302c64",
+ "README.passenger.md": "9007ae9e57138bed0c01ae58607ec2aa",
+ "Rakefile": "0428ea3759a4692c91604396c406a9c1",
+ "files/httpd": "295f5e924afe6f752d29327e73fe6d0a",
+ "lib/puppet/provider/a2mod.rb": "03ed73d680787dd126ea37a03be0b236",
+ "lib/puppet/provider/a2mod/a2mod.rb": "d986d8e8373f3f31c97359381c180628",
+ "lib/puppet/provider/a2mod/gentoo.rb": "2492d446adbb68f678e86a75eb7ff3bd",
+ "lib/puppet/provider/a2mod/modfix.rb": "b689a1c83c9ccd8590399c67f3e588e5",
+ "lib/puppet/provider/a2mod/redhat.rb": "c39b80e75e7d0666def31c2a6cdedb0b",
+ "lib/puppet/type/a2mod.rb": "9042ccc045bfeecca28bebb834114f05",
+ "manifests/balancer.pp": "c635b2d2dec8b5972509960152e169a3",
+ "manifests/balancermember.pp": "8afe51921a42545402fa457820162ae2",
+ "manifests/default_mods.pp": "8493f16440d3eb7b9d392049dfef680b",
+ "manifests/default_mods/load.pp": "b3f21b3186216795dd18ee051f01e3c2",
+ "manifests/dev.pp": "606c3cbe27f32b61cfcbd15fb211890c",
+ "manifests/init.pp": "b0d1433c1848ee81f18d528fcdf5abec",
+ "manifests/listen.pp": "5efc62bd75a0a9a9565b12bd8cb2a9e4",
+ "manifests/mod.pp": "fc66b79d9086d8d296c372d605d31890",
+ "manifests/mod/alias.pp": "f5d65ca4755f5464b32c5f95fd42a052",
+ "manifests/mod/auth_basic.pp": "47ff846317d52d2161c6d09cac05f7f8",
+ "manifests/mod/auth_kerb.pp": "7876ffdca25396285a26afae8dd030eb",
+ "manifests/mod/autoindex.pp": "1b07e7737b4b27f977f80c289172a55b",
+ "manifests/mod/cache.pp": "51b4826a72090da8e463bc007695f05b",
+ "manifests/mod/cgi.pp": "8c9265733584e188196fe69fd3b9fdd7",
+ "manifests/mod/cgid.pp": "63bd38d692ec78f351a6f234f29c2f16",
+ "manifests/mod/dav.pp": "f0228b06b7101864f7c943b541e570d2",
+ "manifests/mod/dav_fs.pp": "93fce4f45e7a85e9d6eb2b745390eaba",
+ "manifests/mod/dav_svn.pp": "85a9a3efe5cce6096d89cf29195e6dc1",
+ "manifests/mod/deflate.pp": "f317ddf1cbfee52945d0433a3b25c728",
+ "manifests/mod/dev.pp": "d6a001af402d8e82e952c8243c5e5321",
+ "manifests/mod/dir.pp": "f3c3e6a21653ebda12f35b4b140e68d5",
+ "manifests/mod/disk_cache.pp": "da3b7f47ce079f20db2d20e2d6539c11",
+ "manifests/mod/fcgid.pp": "d03eb1add8f2cef603331dde96f1f7fd",
+ "manifests/mod/headers.pp": "224438518465d09c951eb00dbaf8123c",
+ "manifests/mod/info.pp": "9a45dd07a2681dc1fef9204de3f42bd9",
+ "manifests/mod/itk.pp": "852588a26f2635979abf24fd33f1a9ff",
+ "manifests/mod/ldap.pp": "f5033ee5197938d402854d8ffa9fb1d3",
+ "manifests/mod/mime.pp": "c9ff4215f9308fd729e96a8d76d3fe1d",
+ "manifests/mod/mime_magic.pp": "9c3a73f877de39c1db2178b827c4a86d",
+ "manifests/mod/mpm_event.pp": "c1540d87cfb2b4a4631c4cc5d3e191f5",
+ "manifests/mod/negotiation.pp": "9f5d70e4c961175a78a049fedaac85c9",
+ "manifests/mod/passenger.pp": "29fca0851862aaaa836acf25718c08cc",
+ "manifests/mod/perl.pp": "72195ad624f68e2c0009074d118bf8e4",
+ "manifests/mod/php.pp": "247915331ce4ee815a0c032897a83157",
+ "manifests/mod/prefork.pp": "2eb8a29fa3a81b4b8ade96989ef06742",
+ "manifests/mod/proxy.pp": "e0e9f9963f720501d9b53ab9fb35f256",
+ "manifests/mod/proxy_balancer.pp": "c71c8ae1eb91d29ec26e19899db2bfec",
+ "manifests/mod/proxy_html.pp": "25cbac9bc2553bc3a18ede060a1a14fd",
+ "manifests/mod/proxy_http.pp": "773d0fbb934440a24b3bc87517faa4d4",
+ "manifests/mod/python.pp": "0b22df3d0e9a39ce948212e18329155f",
+ "manifests/mod/reqtimeout.pp": "2ff860e05de7352d4a1bcd57c0ee08f0",
+ "manifests/mod/rewrite.pp": "165fdccc8acc61e5fb088d9917861a3c",
+ "manifests/mod/setenvif.pp": "32098aaab01723cae4c44d2fff8114ea",
+ "manifests/mod/ssl.pp": "80ee4f522104719f07aa2be33d320973",
+ "manifests/mod/status.pp": "1619d96a0d9b9534145209c98c683cbe",
+ "manifests/mod/suphp.pp": "c42d20b057007eff1a75595fc3fe7adf",
+ "manifests/mod/userdir.pp": "7166fee20a3e5b97d61dfae18fb745c9",
+ "manifests/mod/vhost_alias.pp": "ea2d06875ed4f47ba65da0f7169e529e",
+ "manifests/mod/worker.pp": "36bdeaa252d3ba3c14296bbcf2acb9b0",
+ "manifests/mod/wsgi.pp": "092d35c267e671444d42e2243606bc99",
+ "manifests/mod/xsendfile.pp": "ebe6241729f1b0d8125043a1f34caa54",
+ "manifests/namevirtualhost.pp": "27bb9faa95147fcd15ec2aa0a95bc3af",
+ "manifests/params.pp": "525b2ac104a0a4922f6be584bc5c6e9d",
+ "manifests/php.pp": "a4478838b4cf9b0525b04db150cf55b8",
+ "manifests/proxy.pp": "54e7657920b580546f3bef3980f2fd03",
+ "manifests/python.pp": "2edb06e8119b67a5a62fb24fb280d3e5",
+ "manifests/service.pp": "8e5145ad7866adb9b1f26494559ba6a7",
+ "manifests/ssl.pp": "7f944d1c103a59ebd04d02e68af69f7a",
+ "manifests/vhost.pp": "2242685bed5db4a4fa08ebfe1f836084",
+ "spec/classes/apache_spec.rb": "dbeb82d859d03037b86c754d2e9437b9",
+ "spec/classes/dev_spec.rb": "ecc212316f7801f427fa4c30ca65e259",
+ "spec/classes/mod/auth_kerb_spec.rb": "70e2d94d84724a1b54aff6a9dede1ca6",
+ "spec/classes/mod/dav_svn_spec.rb": "6b014a30e017a6cf30bdc4221e4a15b9",
+ "spec/classes/mod/dev_spec.rb": "27a9d92460a3e62842b5e64f7154f893",
+ "spec/classes/mod/dir_spec.rb": "e462dbea87eb1211e496f60e40538370",
+ "spec/classes/mod/fcgid_spec.rb": "3bd6c0638347b763a88e44d5d7216cb0",
+ "spec/classes/mod/info_spec.rb": "3921a934a1d41c6e1cce328a45b3cc1d",
+ "spec/classes/mod/itk_spec.rb": "e9edc7ebebeda4cea0bf896c597c2267",
+ "spec/classes/mod/passenger_spec.rb": "959b0a3235999e5201980871ea2b862a",
+ "spec/classes/mod/perl_spec.rb": "0ba258605762d1fa25398a08e90157e4",
+ "spec/classes/mod/php_spec.rb": "c4050e546d010f0dcb5a8bd580b5f3ed",
+ "spec/classes/mod/prefork_spec.rb": "0f7de99f1fb58670f11fde4f7280e99e",
+ "spec/classes/mod/proxy_html_spec.rb": "bf313b5dfdd2c9f3054f4b791c32a84c",
+ "spec/classes/mod/python_spec.rb": "2b8079e833cbe6313435a72d9fc00cb9",
+ "spec/classes/mod/ssl_spec.rb": "53b8ecefa9ce0af2562d8183c063167d",
+ "spec/classes/mod/suphp_spec.rb": "1da3f6561f19d8c7f2a71655fa7772ea",
+ "spec/classes/mod/worker_spec.rb": "f3324663e5f93d1b73911276bd984e79",
+ "spec/classes/mod/wsgi_spec.rb": "c41bc8e4cc95a87d1448e06b7d8001eb",
+ "spec/classes/params_spec.rb": "9b1984a3e8a485ff128512833400dfbd",
+ "spec/classes/service_spec.rb": "3448d0a4256bd806902c45f2c13bf5a6",
+ "spec/defines/mod_spec.rb": "d82643d472be88a65cd202381099ed6f",
+ "spec/defines/vhost_spec.rb": "4535046a2cf7d7f9745020b92503f2e4",
+ "spec/fixtures/modules/site_apache/templates/fake.conf.erb": "6b0431dd0b9a0bf803eb0684300c2cff",
+ "spec/spec.opts": "c407193b3d9028941ef59edd114f5968",
+ "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc",
+ "spec/spec_helper_system.rb": "c54584d03120766bac28221597920d3d",
+ "spec/system/basic_spec.rb": "73bab7cf3eb0554b7d7801613c4b483e",
+ "spec/system/class_spec.rb": "ada9b7ebb090d6b4e62db22b3c82b330",
+ "spec/system/default_mods_spec.rb": "b57b9deb89c3905a7a7d9ca9e573f62f",
+ "spec/system/itk_spec.rb": "cbce8cac9e311b2cfce48eb2369ced7b",
+ "spec/system/mod_php_spec.rb": "9bc01054af24b981fa1c49ac723469fc",
+ "spec/system/mod_suphp_spec.rb": "9d38045b3dcb052153e7c08164301c13",
+ "spec/system/prefork_worker_spec.rb": "d7b05867fd73464971919fd4393b3719",
+ "spec/system/service_spec.rb": "3cd71e4e40790e1624487fd233f18a07",
+ "spec/system/vhost_spec.rb": "2e3c1fa5ab5a6e4f8513c68904e52269",
+ "spec/unit/provider/a2mod/gentoo_spec.rb": "24ad9db4f6ba0b4fc7ed77b509b4244c",
+ "templates/httpd.conf.erb": "154af1419ad44722c9f33bd1eb9a9637",
+ "templates/listen.erb": "6286aa08f9e28caee54b1e1ee031b9d6",
+ "templates/mod/alias.conf.erb": "669fc0a80839be3a81e2f4d4150c3ad6",
+ "templates/mod/autoindex.conf.erb": "2421a3c6df32c7e38c2a7a22afdf5728",
+ "templates/mod/cgid.conf.erb": "3d4e24001b50eb16561e45f5a8237b32",
+ "templates/mod/dav_fs.conf.erb": "fdf1f8cff4708a282ef491d60868d1d7",
+ "templates/mod/deflate.conf.erb": "44d54f557a5612be8da04c49dd6da862",
+ "templates/mod/dir.conf.erb": "2485da78a2506c14bf51dde38dd03360",
+ "templates/mod/disk_cache.conf.erb": "7d3e7a5ee3bd7b6a839924b06a60667f",
+ "templates/mod/info.conf.erb": "bb48951beaeaf582d1a1023cb661ac32",
+ "templates/mod/itk.conf.erb": "eff84b78e4f2f8c5c3a2e9fc4b8aad16",
+ "templates/mod/ldap.conf.erb": "a8a33f645497e0dbcec363c98be43795",
+ "templates/mod/mime.conf.erb": "2fa646fe615e44d137a5d629f868c107",
+ "templates/mod/mime_magic.conf.erb": "8a4f61bd7539871cb507cc95f5dbd205",
+ "templates/mod/mpm_event.conf.erb": "80097a19d063a4f973465d9ef5c0c0bf",
+ "templates/mod/negotiation.conf.erb": "47284b5580b986a6ba32580b6ffb9fd7",
+ "templates/mod/passenger.conf.erb": "6e0c2d796b5e67aa366eadc53c963a5e",
+ "templates/mod/php5.conf.erb": "49e2d214790835c141fcaf6d74b5a96d",
+ "templates/mod/prefork.conf.erb": "f9ec5a7eaea78a19b04fa69f8acd8a84",
+ "templates/mod/proxy.conf.erb": "ae1cd187ffbd5cc9b74f8711e313e96b",
+ "templates/mod/proxy_html.conf.erb": "67546d56f2d6bb1860338257e3ac9d29",
+ "templates/mod/reqtimeout.conf.erb": "81c51851ab7ee7942bef389dc7c0e985",
+ "templates/mod/setenvif.conf.erb": "c7ede4173da1915b7ec088201f030c28",
+ "templates/mod/ssl.conf.erb": "2567261763976c62a4388abb62ae1e03",
+ "templates/mod/status.conf.erb": "da061291068f8e20cf33812373319c40",
+ "templates/mod/suphp.conf.erb": "05bb7b3ea23976b032ce405bfd4edd18",
+ "templates/mod/userdir.conf.erb": "e5a7a7229dbf0de07bc034dd3d108ea2",
+ "templates/mod/worker.conf.erb": "9661e7a59eaefb9f17d4c2680c0d243d",
+ "templates/mod/wsgi.conf.erb": "7e098b0013f6e64e935bf244f7efcd67",
+ "templates/namevirtualhost.erb": "fbfca19a639e18e6c477e191344ac8ae",
+ "templates/ports_header.erb": "afe35cb5747574b700ebaa0f0b3a626e",
+ "templates/vhost.conf.erb": "bc0f0bae3b149c8b78d9127714f2d28c",
+ "templates/vhost/_aliases.erb": "319183dd74f4b231747fffa7b4a939f3",
+ "templates/vhost/_block.erb": "7cb56db9254729b54e8d30686c4f3b1a",
+ "templates/vhost/_custom_fragment.erb": "67a4475275ec9208e6421b047b9ed7f4",
+ "templates/vhost/_directories.erb": "5131331896f3839221e1231e28b6e509",
+ "templates/vhost/_itk.erb": "db5b12d7236dbc19b62ce13625d9d60e",
+ "templates/vhost/_proxy.erb": "8faa613a00584432f99956f4b0ac1fbd",
+ "templates/vhost/_rack.erb": "ebe187c1bdc81eec9c8e0d9026120b18",
+ "templates/vhost/_redirect.erb": "0e2eed04e30240fbbd6c4ef7db6b7058",
+ "templates/vhost/_requestheader.erb": "db1b0cdda069ae809b5b83b0871ef991",
+ "templates/vhost/_rewrite.erb": "dcf423c014bdb222bcf15314a2f3a41f",
+ "templates/vhost/_scriptalias.erb": "0373372000ca3198594f32ac637a9462",
+ "templates/vhost/_serveralias.erb": "2ef30c2152b9284463588f408f7f371f",
+ "templates/vhost/_setenv.erb": "da6778b324857234c8441ef346d08969",
+ "templates/vhost/_ssl.erb": "5451565f3c34abdd50024af607ed9dc1",
+ "templates/vhost/_suphp.erb": "6ea2553a4c4284d41b435fa2f4f4edc7",
+ "templates/vhost/_wsgi.erb": "3bbab1e5757dfb584504f05354275f81",
+ "tests/apache.pp": "819cf9116ffd349e6757e1926d11ca2f",
+ "tests/dev.pp": "4cf15c1fecea3ca86009f182b402c7ab",
+ "tests/init.pp": "4eac4a7ef68499854c54a78879e25535",
+ "tests/mods.pp": "0085911ba562b7e56ad8d793099c9240",
+ "tests/mods_custom.pp": "9afd068edce0538b5c55a3bc19f9c24a",
+ "tests/php.pp": "ce7bb9eef69d32b42a32ce32d9653625",
+ "tests/vhost.pp": "70ce947e12f9b344a24f95a08e622c6c",
+ "tests/vhost_directories.pp": "b79a3bcf72474ce4e3b75f6a70cbf272",
+ "tests/vhost_ip_based.pp": "7d9f7b6976de7488ab6ff0a6e647fc73",
+ "tests/vhost_ssl.pp": "9f3716bc15a9a6760f1d6cc3bf8ce8ac",
+ "tests/vhosts_without_listen.pp": "a6692104056a56517b4365bcc816e7f4"
+ },
+ "source": "git://github.com/puppetlabs/puppetlabs-apache.git",
+ "project_page": "https://github.com/puppetlabs/puppetlabs-apache",
+ "license": "Apache 2.0"
+}
\ No newline at end of file
diff --git a/puppet/modules/apache/spec/classes/apache_spec.rb b/puppet/modules/apache/spec/classes/apache_spec.rb
new file mode 100644
index 0000000..7e7a87b
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/apache_spec.rb
@@ -0,0 +1,292 @@
+require 'spec_helper'
+
+describe 'apache', :type => :class do
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_package("httpd").with(
+ 'notify' => 'Class[Apache::Service]'
+ )
+ }
+ it { should contain_user("www-data") }
+ it { should contain_group("www-data") }
+ it { should contain_class("apache::service") }
+ it { should contain_file("/etc/apache2/sites-enabled").with(
+ 'ensure' => 'directory',
+ 'recurse' => 'true',
+ 'purge' => 'true',
+ 'notify' => 'Class[Apache::Service]',
+ 'require' => 'Package[httpd]'
+ )
+ }
+ it { should contain_file("/etc/apache2/mods-enabled").with(
+ 'ensure' => 'directory',
+ 'recurse' => 'true',
+ 'purge' => 'true',
+ 'notify' => 'Class[Apache::Service]',
+ 'require' => 'Package[httpd]'
+ )
+ }
+ it { should contain_file("/etc/apache2/mods-available").with(
+ 'ensure' => 'directory',
+ 'recurse' => 'true',
+ 'purge' => 'true',
+ 'notify' => 'Class[Apache::Service]',
+ 'require' => 'Package[httpd]'
+ )
+ }
+ it { should contain_concat("/etc/apache2/ports.conf").with(
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ 'notify' => 'Class[Apache::Service]'
+ )
+ }
+ # Assert that load files are placed and symlinked for these mods, but no conf file.
+ [
+ 'auth_basic',
+ 'authn_file',
+ 'authz_default',
+ 'authz_groupfile',
+ 'authz_host',
+ 'authz_user',
+ 'dav',
+ 'env'
+ ].each do |modname|
+ it { should contain_file("#{modname}.load").with(
+ 'path' => "/etc/apache2/mods-available/#{modname}.load",
+ 'ensure' => 'file'
+ ) }
+ it { should contain_file("#{modname}.load symlink").with(
+ 'path' => "/etc/apache2/mods-enabled/#{modname}.load",
+ 'ensure' => 'link',
+ 'target' => "/etc/apache2/mods-available/#{modname}.load"
+ ) }
+ it { should_not contain_file("#{modname}.conf") }
+ it { should_not contain_file("#{modname}.conf symlink") }
+ end
+
+ # Assert that both load files and conf files are placed and symlinked for these mods
+ [
+ 'alias',
+ 'autoindex',
+ 'dav_fs',
+ 'deflate',
+ 'dir',
+ 'mime',
+ 'negotiation',
+ 'setenvif',
+ ].each do |modname|
+ it { should contain_file("#{modname}.load").with(
+ 'path' => "/etc/apache2/mods-available/#{modname}.load",
+ 'ensure' => 'file'
+ ) }
+ it { should contain_file("#{modname}.load symlink").with(
+ 'path' => "/etc/apache2/mods-enabled/#{modname}.load",
+ 'ensure' => 'link',
+ 'target' => "/etc/apache2/mods-available/#{modname}.load"
+ ) }
+ it { should contain_file("#{modname}.conf").with(
+ 'path' => "/etc/apache2/mods-available/#{modname}.conf",
+ 'ensure' => 'file'
+ ) }
+ it { should contain_file("#{modname}.conf symlink").with(
+ 'path' => "/etc/apache2/mods-enabled/#{modname}.conf",
+ 'ensure' => 'link',
+ 'target' => "/etc/apache2/mods-available/#{modname}.conf"
+ ) }
+ end
+ end
+ context "on a RedHat 5 OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '5',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_package("httpd").with(
+ 'notify' => 'Class[Apache::Service]'
+ )
+ }
+ it { should contain_user("apache") }
+ it { should contain_group("apache") }
+ it { should contain_class("apache::service") }
+ it { should contain_file("/etc/httpd/conf.d").with(
+ 'ensure' => 'directory',
+ 'recurse' => 'true',
+ 'purge' => 'true',
+ 'notify' => 'Class[Apache::Service]',
+ 'require' => 'Package[httpd]'
+ )
+ }
+ it { should contain_concat("/etc/httpd/conf/ports.conf").with(
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ 'notify' => 'Class[Apache::Service]'
+ )
+ }
+ describe "Alternate confd/mod/vhosts directory" do
+ let :params do
+ {
+ :vhost_dir => '/etc/httpd/site.d',
+ :confd_dir => '/etc/httpd/conf.d',
+ :mod_dir => '/etc/httpd/mod.d',
+ }
+ end
+
+ ['mod.d','site.d','conf.d'].each do |dir|
+ it { should contain_file("/etc/httpd/#{dir}").with(
+ 'ensure' => 'directory',
+ 'recurse' => 'true',
+ 'purge' => 'true',
+ 'notify' => 'Class[Apache::Service]',
+ 'require' => 'Package[httpd]'
+ ) }
+ end
+
+ # Assert that load files are placed for these mods, but no conf file.
+ [
+ 'auth_basic',
+ 'authn_file',
+ 'authz_default',
+ 'authz_groupfile',
+ 'authz_host',
+ 'authz_user',
+ 'dav',
+ 'env',
+ ].each do |modname|
+ it { should contain_file("#{modname}.load").with_path(
+ "/etc/httpd/mod.d/#{modname}.load"
+ ) }
+ it { should_not contain_file("#{modname}.conf").with_path(
+ "/etc/httpd/mod.d/#{modname}.conf"
+ ) }
+ end
+
+ # Assert that both load files and conf files are placed for these mods
+ [
+ 'alias',
+ 'autoindex',
+ 'dav_fs',
+ 'deflate',
+ 'dir',
+ 'mime',
+ 'negotiation',
+ 'setenvif',
+ ].each do |modname|
+ it { should contain_file("#{modname}.load").with_path(
+ "/etc/httpd/mod.d/#{modname}.load"
+ ) }
+ it { should contain_file("#{modname}.conf").with_path(
+ "/etc/httpd/mod.d/#{modname}.conf"
+ ) }
+ end
+
+ it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include /etc/httpd/conf\.d/\*\.conf$} }
+ it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include /etc/httpd/site\.d/\*\.conf$} }
+ it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include /etc/httpd/mod\.d/\*\.conf$} }
+ it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include /etc/httpd/mod\.d/\*\.load$} }
+ end
+
+ describe "Alternate conf.d directory" do
+ let :params do
+ { :confd_dir => '/etc/httpd/special_conf.d' }
+ end
+
+ it { should contain_file("/etc/httpd/special_conf.d").with(
+ 'ensure' => 'directory',
+ 'recurse' => 'true',
+ 'purge' => 'true',
+ 'notify' => 'Class[Apache::Service]',
+ 'require' => 'Package[httpd]'
+ ) }
+ end
+
+ describe "Alternate mpm_modules" do
+ context "when declaring mpm_module is false" do
+ let :params do
+ { :mpm_module => false }
+ end
+ it 'should not declare mpm modules' do
+ should_not contain_class('apache::mod::itk')
+ should_not contain_class('apache::mod::prefork')
+ should_not contain_class('apache::mod::worker')
+ end
+ end
+ context "when declaring mpm_module => prefork" do
+ let :params do
+ { :mpm_module => 'prefork' }
+ end
+ it { should contain_class('apache::mod::prefork') }
+ it { should_not contain_class('apache::mod::itk') }
+ it { should_not contain_class('apache::mod::worker') }
+ end
+ context "when declaring mpm_module => worker" do
+ let :params do
+ { :mpm_module => 'worker' }
+ end
+ it { should contain_class('apache::mod::worker') }
+ it { should_not contain_class('apache::mod::itk') }
+ it { should_not contain_class('apache::mod::prefork') }
+ end
+ context "when declaring mpm_module => breakme" do
+ let :params do
+ { :mpm_module => 'breakme' }
+ end
+ it { expect { should contain_class('apache::params') }.to raise_error Puppet::Error, /does not match/ }
+ end
+ end
+
+ describe "different templates for httpd.conf" do
+ context "with default" do
+ let :params do
+ { :conf_template => 'apache/httpd.conf.erb' }
+ end
+ it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^# Security\n} }
+ end
+ context "with non-default" do
+ let :params do
+ { :conf_template => 'site_apache/fake.conf.erb' }
+ end
+ it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Fake template for rspec.$} }
+ end
+ end
+
+ describe "default mods" do
+ context "without" do
+ let :params do
+ { :default_mods => false }
+ end
+
+ it { should contain_apache__mod('authz_host') }
+ it { should_not contain_apache__mod('env') }
+ end
+ context "custom" do
+ let :params do
+ { :default_mods => [
+ 'info',
+ 'alias',
+ 'mime',
+ 'env',
+ 'setenv',
+ 'expires',
+ ]}
+ end
+
+ it { should contain_apache__mod('authz_host') }
+ it { should contain_apache__mod('env') }
+ it { should contain_class('apache::mod::info') }
+ it { should contain_class('apache::mod::mime') }
+ end
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/dev_spec.rb b/puppet/modules/apache/spec/classes/dev_spec.rb
new file mode 100644
index 0000000..8bdf120
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/dev_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe 'apache::dev', :type => :class do
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_package("libaprutil1-dev") }
+ it { should contain_package("libapr1-dev") }
+ it { should contain_package("apache2-prefork-dev") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_package("httpd-devel") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/auth_kerb_spec.rb b/puppet/modules/apache/spec/classes/mod/auth_kerb_spec.rb
new file mode 100644
index 0000000..c4aa8a6
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/auth_kerb_spec.rb
@@ -0,0 +1,29 @@
+describe 'apache::mod::auth_kerb', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod("auth_kerb") }
+ it { should contain_package("libapache2-mod-auth-kerb") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod("auth_kerb") }
+ it { should contain_package("mod_auth_kerb") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/dav_svn_spec.rb b/puppet/modules/apache/spec/classes/mod/dav_svn_spec.rb
new file mode 100644
index 0000000..4d293b3
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/dav_svn_spec.rb
@@ -0,0 +1,29 @@
+describe 'apache::mod::dav_svn', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('dav_svn') }
+ it { should contain_package("libapache2-svn") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('dav_svn') }
+ it { should contain_package("mod_dav_svn") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/dev_spec.rb b/puppet/modules/apache/spec/classes/mod/dev_spec.rb
new file mode 100644
index 0000000..4d88768
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/dev_spec.rb
@@ -0,0 +1,27 @@
+describe 'apache::dev', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should contain_package("libaprutil1-dev") }
+ it { should contain_package("libapr1-dev") }
+ it { should contain_package("apache2-prefork-dev") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should contain_package("httpd-devel") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/dir_spec.rb b/puppet/modules/apache/spec/classes/mod/dir_spec.rb
new file mode 100644
index 0000000..ec94b28
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/dir_spec.rb
@@ -0,0 +1,61 @@
+describe 'apache::mod::dir', :type => :class do
+ let :pre_condition do
+ 'class { "apache":
+ default_mods => false,
+ }'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ context "passing no parameters" do
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('dir') }
+ it { should contain_file('dir.conf').with_content(/^DirectoryIndex /) }
+ it { should contain_file('dir.conf').with_content(/ index\.html /) }
+ it { should contain_file('dir.conf').with_content(/ index\.html\.var /) }
+ it { should contain_file('dir.conf').with_content(/ index\.cgi /) }
+ it { should contain_file('dir.conf').with_content(/ index\.pl /) }
+ it { should contain_file('dir.conf').with_content(/ index\.php /) }
+ it { should contain_file('dir.conf').with_content(/ index\.xhtml$/) }
+ end
+ context "passing indexes => ['example.txt','fearsome.aspx']" do
+ let :params do
+ {:indexes => ['example.txt','fearsome.aspx']}
+ end
+ it { should contain_file('dir.conf').with_content(/ example\.txt /) }
+ it { should contain_file('dir.conf').with_content(/ fearsome\.aspx$/) }
+ end
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ context "passing no parameters" do
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('dir') }
+ it { should contain_file('dir.conf').with_content(/^DirectoryIndex /) }
+ it { should contain_file('dir.conf').with_content(/ index\.html /) }
+ it { should contain_file('dir.conf').with_content(/ index\.html\.var /) }
+ it { should contain_file('dir.conf').with_content(/ index\.cgi /) }
+ it { should contain_file('dir.conf').with_content(/ index\.pl /) }
+ it { should contain_file('dir.conf').with_content(/ index\.php /) }
+ it { should contain_file('dir.conf').with_content(/ index\.xhtml$/) }
+ end
+ context "passing indexes => ['example.txt','fearsome.aspx']" do
+ let :params do
+ {:indexes => ['example.txt','fearsome.aspx']}
+ end
+ it { should contain_file('dir.conf').with_content(/ example\.txt /) }
+ it { should contain_file('dir.conf').with_content(/ fearsome\.aspx$/) }
+ end
+ end
+end
\ No newline at end of file
diff --git a/puppet/modules/apache/spec/classes/mod/fcgid_spec.rb b/puppet/modules/apache/spec/classes/mod/fcgid_spec.rb
new file mode 100644
index 0000000..be444c8
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/fcgid_spec.rb
@@ -0,0 +1,29 @@
+describe 'apache::mod::fcgid', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('fcgid') }
+ it { should contain_package("libapache2-mod-fcgid") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('fcgid') }
+ it { should contain_package("mod_fcgid") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/info_spec.rb b/puppet/modules/apache/spec/classes/mod/info_spec.rb
new file mode 100644
index 0000000..a057bf1
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/info_spec.rb
@@ -0,0 +1,81 @@
+# This function is called inside the OS specific contexts
+def general_info_specs
+ it { should contain_apache__mod("info") }
+
+ it do
+ should contain_file("info.conf").with_content(
+ "<Location /server-info>\n"\
+ " SetHandler server-info\n"\
+ " Order deny,allow\n"\
+ " Deny from all\n"\
+ " Allow from 127.0.0.1 ::1\n"\
+ "</Location>\n"
+ )
+ end
+end
+
+describe 'apache::mod::info', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+
+ context "On a Debian OS with default params" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+
+ # Load the more generic tests for this context
+ general_info_specs()
+
+ it { should contain_file("info.conf").with({
+ :ensure => 'file',
+ :path => '/etc/apache2/mods-available/info.conf',
+ } ) }
+ it { should contain_file("info.conf symlink").with({
+ :ensure => 'link',
+ :path => '/etc/apache2/mods-enabled/info.conf',
+ } ) }
+ end
+
+ context "on a RedHat OS with default params" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+
+ # Load the more generic tests for this context
+ general_info_specs()
+
+ it { should contain_file("info.conf").with_path("/etc/httpd/conf.d/info.conf") }
+ end
+
+ context "with $allow_from => ['10.10.10.10','11.11.11.11']" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ let :params do
+ { :allow_from => ['10.10.10.10','11.11.11.11'] }
+ end
+ it do
+ should contain_file("info.conf").with_content(
+ "<Location /server-info>\n"\
+ " SetHandler server-info\n"\
+ " Order deny,allow\n"\
+ " Deny from all\n"\
+ " Allow from 10.10.10.10 11.11.11.11\n"\
+ "</Location>\n"
+ )
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/itk_spec.rb b/puppet/modules/apache/spec/classes/mod/itk_spec.rb
new file mode 100644
index 0000000..7a0f761
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/itk_spec.rb
@@ -0,0 +1,19 @@
+describe 'apache::mod::itk', :type => :class do
+ let :pre_condition do
+ 'class { "apache": mpm_module => false, }'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should_not contain_apache__mod('itk') }
+ it { should contain_file("/etc/apache2/mods-available/itk.conf").with_ensure('file') }
+ it { should contain_file("/etc/apache2/mods-enabled/itk.conf").with_ensure('link') }
+ it { should contain_package("apache2-mpm-itk") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/passenger_spec.rb b/puppet/modules/apache/spec/classes/mod/passenger_spec.rb
new file mode 100644
index 0000000..2e5212f
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/passenger_spec.rb
@@ -0,0 +1,94 @@
+describe 'apache::mod::passenger', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('passenger') }
+ it { should contain_package("libapache2-mod-passenger") }
+ it { should contain_file('passenger.conf').with({
+ 'path' => '/etc/apache2/mods-available/passenger.conf',
+ }) }
+ it { should contain_file('passenger.conf').with_content(/^ PassengerRoot \/usr$/) }
+ it { should contain_file('passenger.conf').with_content(/^ PassengerRuby \/usr\/bin\/ruby$/) }
+ describe "with passenger_high_performance => true" do
+ let :params do
+ { :passenger_high_performance => 'true' }
+ end
+ it { should contain_file('passenger.conf').with_content(/^ PassengerHighPerformance true$/) }
+ end
+ describe "with passenger_pool_idle_time => 1200" do
+ let :params do
+ { :passenger_pool_idle_time => 1200 }
+ end
+ it { should contain_file('passenger.conf').with_content(/^ PassengerPoolIdleTime 1200$/) }
+ end
+ describe "with passenger_max_requests => 20" do
+ let :params do
+ { :passenger_max_requests => 20 }
+ end
+ it { should contain_file('passenger.conf').with_content(/^ PassengerMaxRequests 20$/) }
+ end
+ describe "with passenger_stat_throttle_rate => 10" do
+ let :params do
+ { :passenger_stat_throttle_rate => 10 }
+ end
+ it { should contain_file('passenger.conf').with_content(/^ PassengerStatThrottleRate 10$/) }
+ end
+ describe "with passenger_max_pool_size => 16" do
+ let :params do
+ { :passenger_max_pool_size => 16 }
+ end
+ it { should contain_file('passenger.conf').with_content(/^ PassengerMaxPoolSize 16$/) }
+ end
+ describe "with rack_autodetect => true" do
+ let :params do
+ { :rack_autodetect => true }
+ end
+ it { should contain_file('passenger.conf').with_content(/^ RackAutoDetect true$/) }
+ end
+ describe "with rails_autodetect => true" do
+ let :params do
+ { :rails_autodetect => true }
+ end
+ it { should contain_file('passenger.conf').with_content(/^ RailsAutoDetect true$/) }
+ end
+ describe "with passenger_root => '/usr/lib/example'" do
+ let :params do
+ { :passenger_root => '/usr/lib/example' }
+ end
+ it { should contain_file('passenger.conf').with_content(/^ PassengerRoot \/usr\/lib\/example$/) }
+ end
+ describe "with passenger_ruby => /user/lib/example/ruby" do
+ let :params do
+ { :passenger_ruby => '/user/lib/example/ruby' }
+ end
+ it { should contain_file('passenger.conf').with_content(/^ PassengerRuby \/user\/lib\/example\/ruby$/) }
+ end
+
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('passenger') }
+ it { should contain_package("mod_passenger") }
+ it { should contain_file('passenger.conf').with({
+ 'path' => '/etc/httpd/conf.d/passenger.conf',
+ }) }
+ it { should contain_file('passenger.conf').with_content(/^ PassengerRoot \/usr\/share\/rubygems\/gems\/passenger-3.0.17$/) }
+ it { should contain_file('passenger.conf').with_content(/^ PassengerRuby \/usr\/bin\/ruby$/) }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/perl_spec.rb b/puppet/modules/apache/spec/classes/mod/perl_spec.rb
new file mode 100644
index 0000000..0f76abb
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/perl_spec.rb
@@ -0,0 +1,29 @@
+describe 'apache::mod::perl', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('perl') }
+ it { should contain_package("libapache2-mod-perl2") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('perl') }
+ it { should contain_package("mod_perl") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/php_spec.rb b/puppet/modules/apache/spec/classes/mod/php_spec.rb
new file mode 100644
index 0000000..6bcfc43
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/php_spec.rb
@@ -0,0 +1,61 @@
+describe 'apache::mod::php', :type => :class do
+ describe "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ context "with mpm_module => prefork" do
+ let :pre_condition do
+ 'class { "apache": mpm_module => prefork, }'
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('php5') }
+ it { should contain_package("libapache2-mod-php5") }
+ it { should contain_file("php5.load").with(
+ :content => "LoadModule php5_module /usr/lib/apache2/modules/libphp5.so\n"
+ ) }
+ end
+ context 'with mpm_module => worker' do
+ let :pre_condition do
+ 'class { "apache": mpm_module => worker, }'
+ end
+ it 'should raise an error' do
+ expect { subject.should contain_apache__mod('php5') }.to raise_error Puppet::Error, /mpm_module => 'prefork'/
+ end
+ end
+ end
+ describe "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ context "with default params" do
+ let :pre_condition do
+ 'class { "apache": }'
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('php5') }
+ it { should contain_package("php") }
+ it { should contain_file("php5.load").with(
+ :content => "LoadModule php5_module modules/libphp5.so\n"
+ ) }
+ end
+ context "with mpm_module => prefork" do
+ let :pre_condition do
+ 'class { "apache": mpm_module => prefork, }'
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('php5') }
+ it { should contain_package("php") }
+ it { should contain_file("php5.load").with(
+ :content => "LoadModule php5_module modules/libphp5.so\n"
+ ) }
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/prefork_spec.rb b/puppet/modules/apache/spec/classes/mod/prefork_spec.rb
new file mode 100644
index 0000000..fa34a20
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/prefork_spec.rb
@@ -0,0 +1,35 @@
+describe 'apache::mod::prefork', :type => :class do
+ let :pre_condition do
+ 'class { "apache": mpm_module => false, }'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should_not contain_apache__mod('prefork') }
+ it { should contain_file("/etc/apache2/mods-available/prefork.conf").with_ensure('file') }
+ it { should contain_file("/etc/apache2/mods-enabled/prefork.conf").with_ensure('link') }
+ it { should contain_package("apache2-mpm-prefork") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should_not contain_apache__mod('prefork') }
+ it { should contain_file("/etc/httpd/conf.d/prefork.conf").with_ensure('file') }
+ it { should contain_file_line("/etc/sysconfig/httpd prefork enable").with({
+ 'require' => 'Package[httpd]',
+ })
+ }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/proxy_html_spec.rb b/puppet/modules/apache/spec/classes/mod/proxy_html_spec.rb
new file mode 100644
index 0000000..c257fe7
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/proxy_html_spec.rb
@@ -0,0 +1,33 @@
+describe 'apache::mod::proxy_html', :type => :class do
+ let :pre_condition do
+ [
+ 'include apache',
+ 'include apache::mod::proxy',
+ 'include apache::mod::proxy_http',
+ ]
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('proxy_html') }
+ it { should contain_package("libapache2-mod-proxy-html") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('proxy_html') }
+ it { should contain_package("mod_proxy_html") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/python_spec.rb b/puppet/modules/apache/spec/classes/mod/python_spec.rb
new file mode 100644
index 0000000..09e8cc2
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/python_spec.rb
@@ -0,0 +1,29 @@
+describe 'apache::mod::python', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod("python") }
+ it { should contain_package("libapache2-mod-python") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod("python") }
+ it { should contain_package("mod_python") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/ssl_spec.rb b/puppet/modules/apache/spec/classes/mod/ssl_spec.rb
new file mode 100644
index 0000000..9444d89
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/ssl_spec.rb
@@ -0,0 +1,41 @@
+describe 'apache::mod::ssl', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+ context 'on an unsupported OS' do
+ let :facts do
+ {
+ :osfamily => 'Magic',
+ :operatingsystemrelease => '0',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { expect { should raise_error(Puppet::Error, "Unsupported operatingsystem:") } }
+ end
+
+ context 'on a RedHat OS' do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class('apache::params') }
+ it { should contain_apache__mod('ssl') }
+ it { should contain_package('mod_ssl') }
+ end
+
+ context 'on a Debian OS' do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class('apache::params') }
+ it { should contain_apache__mod('ssl') }
+ it { should_not contain_package('libapache2-mod-ssl') }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/suphp_spec.rb b/puppet/modules/apache/spec/classes/mod/suphp_spec.rb
new file mode 100644
index 0000000..2d6517c
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/suphp_spec.rb
@@ -0,0 +1,27 @@
+describe 'apache::mod::suphp', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_package("libapache2-mod-suphp") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_package("mod_suphp") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/worker_spec.rb b/puppet/modules/apache/spec/classes/mod/worker_spec.rb
new file mode 100644
index 0000000..7d55432
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/worker_spec.rb
@@ -0,0 +1,32 @@
+describe 'apache::mod::worker', :type => :class do
+ let :pre_condition do
+ 'class { "apache": mpm_module => false, }'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should_not contain_apache__mod('worker') }
+ it { should contain_file("/etc/apache2/mods-available/worker.conf").with_ensure('file') }
+ it { should contain_file("/etc/apache2/mods-enabled/worker.conf").with_ensure('link') }
+ it { should contain_package("apache2-mpm-worker") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should_not contain_apache__mod('worker') }
+ it { should contain_file("/etc/httpd/conf.d/worker.conf").with_ensure('file') }
+ it { should contain_file_line("/etc/sysconfig/httpd worker enable") }
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/mod/wsgi_spec.rb b/puppet/modules/apache/spec/classes/mod/wsgi_spec.rb
new file mode 100644
index 0000000..30ef523
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/mod/wsgi_spec.rb
@@ -0,0 +1,42 @@
+describe 'apache::mod::wsgi', :type => :class do
+ let :pre_condition do
+ 'include apache'
+ end
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('wsgi') }
+ it { should contain_package("libapache2-mod-wsgi") }
+ end
+ context "on a RedHat OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should include_class("apache::params") }
+ it { should contain_apache__mod('wsgi') }
+ it { should contain_package("mod_wsgi") }
+
+ describe "with custom WSGISocketPrefix" do
+ let :params do
+ { :wsgi_socket_prefix => 'run/wsgi' }
+ end
+ it {should contain_file('wsgi.conf').with_content(/^ WSGISocketPrefix run\/wsgi$/)}
+ end
+ describe "with custom WSGIPythonHome" do
+ let :params do
+ { :wsgi_python_home => '/path/to/virtenv' }
+ end
+ it {should contain_file('wsgi.conf').with_content(/^ WSGIPythonHome \/path\/to\/virtenv$/)}
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/params_spec.rb b/puppet/modules/apache/spec/classes/params_spec.rb
new file mode 100644
index 0000000..39e16b6
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/params_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe 'apache::params', :type => :class do
+ context "On a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should contain_apache__params }
+
+ # There are 4 resources in this class currently
+ # there should not be any more resources because it is a params class
+ # The resources are class[apache::params], class[main], class[settings], stage[main]
+ it "Should not contain any resources" do
+ subject.resources.size.should == 4
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/classes/service_spec.rb b/puppet/modules/apache/spec/classes/service_spec.rb
new file mode 100644
index 0000000..745b100
--- /dev/null
+++ b/puppet/modules/apache/spec/classes/service_spec.rb
@@ -0,0 +1,62 @@
+require 'spec_helper'
+
+describe 'apache::service', :type => :class do
+ context "on a Debian OS" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should contain_service("httpd").with(
+ 'ensure' => 'true',
+ 'enable' => 'true'
+ )
+ }
+
+ context "with $service_enable => true" do
+ let (:params) {{ :service_enable => true }}
+ it { should contain_service("httpd").with(
+ 'ensure' => 'true',
+ 'enable' => 'true'
+ )
+ }
+ end
+
+ context "with $service_enable => false" do
+ let (:params) {{ :service_enable => false }}
+ it { should contain_service("httpd").with(
+ 'ensure' => 'false',
+ 'enable' => 'false'
+ )
+ }
+ end
+
+ context "$service_enable must be a bool" do
+ let (:params) {{ :service_enable => 'not-a-boolean' }}
+
+ it 'should fail' do
+ expect {
+ should include_class('apache::service')
+ }.to raise_error(Puppet::Error, /is not a boolean/)
+ end
+ end
+ end
+
+
+ context "on a RedHat 5 OS" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '5',
+ :concat_basedir => '/dne',
+ }
+ end
+ it { should contain_service("httpd").with(
+ 'ensure' => 'true',
+ 'enable' => 'true'
+ )
+ }
+ end
+end
diff --git a/puppet/modules/apache/spec/defines/mod_spec.rb b/puppet/modules/apache/spec/defines/mod_spec.rb
new file mode 100644
index 0000000..77c8dfd
--- /dev/null
+++ b/puppet/modules/apache/spec/defines/mod_spec.rb
@@ -0,0 +1,79 @@
+require 'spec_helper'
+
+describe 'apache::mod', :type => :define do
+ let :pre_condition do
+ 'include apache'
+ end
+ context "on a RedHat osfamily" do
+ let :facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+
+ describe "for non-special modules" do
+ let :title do
+ 'spec_m'
+ end
+ it { should include_class("apache::params") }
+ it "should manage the module load file" do
+ should contain_file('spec_m.load').with({
+ :path => '/etc/httpd/conf.d/spec_m.load',
+ :content => "LoadModule spec_m_module modules/mod_spec_m.so\n",
+ :owner => 'root',
+ :group => 'root',
+ :mode => '0644',
+ } )
+ end
+ end
+
+ describe "with shibboleth module and package param passed" do
+ # name/title for the apache::mod define
+ let :title do
+ 'xsendfile'
+ end
+ # parameters
+ let(:params) { {:package => 'mod_xsendfile'} }
+
+ it { should include_class("apache::params") }
+ it { should contain_package('mod_xsendfile') }
+ end
+ end
+
+ context "on a Debian osfamily" do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+
+ describe "for non-special modules" do
+ let :title do
+ 'spec_m'
+ end
+ it { should include_class("apache::params") }
+ it "should manage the module load file" do
+ should contain_file('spec_m.load').with({
+ :path => '/etc/apache2/mods-available/spec_m.load',
+ :content => "LoadModule spec_m_module /usr/lib/apache2/modules/mod_spec_m.so\n",
+ :owner => 'root',
+ :group => 'root',
+ :mode => '0644',
+ } )
+ end
+ it "should link the module load file" do
+ should contain_file('spec_m.load symlink').with({
+ :path => '/etc/apache2/mods-enabled/spec_m.load',
+ :target => '/etc/apache2/mods-available/spec_m.load',
+ :owner => 'root',
+ :group => 'root',
+ :mode => '0644',
+ } )
+ end
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/defines/vhost_spec.rb b/puppet/modules/apache/spec/defines/vhost_spec.rb
new file mode 100644
index 0000000..a2a3777
--- /dev/null
+++ b/puppet/modules/apache/spec/defines/vhost_spec.rb
@@ -0,0 +1,658 @@
+require 'spec_helper'
+
+describe 'apache::vhost', :type => :define do
+ let :pre_condition do
+ 'class { "apache": default_vhost => false, }'
+ end
+ let :title do
+ 'rspec.example.com'
+ end
+ let :default_params do
+ {
+ :docroot => '/rspec/docroot',
+ :port => '84',
+ }
+ end
+ describe 'os-dependent items' do
+ context "on RedHat based systems" do
+ let :default_facts do
+ {
+ :osfamily => 'RedHat',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ let :params do default_params end
+ let :facts do default_facts end
+ it { should include_class("apache") }
+ it { should include_class("apache::params") }
+ end
+ context "on Debian based systems" do
+ let :default_facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ let :params do default_params end
+ let :facts do default_facts end
+ it { should include_class("apache") }
+ it { should include_class("apache::params") }
+ it { should contain_file("25-rspec.example.com.conf").with(
+ :ensure => 'present',
+ :path => '/etc/apache2/sites-available/25-rspec.example.com.conf'
+ ) }
+ it { should contain_file("25-rspec.example.com.conf symlink").with(
+ :ensure => 'link',
+ :path => '/etc/apache2/sites-enabled/25-rspec.example.com.conf',
+ :target => '/etc/apache2/sites-available/25-rspec.example.com.conf'
+ ) }
+ end
+ end
+ describe 'os-independent items' do
+ let :facts do
+ {
+ :osfamily => 'Debian',
+ :operatingsystemrelease => '6',
+ :concat_basedir => '/dne',
+ }
+ end
+ describe 'basic assumptions' do
+ let :params do default_params end
+ it { should include_class("apache") }
+ it { should include_class("apache::params") }
+ it { should contain_apache__listen(params[:port]) }
+ it { should contain_apache__namevirtualhost("*:#{params[:port]}") }
+ end
+
+ context ".conf content" do
+ [
+ {
+ :title => 'should contain docroot',
+ :attr => 'docroot',
+ :value => '/not/default',
+ :match => [' DocumentRoot /not/default',' <Directory /not/default>'],
+ },
+ {
+ :title => 'should set a port',
+ :attr => 'port',
+ :value => '8080',
+ :match => '<VirtualHost *:8080>',
+ },
+ {
+ :title => 'should set an ip',
+ :attr => 'ip',
+ :value => '10.0.0.1',
+ :match => '<VirtualHost 10.0.0.1:84>',
+ },
+ {
+ :title => 'should set a serveradmin',
+ :attr => 'serveradmin',
+ :value => 'test@test.com',
+ :match => ' ServerAdmin test@test.com'
+ },
+ {
+ :title => 'should enable ssl',
+ :attr => 'ssl',
+ :value => true,
+ :match => ' SSLEngine on',
+ },
+ {
+ :title => 'should set a servername',
+ :attr => 'servername',
+ :value => 'param.test',
+ :match => ' ServerName param.test',
+ },
+ {
+ :title => 'should accept server aliases',
+ :attr => 'serveraliases',
+ :value => ['one.com','two.com'],
+ :match => [' ServerAlias one.com',' ServerAlias two.com'],
+ },
+ {
+ :title => 'should accept setenv',
+ :attr => 'setenv',
+ :value => ['TEST1 one','TEST2 two'],
+ :match => [' SetEnv TEST1 one',' SetEnv TEST2 two'],
+ },
+ {
+ :title => 'should accept setenvif',
+ :attr => 'setenvif',
+ ## These are bugged in rspec-puppet; the $1 is droped
+ #:value => ['Host "^([^\.]*)\.website\.com$" CLIENT_NAME=$1'],
+ #:match => [' SetEnvIf Host "^([^\.]*)\.website\.com$" CLIENT_NAME=$1'],
+ :value => ['Host "^test\.com$" VHOST_ACCESS=test'],
+ :match => [' SetEnvIf Host "^test\.com$" VHOST_ACCESS=test'],
+ },
+ {
+ :title => 'should accept options',
+ :attr => 'options',
+ :value => ['Fake','Options'],
+ :match => ' Options Fake Options',
+ },
+ {
+ :title => 'should accept overrides',
+ :attr => 'override',
+ :value => ['Fake', 'Override'],
+ :match => ' AllowOverride Fake Override',
+ },
+ {
+ :title => 'should accept logroot',
+ :attr => 'logroot',
+ :value => '/fake/log',
+ :match => [/CustomLog \/fake\/log\//,/ErrorLog \/fake\/log\//],
+ },
+ {
+ :title => 'should accept pipe destination for access log',
+ :attr => 'access_log_pipe',
+ :value => '| /bin/fake/logging',
+ :match => /CustomLog "| \/bin\/fake\/logging" combined$/,
+ },
+ {
+ :title => 'should accept pipe destination for error log',
+ :attr => 'error_log_pipe',
+ :value => '| /bin/fake/logging',
+ :match => /ErrorLog "| \/bin\/fake\/logging" combined$/,
+ },
+ {
+ :title => 'should accept syslog destination for access log',
+ :attr => 'access_log_syslog',
+ :value => 'syslog:local1',
+ :match => /CustomLog syslog:local1 combined$/,
+ },
+ {
+ :title => 'should accept syslog destination for error log',
+ :attr => 'error_log_syslog',
+ :value => 'syslog',
+ :match => /ErrorLog syslog$/,
+ },
+ {
+ :title => 'should accept custom format for access logs',
+ :attr => 'access_log_format',
+ :value => '%h %{X-Forwarded-For}i %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\" \"Host: %{Host}i\" %T %D',
+ :match => /CustomLog \/var\/log\/.+_access\.log "%h %\{X-Forwarded-For\}i %l %u %t \\"%r\\" %s %b \\"%\{Referer\}i\\" \\"%\{User-agent\}i\\" \\"Host: %\{Host\}i\\" %T %D"$/,
+ },
+ {
+ :title => 'should contain access logs',
+ :attr => 'access_log',
+ :value => true,
+ :match => /CustomLog \/var\/log\/.+_access\.log combined$/,
+ },
+ {
+ :title => 'should not contain access logs',
+ :attr => 'access_log',
+ :value => false,
+ :notmatch => /CustomLog \/var\/log\/.+_access\.log combined$/,
+ },
+ {
+ :title => 'should contain error logs',
+ :attr => 'error_log',
+ :value => true,
+ :match => /ErrorLog.+$/,
+ },
+ {
+ :title => 'should not contain error logs',
+ :attr => 'error_log',
+ :value => false,
+ :notmatch => /ErrorLog.+$/,
+ },
+ {
+ :title => 'should accept scriptaliases',
+ :attr => 'scriptalias',
+ :value => '/usr/scripts',
+ :match => ' ScriptAlias /cgi-bin/ "/usr/scripts/"',
+ },
+ {
+ :title => 'should accept proxy destinations',
+ :attr => 'proxy_dest',
+ :value => 'http://fake.com',
+ :match => [
+ ' ProxyPass / http://fake.com/',
+ ' ProxyPassReverse / http://fake.com/',
+ ],
+ :notmatch => /ProxyPass .+!$/,
+ },
+ {
+ :title => 'should accept proxy_pass hash',
+ :attr => 'proxy_pass',
+ :value => { 'path' => '/path-a', 'url' => 'http://fake.com/a/' },
+ :match => [
+ ' ProxyPass /path-a http://fake.com/a/',
+ ' ProxyPassReverse /path-a http://fake.com/a/',
+ ],
+ :notmatch => /ProxyPass .+!$/,
+ },
+ {
+ :title => 'should accept proxy_pass array of hash',
+ :attr => 'proxy_pass',
+ :value => [
+ { 'path' => '/path-a', 'url' => 'http://fake.com/a/' },
+ { 'path' => '/path-b', 'url' => 'http://fake.com/b/' },
+ ],
+ :match => [
+ ' ProxyPass /path-a http://fake.com/a/',
+ ' ProxyPassReverse /path-a http://fake.com/a/',
+ ' ProxyPass /path-b http://fake.com/b/',
+ ' ProxyPassReverse /path-b http://fake.com/b/',
+ ],
+ :notmatch => /ProxyPass .+!$/,
+ },
+ {
+ :title => 'should enable rack',
+ :attr => 'rack_base_uris',
+ :value => ['/rack1','/rack2'],
+ :match => [' RackBaseURI /rack1',' RackBaseURI /rack2'],
+ },
+ {
+ :title => 'should accept request headers',
+ :attr => 'request_headers',
+ :value => ['append something', 'unset something_else'],
+ :match => [
+ ' RequestHeader append something',
+ ' RequestHeader unset something_else',
+ ],
+ },
+ {
+ :title => 'should accept rewrite rules',
+ :attr => 'rewrite_rule',
+ :value => 'not a real rule',
+ :match => ' RewriteRule not a real rule',
+ },
+ {
+ :title => 'should block scm',
+ :attr => 'block',
+ :value => 'scm',
+ :match => ' <DirectoryMatch .*\.(svn|git|bzr)/.*>',
+ },
+ {
+ :title => 'should accept a custom fragment',
+ :attr => 'custom_fragment',
+ :value => " Some custom fragment line\n That spans multiple lines",
+ :match => [
+ ' Some custom fragment line',
+ ' That spans multiple lines',
+ '</VirtualHost>',
+ ],
+ },
+ {
+ :title => 'should accept an array of alias hashes',
+ :attr => 'aliases',
+ :value => [ { 'alias' => '/', 'path' => '/var/www'} ],
+ :match => ' Alias / /var/www',
+ },
+ {
+ :title => 'should accept an alias hash',
+ :attr => 'aliases',
+ :value => { 'alias' => '/', 'path' => '/var/www'},
+ :match => ' Alias / /var/www',
+ },
+ {
+ :title => 'should accept multiple aliases',
+ :attr => 'aliases',
+ :value => [
+ { 'alias' => '/', 'path' => '/var/www'},
+ { 'alias' => '/cgi-bin', 'path' => '/var/www/cgi-bin'},
+ { 'alias' => '/css', 'path' => '/opt/someapp/css'},
+ ],
+ :match => [
+ ' Alias / /var/www',
+ ' Alias /cgi-bin /var/www/cgi-bin',
+ ' Alias /css /opt/someapp/css'
+ ],
+ },
+ {
+ :title => 'should accept a suPHP_Engine',
+ :attr => 'suphp_engine',
+ :value => 'on',
+ :match => ' suPHP_Engine on',
+ },
+ {
+ :title => 'should accept a wsgi script alias',
+ :attr => 'wsgi_script_aliases',
+ :value => { '/' => '/var/www/myapp.wsgi'},
+ :match => ' WSGIScriptAlias / /var/www/myapp.wsgi',
+ },
+ {
+ :title => 'should accept multiple wsgi aliases',
+ :attr => 'wsgi_script_aliases',
+ :value => {
+ '/wiki' => '/usr/local/wsgi/scripts/mywiki.wsgi',
+ '/blog' => '/usr/local/wsgi/scripts/myblog.wsgi',
+ '/' => '/usr/local/wsgi/scripts/myapp.wsgi',
+ },
+ :match => [
+ ' WSGIScriptAlias /wiki /usr/local/wsgi/scripts/mywiki.wsgi',
+ ' WSGIScriptAlias /blog /usr/local/wsgi/scripts/myblog.wsgi',
+ ' WSGIScriptAlias / /usr/local/wsgi/scripts/myapp.wsgi'
+ ],
+ },
+ {
+ :title => 'should accept a directory',
+ :attr => 'directories',
+ :value => { 'path' => '/opt/app' },
+ :notmatch => ' <Directory /rspec/docroot>',
+ :match => [
+ ' <Directory /opt/app>',
+ ' AllowOverride None',
+ ' Order allow,deny',
+ ' Allow from all',
+ ' </Directory>',
+ ],
+ },
+ {
+ :title => 'should accept directory directives hash',
+ :attr => 'directories',
+ :value => {
+ 'path' => '/opt/app',
+ 'headers' => 'Set X-Robots-Tag "noindex, noarchive, nosnippet"',
+ 'allow' => 'from rspec.org',
+ 'allow_override' => 'Lol',
+ 'deny' => 'from google.com',
+ 'options' => '-MultiViews',
+ 'order' => 'deny,yned',
+ 'passenger_enabled' => 'onf',
+ },
+ :match => [
+ ' <Directory /opt/app>',
+ ' Header Set X-Robots-Tag "noindex, noarchive, nosnippet"',
+ ' Allow from rspec.org',
+ ' AllowOverride Lol',
+ ' Deny from google.com',
+ ' Options -MultiViews',
+ ' Order deny,yned',
+ ' PassengerEnabled onf',
+ ' </Directory>',
+ ],
+ },
+ {
+ :title => 'should accept directory directives with arrays and hashes',
+ :attr => 'directories',
+ :value => [
+ {
+ 'path' => '/opt/app1',
+ 'allow' => 'from rspec.org',
+ 'allow_override' => ['AuthConfig','Indexes'],
+ 'deny' => 'from google.com',
+ 'options' => ['-MultiViews','+MultiViews'],
+ 'order' => ['deny','yned'],
+ 'passenger_enabled' => 'onf',
+ },
+ {
+ 'path' => '/opt/app2',
+ 'addhandlers' => {
+ 'handler' => 'cgi-script',
+ 'extensions' => '.cgi',
+ },
+ },
+ ],
+ :match => [
+ ' <Directory /opt/app1>',
+ ' Allow from rspec.org',
+ ' AllowOverride AuthConfig Indexes',
+ ' Deny from google.com',
+ ' Options -MultiViews +MultiViews',
+ ' Order deny,yned',
+ ' PassengerEnabled onf',
+ ' </Directory>',
+ ' <Directory /opt/app2>',
+ ' AllowOverride None',
+ ' Order allow,deny',
+ ' Allow from all',
+ ' AddHandler cgi-script .cgi',
+ ' </Directory>',
+ ],
+ },
+ {
+ :title => 'should accept multiple directories',
+ :attr => 'directories',
+ :value => [
+ { 'path' => '/opt/app' },
+ { 'path' => '/var/www' },
+ { 'path' => '/rspec/docroot'}
+ ],
+ :match => [
+ ' <Directory /opt/app>',
+ ' <Directory /var/www>',
+ ' <Directory /rspec/docroot>',
+ ],
+ },
+ {
+ :title => 'should contain virtual_docroot',
+ :attr => 'virtual_docroot',
+ :value => '/not/default',
+ :match => [
+ ' VirtualDocumentRoot /not/default',
+ ],
+ },
+ ].each do |param|
+ describe "when #{param[:attr]} is #{param[:value]}" do
+ let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end
+
+ it { should contain_file("25-#{title}.conf").with_mode('0644') }
+ it param[:title] do
+ lines = subject.resource('file', "25-#{title}.conf").send(:parameters)[:content].split("\n")
+ (Array(param[:match]).collect { |x| (lines.grep x).first }.length).should == Array(param[:match]).length
+ (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty
+ end
+ end
+ end
+ end
+
+ context 'attribute resources' do
+ describe 'when access_log_file and access_log_pipe are specified' do
+ let :params do default_params.merge({
+ :access_log_file => 'fake.log',
+ :access_log_pipe => '| /bin/fake',
+ }) end
+ it 'should cause a failure' do
+ expect {should raise_error(Puppet::Error, 'Apache::Vhost[${name}]: \'access_log_file\' and \'access_log_pipe\' cannot be defined at the same time') }
+ end
+ end
+ describe 'when error_log_file and error_log_pipe are specified' do
+ let :params do default_params.merge({
+ :error_log_file => 'fake.log',
+ :error_log_pipe => '| /bin/fake',
+ }) end
+ it 'should cause a failure' do
+ expect { should raise_error(Puppet::Error, 'Apache::Vhost[${name}]: \'error_log_file\' and \'error_log_pipe\' cannot be defined at the same time') }
+ end
+ end
+ describe 'when docroot owner is specified' do
+ let :params do default_params.merge({
+ :docroot_owner => 'testuser',
+ :docroot_group => 'testgroup',
+ }) end
+ it 'should set vhost ownership' do
+ should contain_file(params[:docroot]).with({
+ :ensure => :directory,
+ :owner => 'testuser',
+ :group => 'testgroup',
+ })
+ end
+ end
+
+ describe 'when wsgi_daemon_process and wsgi_daemon_process_options are specified' do
+ let :params do default_params.merge({
+ :wsgi_daemon_process => 'example.org',
+ :wsgi_daemon_process_options => { 'processes' => '2', 'threads' => '15' },
+ }) end
+ it 'should set wsgi_daemon_process_options' do
+ should contain_file("25-#{title}.conf").with_content(
+ /^ WSGIDaemonProcess example.org processes=2 threads=15$/
+ )
+ end
+ end
+
+ describe 'when rewrite_rule and rewrite_cond are specified' do
+ let :params do default_params.merge({
+ :rewrite_cond => '%{HTTPS} off',
+ :rewrite_rule => '(.*) https://%{HTTPS_HOST}%{REQUEST_URI}',
+ }) end
+ it 'should set RewriteCond' do
+ should contain_file("25-#{title}.conf").with_content(
+ /^ RewriteCond %\{HTTPS\} off$/
+ )
+ end
+ end
+
+ describe 'when suphp_engine is on and suphp_configpath is specified' do
+ let :params do default_params.merge({
+ :suphp_engine => 'on',
+ :suphp_configpath => '/etc/php5/apache2',
+ }) end
+ it 'should set suphp_configpath' do
+ should contain_file("25-#{title}.conf").with_content(
+ /^ suPHP_ConfigPath \/etc\/php5\/apache2$/
+ )
+ end
+ end
+
+ describe 'when suphp_engine is on and suphp_addhandler is specified' do
+ let :params do default_params.merge({
+ :suphp_engine => 'on',
+ :suphp_addhandler => 'x-httpd-php',
+ }) end
+ it 'should set suphp_addhandler' do
+ should contain_file("25-#{title}.conf").with_content(
+ /^ suPHP_AddHandler x-httpd-php/
+ )
+ end
+ end
+
+ describe 'priority/default settings' do
+ describe 'when neither priority/default is specified' do
+ let :params do default_params end
+ it { should contain_file("25-#{title}.conf").with_path(
+ /25-#{title}.conf/
+ ) }
+ end
+ describe 'when both priority/default_vhost is specified' do
+ let :params do
+ default_params.merge({
+ :priority => 15,
+ :default_vhost => true,
+ })
+ end
+ it { should contain_file("15-#{title}.conf").with_path(
+ /15-#{title}.conf/
+ ) }
+ end
+ describe 'when only priority is specified' do
+ let :params do
+ default_params.merge({ :priority => 14, })
+ end
+ it { should contain_file("14-#{title}.conf").with_path(
+ /14-#{title}.conf/
+ ) }
+ end
+ describe 'when only default is specified' do
+ let :params do
+ default_params.merge({ :default_vhost => true, })
+ end
+ it { should contain_file("10-#{title}.conf").with_path(
+ /10-#{title}.conf/
+ ) }
+ end
+ end
+
+ describe 'various ip/port combos' do
+ describe 'when ip_based is true' do
+ let :params do default_params.merge({ :ip_based => true }) end
+ it 'should not specify a NameVirtualHost' do
+ should contain_apache__listen(params[:port])
+ should_not contain_apache__namevirtualhost("*:#{params[:port]}")
+ end
+ end
+
+ describe 'when ip_based is default' do
+ let :params do default_params end
+ it 'should specify a NameVirtualHost' do
+ should contain_apache__listen(params[:port])
+ should contain_apache__namevirtualhost("*:#{params[:port]}")
+ end
+ end
+
+ describe 'when an ip is set' do
+ let :params do default_params.merge({ :ip => '10.0.0.1' }) end
+ it 'should specify a NameVirtualHost for the ip' do
+ should_not contain_apache__listen(params[:port])
+ should contain_apache__listen("10.0.0.1:#{params[:port]}")
+ should contain_apache__namevirtualhost("10.0.0.1:#{params[:port]}")
+ end
+ end
+
+ describe 'an ip_based vhost without a port' do
+ let :params do
+ {
+ :docroot => '/fake',
+ :ip => '10.0.0.1',
+ :ip_based => true,
+ }
+ end
+ it 'should specify a NameVirtualHost for the ip' do
+ should_not contain_apache__listen(params[:ip])
+ should_not contain_apache__namevirtualhost(params[:ip])
+ should contain_file("25-#{title}.conf").with_content %r{<VirtualHost 10\.0\.0\.1>}
+ end
+ end
+ end
+
+ describe 'redirect rules' do
+ describe 'without lockstep arrays' do
+ let :params do
+ default_params.merge({
+ :redirect_source => [
+ '/login',
+ '/logout',
+ ],
+ :redirect_dest => [
+ 'http://10.0.0.10/login',
+ 'http://10.0.0.10/logout',
+ ],
+ :redirect_status => [
+ 'permanent',
+ '',
+ ],
+ })
+ end
+
+ it { should contain_file("25-#{title}.conf").with_content %r{ Redirect permanent /login http://10\.0\.0\.10/login} }
+ it { should contain_file("25-#{title}.conf").with_content %r{ Redirect /logout http://10\.0\.0\.10/logout} }
+ end
+ describe 'without a status' do
+ let :params do
+ default_params.merge({
+ :redirect_source => [
+ '/login',
+ '/logout',
+ ],
+ :redirect_dest => [
+ 'http://10.0.0.10/login',
+ 'http://10.0.0.10/logout',
+ ],
+ })
+ end
+
+ it { should contain_file("25-#{title}.conf").with_content %r{ Redirect /login http://10\.0\.0\.10/login} }
+ it { should contain_file("25-#{title}.conf").with_content %r{ Redirect /logout http://10\.0\.0\.10/logout} }
+ end
+ describe 'with a single status and dest' do
+ let :params do
+ default_params.merge({
+ :redirect_source => [
+ '/login',
+ '/logout',
+ ],
+ :redirect_dest => 'http://10.0.0.10/test',
+ :redirect_status => 'permanent',
+ })
+ end
+
+ it { should contain_file("25-#{title}.conf").with_content %r{ Redirect permanent /login http://10\.0\.0\.10/test} }
+ it { should contain_file("25-#{title}.conf").with_content %r{ Redirect permanent /logout http://10\.0\.0\.10/test} }
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/fixtures/modules/site_apache/templates/fake.conf.erb b/puppet/modules/apache/spec/fixtures/modules/site_apache/templates/fake.conf.erb
new file mode 100644
index 0000000..019debf
--- /dev/null
+++ b/puppet/modules/apache/spec/fixtures/modules/site_apache/templates/fake.conf.erb
@@ -0,0 +1 @@
+Fake template for rspec.
diff --git a/puppet/modules/apache/spec/spec.opts b/puppet/modules/apache/spec/spec.opts
new file mode 100644
index 0000000..de653df
--- /dev/null
+++ b/puppet/modules/apache/spec/spec.opts
@@ -0,0 +1,4 @@
+--format s
+--colour
+--loadby mtime
+--backtrace
diff --git a/puppet/modules/apache/spec/spec_helper.rb b/puppet/modules/apache/spec/spec_helper.rb
new file mode 100644
index 0000000..2c6f566
--- /dev/null
+++ b/puppet/modules/apache/spec/spec_helper.rb
@@ -0,0 +1 @@
+require 'puppetlabs_spec_helper/module_spec_helper'
diff --git a/puppet/modules/apache/spec/spec_helper_system.rb b/puppet/modules/apache/spec/spec_helper_system.rb
new file mode 100644
index 0000000..55d5114
--- /dev/null
+++ b/puppet/modules/apache/spec/spec_helper_system.rb
@@ -0,0 +1,28 @@
+require 'rspec-system/spec_helper'
+require 'rspec-system-puppet/helpers'
+require 'rspec-system-serverspec/helpers'
+include Serverspec::Helper::RSpecSystem
+include Serverspec::Helper::DetectOS
+include RSpecSystemPuppet::Helpers
+
+RSpec.configure do |c|
+ # Project root
+ proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+ # Enable colour
+ c.tty = true
+
+ c.include RSpecSystemPuppet::Helpers
+
+ # This is where we 'setup' the nodes before running our tests
+ c.before :suite do
+ # Install puppet
+ puppet_install
+
+ # Install modules and dependencies
+ puppet_module_install(:source => proj_root, :module_name => 'apache')
+ shell('puppet module install puppetlabs-concat --version 1.0.0')
+ shell('puppet module install puppetlabs-stdlib --version 2.4.0')
+ end
+end
+
diff --git a/puppet/modules/apache/spec/system/basic_spec.rb b/puppet/modules/apache/spec/system/basic_spec.rb
new file mode 100644
index 0000000..a87f908
--- /dev/null
+++ b/puppet/modules/apache/spec/system/basic_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper_system'
+
+describe 'basic tests:' do
+ # Using puppet_apply as a subject
+ context puppet_apply 'notice("foo")' do
+ its(:stdout) { should =~ /foo/ }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+end
+
+describe 'disable selinux:' do
+ context puppet_apply '
+ exec { "setenforce 0":
+ path => "/bin:/sbin:/usr/bin:/usr/sbin",
+ onlyif => "which setenforce && getenforce | grep Enforcing",
+ }
+ ' do
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should_not == 1 }
+ end
+end
diff --git a/puppet/modules/apache/spec/system/class_spec.rb b/puppet/modules/apache/spec/system/class_spec.rb
new file mode 100644
index 0000000..4413316
--- /dev/null
+++ b/puppet/modules/apache/spec/system/class_spec.rb
@@ -0,0 +1,62 @@
+require 'spec_helper_system'
+
+describe 'apache class' do
+ case node.facts['osfamily']
+ when 'RedHat'
+ package_name = 'httpd'
+ service_name = 'httpd'
+ when 'Debian'
+ package_name = 'apache2'
+ service_name = 'apache2'
+ end
+
+ context 'default parameters' do
+ # Using puppet_apply as a helper
+ it 'should work with no errors' do
+ pp = <<-EOS
+ class { 'apache': }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ r.refresh
+ r.exit_code.should be_zero
+ end
+ end
+
+ describe package(package_name) do
+ it { should be_installed }
+ end
+
+ describe service(service_name) do
+ it { should be_enabled }
+ it { should be_running }
+ end
+ end
+
+ context 'custom site/mod dir parameters' do
+ # Using puppet_apply as a helper
+ it 'should work with no errors' do
+ pp = <<-EOS
+ file { '/apache': ensure => directory, }
+ class { 'apache':
+ mod_dir => '/apache/mods',
+ vhost_dir => '/apache/vhosts',
+ }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ r.refresh
+ r.exit_code.should be_zero
+ end
+ end
+
+ describe service(service_name) do
+ it { should be_enabled }
+ it { should be_running }
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/system/default_mods_spec.rb b/puppet/modules/apache/spec/system/default_mods_spec.rb
new file mode 100644
index 0000000..dbb2338
--- /dev/null
+++ b/puppet/modules/apache/spec/system/default_mods_spec.rb
@@ -0,0 +1,102 @@
+require 'spec_helper_system'
+
+case node.facts['osfamily']
+when 'RedHat'
+ servicename = 'httpd'
+when 'Debian'
+ servicename = 'apache2'
+else
+ raise Error, "Unconfigured OS for apache service on #{node.facts['osfamily']}"
+end
+
+describe 'apache::default_mods class' do
+ describe 'no default mods' do
+ # Using puppet_apply as a helper
+ it 'should apply with no errors' do
+ pp = <<-EOS
+ class { 'apache':
+ default_mods => false,
+ }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ [0,2].should include(r.exit_code)
+ r.refresh
+ r.exit_code.should be_zero
+ end
+ end
+
+ describe service(servicename) do
+ it { should be_running }
+ end
+ end
+
+ describe 'no default mods and failing' do
+ # Using puppet_apply as a helper
+ it 'should apply with errors' do
+ pp = <<-EOS
+ class { 'apache':
+ default_mods => false,
+ }
+ apache::vhost { 'defaults.example.com':
+ docroot => '/var/www/defaults',
+ aliases => {
+ alias => '/css',
+ path => '/var/www/css',
+ },
+ setenv => 'TEST1 one',
+ }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ [4,6].should include(r.exit_code)
+ end
+ end
+
+ describe "service #{servicename}" do
+ it 'should not be running' do
+ shell("pidof #{servicename}") do |r|
+ r.exit_code.should eq(1)
+ end
+ end
+ end
+ end
+
+ describe 'alternative default mods' do
+ # Using puppet_apply as a helper
+ it 'should apply with no errors' do
+ pp = <<-EOS
+ class { 'apache':
+ default_mods => [
+ 'info',
+ 'alias',
+ 'mime',
+ 'env',
+ 'expires',
+ ],
+ }
+ apache::vhost { 'defaults.example.com':
+ docroot => '/var/www/defaults',
+ aliases => {
+ alias => '/css',
+ path => '/var/www/css',
+ },
+ setenv => 'TEST1 one',
+ }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ [0,2].should include(r.exit_code)
+ r.refresh
+ r.exit_code.should be_zero
+ end
+ end
+
+ describe service(servicename) do
+ it { should be_running }
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/system/itk_spec.rb b/puppet/modules/apache/spec/system/itk_spec.rb
new file mode 100644
index 0000000..fdbabb9
--- /dev/null
+++ b/puppet/modules/apache/spec/system/itk_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper_system'
+
+case node.facts['osfamily']
+when 'Debian'
+ service_name = 'apache2'
+else
+ # Not implemented yet
+ service_name = :skip
+end
+
+unless service_name.equal? :skip
+ describe 'apache::mod::itk class' do
+ describe 'running puppet code' do
+ # Using puppet_apply as a helper
+ it 'should work with no errors' do
+ pp = <<-EOS
+ class { 'apache':
+ mpm_module => 'itk',
+ }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ r.refresh
+ r.exit_code.should be_zero
+ end
+ end
+ end
+
+ describe service(service_name) do
+ it { should be_running }
+ it { should be_enabled }
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/system/mod_php_spec.rb b/puppet/modules/apache/spec/system/mod_php_spec.rb
new file mode 100644
index 0000000..71a806b
--- /dev/null
+++ b/puppet/modules/apache/spec/system/mod_php_spec.rb
@@ -0,0 +1,48 @@
+require 'spec_helper_system'
+
+describe 'apache::mod::php class' do
+ case node.facts['osfamily']
+ when 'Debian'
+ mod_dir = '/etc/apache2/mods-available'
+ service_name = 'apache2'
+ when 'RedHat'
+ mod_dir = '/etc/httpd/conf.d'
+ service_name = 'httpd'
+ end
+
+ context "default php config" do
+ it 'succeeds in puppeting php' do
+ puppet_apply(%{
+ class { 'apache':
+ mpm_module => 'prefork',
+ }
+ class { 'apache::mod::php': }
+ apache::vhost { 'php.example.com':
+ port => '80',
+ docroot => '/var/www/php',
+ }
+ host { 'php.example.com': ip => '127.0.0.1', }
+ file { '/var/www/php/index.php':
+ ensure => file,
+ content => "<?php phpinfo(); ?>\\n",
+ }
+ }) { |r| [0,2].should include r.exit_code}
+ end
+
+ describe service(service_name) do
+ it { should be_enabled }
+ it { should be_running }
+ end
+
+ describe file("#{mod_dir}/php5.conf") do
+ it { should contain "DirectoryIndex index.php" }
+ end
+
+ it 'should answer to php.example.com' do
+ shell("/usr/bin/curl php.example.com:80") do |r|
+ r.stdout.should =~ /PHP Version/
+ r.exit_code.should == 0
+ end
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/system/mod_suphp_spec.rb b/puppet/modules/apache/spec/system/mod_suphp_spec.rb
new file mode 100644
index 0000000..297b2d5
--- /dev/null
+++ b/puppet/modules/apache/spec/system/mod_suphp_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper_system'
+
+describe 'apache::mod::suphp class' do
+ case node.facts['osfamily']
+ when 'Debian'
+ context "default suphp config" do
+ it 'succeeds in puppeting suphp' do
+ puppet_apply(%{
+ class { 'apache':
+ mpm_module => 'prefork',
+ }
+ class { 'apache::mod::php': }
+ class { 'apache::mod::suphp': }
+ apache::vhost { 'suphp.example.com':
+ port => '80',
+ docroot => '/var/www/suphp',
+ }
+ host { 'suphp.example.com': ip => '127.0.0.1', }
+ file { '/var/www/suphp/index.php':
+ ensure => file,
+ owner => 'puppet',
+ group => 'puppet',
+ content => "<?php echo get_current_user(); ?>\\n",
+ }
+ }) { |r| [0,2].should include r.exit_code}
+ end
+
+ describe service('apache2') do
+ it { should be_enabled }
+ it { should be_running }
+ end
+
+ it 'should answer to suphp.example.com' do
+ shell("/usr/bin/curl suphp.example.com:80") do |r|
+ r.stdout.should =~ /^puppet$/
+ r.exit_code.should == 0
+ end
+ end
+ end
+ when 'RedHat'
+ # Not implemented yet
+ end
+end
diff --git a/puppet/modules/apache/spec/system/prefork_worker_spec.rb b/puppet/modules/apache/spec/system/prefork_worker_spec.rb
new file mode 100644
index 0000000..ae7eae9
--- /dev/null
+++ b/puppet/modules/apache/spec/system/prefork_worker_spec.rb
@@ -0,0 +1,60 @@
+require 'spec_helper_system'
+
+case node.facts['osfamily']
+when 'RedHat'
+ servicename = 'httpd'
+when 'Debian'
+ servicename = 'apache2'
+else
+ raise Error, "Unconfigured OS for apache service on #{node.facts['osfamily']}"
+end
+
+describe 'apache::mod::worker class' do
+ describe 'running puppet code' do
+ # Using puppet_apply as a helper
+ it 'should work with no errors' do
+ pp = <<-EOS
+ class { 'apache':
+ mpm_module => 'worker',
+ }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ r.refresh
+ r.exit_code.should be_zero
+ end
+ end
+ end
+
+ describe service(servicename) do
+ it { should be_running }
+ it { should be_enabled }
+ end
+end
+
+describe 'apache::mod::prefork class' do
+ describe 'running puppet code' do
+ # Using puppet_apply as a helper
+ it 'should work with no errors' do
+ pp = <<-EOS
+ class { 'apache':
+ mpm_module => 'prefork',
+ }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ r.refresh
+ r.exit_code.should be_zero
+ end
+ end
+ end
+
+ describe service(servicename) do
+ it { should be_running }
+ it { should be_enabled }
+ end
+end
diff --git a/puppet/modules/apache/spec/system/service_spec.rb b/puppet/modules/apache/spec/system/service_spec.rb
new file mode 100644
index 0000000..5f76600
--- /dev/null
+++ b/puppet/modules/apache/spec/system/service_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper_system'
+
+describe 'apache::service class' do
+ describe 'adding dependencies in between the base class and service class' do
+ it 'should work with no errors' do
+ pp = <<-EOS
+ class { 'apache': }
+ file { '/tmp/test':
+ require => Class['apache'],
+ notify => Class['apache::service'],
+ }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ [0,2].should include(r.exit_code)
+ r.refresh
+ r.exit_code.should be_zero
+ end
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/system/vhost_spec.rb b/puppet/modules/apache/spec/system/vhost_spec.rb
new file mode 100644
index 0000000..3c8002e
--- /dev/null
+++ b/puppet/modules/apache/spec/system/vhost_spec.rb
@@ -0,0 +1,183 @@
+require 'spec_helper_system'
+
+describe 'apache::vhost define' do
+ case node.facts['osfamily']
+ when 'RedHat'
+ vhost_dir = '/etc/httpd/conf.d'
+ package_name = 'httpd'
+ service_name = 'httpd'
+ when 'Debian'
+ vhost_dir = '/etc/apache2/sites-enabled'
+ package_name = 'apache2'
+ service_name = 'apache2'
+ end
+
+ context "default vhost without ssl" do
+ it 'should create a default vhost config' do
+ puppet_apply(%{
+ class { 'apache': }
+ }) { |r| [0,2].should include r.exit_code}
+ end
+
+ describe file("#{vhost_dir}/15-default.conf") do
+ it { should contain '<VirtualHost \*:80>' }
+ end
+
+ describe file("#{vhost_dir}/15-default-ssl.conf") do
+ it { should_not be_file }
+ end
+ end
+
+ context 'default vhost with ssl' do
+ it 'should create default vhost configs' do
+ puppet_apply(%{
+ class { 'apache':
+ default_ssl_vhost => true,
+ }
+ }) { |r| [0,2].should include r.exit_code}
+ end
+
+ describe file("#{vhost_dir}/15-default.conf") do
+ it { should contain '<VirtualHost \*:80>' }
+ end
+
+ describe file("#{vhost_dir}/15-default-ssl.conf") do
+ it { should contain '<VirtualHost \*:443>' }
+ it { should contain "SSLEngine on" }
+ end
+ end
+
+ context 'new vhost on port 80' do
+ it 'should configure an apache vhost' do
+ puppet_apply(%{
+ class { 'apache': }
+ apache::vhost { 'first.example.com':
+ port => '80',
+ docroot => '/var/www/first',
+ }
+ }) { |r| [0,2].should include r.exit_code}
+ end
+
+ describe file("#{vhost_dir}/25-first.example.com.conf") do
+ it { should contain '<VirtualHost \*:80>' }
+ it { should contain "ServerName first.example.com" }
+ end
+ end
+
+ context 'new vhost on port 80' do
+ it 'should configure two apache vhosts' do
+ puppet_apply(%{
+ class { 'apache': }
+ apache::vhost { 'first.example.com':
+ port => '80',
+ docroot => '/var/www/first',
+ }
+ host { 'first.example.com': ip => '127.0.0.1', }
+ file { '/var/www/first/index.html':
+ ensure => file,
+ content => "Hello from first\\n",
+ }
+ apache::vhost { 'second.example.com':
+ port => '80',
+ docroot => '/var/www/second',
+ }
+ host { 'second.example.com': ip => '127.0.0.1', }
+ file { '/var/www/second/index.html':
+ ensure => file,
+ content => "Hello from second\\n",
+ }
+ }) { |r| [0,2].should include r.exit_code}
+ end
+
+ describe service(service_name) do
+ it { should be_enabled }
+ it { should be_running }
+ end
+
+ it 'should answer to first.example.com' do
+ shell("/usr/bin/curl first.example.com:80") do |r|
+ r.stdout.should == "Hello from first\n"
+ r.exit_code.should == 0
+ end
+ end
+
+ it 'should answer to second.example.com' do
+ shell("/usr/bin/curl second.example.com:80") do |r|
+ r.stdout.should == "Hello from second\n"
+ r.exit_code.should == 0
+ end
+ end
+ end
+
+ context 'apache_directories readme example, adapted' do
+ it 'should configure a vhost with Files' do
+ puppet_apply(%{
+ class { 'apache': }
+ apache::vhost { 'files.example.net':
+ docroot => '/var/www/files',
+ directories => [
+ { path => '~ (\.swp|\.bak|~)$', 'provider' => 'files', 'deny' => 'from all' },
+ ],
+ }
+ file { '/var/www/files/index.html.bak':
+ ensure => file,
+ content => "Hello World\\n",
+ }
+ host { 'files.example.net': ip => '127.0.0.1', }
+ }) { |r| [0,2].should include r.exit_code}
+ end
+
+ describe service(service_name) do
+ it { should be_enabled }
+ it { should be_running }
+ end
+
+ it 'should answer to files.example.net' do
+ shell("/usr/bin/curl -sSf files.example.net:80/index.html.bak") do |r|
+ r.stderr.should =~ /curl: \(22\) The requested URL returned error: 403/
+ r.exit_code.should == 22
+ end
+ end
+
+ end
+
+ context 'virtual_docroot hosting separate sites' do
+ it 'should configure a vhost with VirtualDocumentRoot' do
+ puppet_apply(%{
+ class { 'apache': }
+ apache::vhost { 'virt.example.com':
+ vhost_name => '*',
+ serveraliases => '*virt.example.com',
+ port => '80',
+ docroot => '/var/www/virt',
+ virtual_docroot => '/var/www/virt/%1',
+ }
+ host { 'virt.example.com': ip => '127.0.0.1', }
+ host { 'a.virt.example.com': ip => '127.0.0.1', }
+ host { 'b.virt.example.com': ip => '127.0.0.1', }
+ file { [ '/var/www/virt/a', '/var/www/virt/b', ]: ensure => directory, }
+ file { '/var/www/virt/a/index.html': ensure => file, content => "Hello from a.virt\\n", }
+ file { '/var/www/virt/b/index.html': ensure => file, content => "Hello from b.virt\\n", }
+ }) { |r| [0,2].should include r.exit_code}
+ end
+
+ describe service(service_name) do
+ it { should be_enabled }
+ it { should be_running }
+ end
+
+ it 'should answer to a.virt.example.com' do
+ shell("/usr/bin/curl a.virt.example.com:80") do |r|
+ r.stdout.should == "Hello from a.virt\n"
+ r.exit_code.should == 0
+ end
+ end
+
+ it 'should answer to b.virt.example.com' do
+ shell("/usr/bin/curl b.virt.example.com:80") do |r|
+ r.stdout.should == "Hello from b.virt\n"
+ r.exit_code.should == 0
+ end
+ end
+ end
+end
diff --git a/puppet/modules/apache/spec/unit/provider/a2mod/gentoo_spec.rb b/puppet/modules/apache/spec/unit/provider/a2mod/gentoo_spec.rb
new file mode 100644
index 0000000..ddb9ddd
--- /dev/null
+++ b/puppet/modules/apache/spec/unit/provider/a2mod/gentoo_spec.rb
@@ -0,0 +1,184 @@
+#!/usr/bin/env rspec
+
+require 'spec_helper'
+
+provider_class = Puppet::Type.type(:a2mod).provider(:gentoo)
+
+describe provider_class do
+ before :each do
+ provider_class.clear
+ end
+
+ [:conf_file, :instances, :modules, :initvars, :conf_file, :clear].each do |method|
+ it "should respond to the class method #{method}" do
+ provider_class.should respond_to(method)
+ end
+ end
+
+ describe "when fetching modules" do
+ before do
+ @filetype = mock()
+ end
+
+ it "should return a sorted array of the defined parameters" do
+ @filetype.expects(:read).returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n})
+ provider_class.expects(:filetype).returns(@filetype)
+
+ provider_class.modules.should == %w{bar baz foo}
+ end
+
+ it "should cache the module list" do
+ @filetype.expects(:read).once.returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n})
+ provider_class.expects(:filetype).once.returns(@filetype)
+
+ 2.times { provider_class.modules.should == %w{bar baz foo} }
+ end
+
+ it "should normalize parameters" do
+ @filetype.expects(:read).returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAR"\n})
+ provider_class.expects(:filetype).returns(@filetype)
+
+ provider_class.modules.should == %w{bar foo}
+ end
+ end
+
+ describe "when prefetching" do
+ it "should match providers to resources" do
+ provider = mock("ssl_provider", :name => "ssl")
+ resource = mock("ssl_resource")
+ resource.expects(:provider=).with(provider)
+
+ provider_class.expects(:instances).returns([provider])
+ provider_class.prefetch("ssl" => resource)
+ end
+ end
+
+ describe "when flushing" do
+ before :each do
+ @filetype = mock()
+ @filetype.stubs(:backup)
+ provider_class.expects(:filetype).at_least_once.returns(@filetype)
+
+ @info = mock()
+ @info.stubs(:[]).with(:name).returns("info")
+ @info.stubs(:provider=)
+
+ @mpm = mock()
+ @mpm.stubs(:[]).with(:name).returns("mpm")
+ @mpm.stubs(:provider=)
+
+ @ssl = mock()
+ @ssl.stubs(:[]).with(:name).returns("ssl")
+ @ssl.stubs(:provider=)
+ end
+
+ it "should add modules whose ensure is present" do
+ @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
+ @filetype.expects(:write).with(%Q{APACHE2_OPTS="-D INFO"})
+
+ @info.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("info" => @info)
+
+ provider_class.flush
+ end
+
+ it "should remove modules whose ensure is present" do
+ @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-D INFO"})
+ @filetype.expects(:write).with(%Q{APACHE2_OPTS=""})
+
+ @info.stubs(:should).with(:ensure).returns(:absent)
+ @info.stubs(:provider=)
+ provider_class.prefetch("info" => @info)
+
+ provider_class.flush
+ end
+
+ it "should not modify providers without resources" do
+ @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-D INFO -D MPM"})
+ @filetype.expects(:write).with(%Q{APACHE2_OPTS="-D MPM -D SSL"})
+
+ @info.stubs(:should).with(:ensure).returns(:absent)
+ provider_class.prefetch("info" => @info)
+
+ @ssl.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("ssl" => @ssl)
+
+ provider_class.flush
+ end
+
+ it "should write the modules in sorted order" do
+ @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
+ @filetype.expects(:write).with(%Q{APACHE2_OPTS="-D INFO -D MPM -D SSL"})
+
+ @mpm.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("mpm" => @mpm)
+ @info.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("info" => @info)
+ @ssl.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("ssl" => @ssl)
+
+ provider_class.flush
+ end
+
+ it "should write the records back once" do
+ @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
+ @filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-D INFO -D SSL"})
+
+ @info.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("info" => @info)
+
+ @ssl.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("ssl" => @ssl)
+
+ provider_class.flush
+ end
+
+ it "should only modify the line containing APACHE2_OPTS" do
+ @filetype.expects(:read).at_least_once.returns(%Q{# Comment\nAPACHE2_OPTS=""\n# Another comment})
+ @filetype.expects(:write).once.with(%Q{# Comment\nAPACHE2_OPTS="-D INFO"\n# Another comment})
+
+ @info.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("info" => @info)
+ provider_class.flush
+ end
+
+ it "should restore any arbitrary arguments" do
+ @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-Y -D MPM -X"})
+ @filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-Y -X -D INFO -D MPM"})
+
+ @info.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("info" => @info)
+ provider_class.flush
+ end
+
+ it "should backup the file once if changes were made" do
+ @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""})
+ @filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-D INFO -D SSL"})
+
+ @info.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("info" => @info)
+
+ @ssl.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("ssl" => @ssl)
+
+ @filetype.unstub(:backup)
+ @filetype.expects(:backup)
+ provider_class.flush
+ end
+
+ it "should not write the file or run backups if no changes were made" do
+ @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-X -D INFO -D SSL -Y"})
+ @filetype.expects(:write).never
+
+ @info.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("info" => @info)
+
+ @ssl.stubs(:should).with(:ensure).returns(:present)
+ provider_class.prefetch("ssl" => @ssl)
+
+ @filetype.unstub(:backup)
+ @filetype.expects(:backup).never
+ provider_class.flush
+ end
+ end
+end
diff --git a/puppet/modules/apache/templates/httpd.conf.erb b/puppet/modules/apache/templates/httpd.conf.erb
new file mode 100644
index 0000000..2bfb273
--- /dev/null
+++ b/puppet/modules/apache/templates/httpd.conf.erb
@@ -0,0 +1,86 @@
+# Security
+ServerTokens OS
+ServerSignature On
+TraceEnable Off
+
+ServerName "<%= @servername %>"
+ServerRoot "<%= @httpd_dir %>"
+PidFile <%= @pidfile %>
+Timeout 120
+KeepAlive <%= @keepalive %>
+MaxKeepAliveRequests 100
+KeepAliveTimeout <%= @keepalive_timeout %>
+
+User <%= @user %>
+Group <%= @group %>
+
+AccessFileName .htaccess
+<Files ~ "^\.ht">
+ Order allow,deny
+ Deny from all
+ Satisfy all
+</Files>
+
+<Directory />
+ Options FollowSymLinks
+ AllowOverride None
+</Directory>
+
+DefaultType none
+HostnameLookups Off
+ErrorLog <%= @logroot %>/<%= @error_log %>
+LogLevel warn
+<% if @sendfile %>
+EnableSendfile <%= @sendfile %>
+<% end %>
+
+#Listen 80
+Include <%= @mod_load_dir %>/*.load
+<% if @mod_load_dir != @confd_dir and @mod_load_dir != @vhost_load_dir -%>
+Include <%= @mod_load_dir %>/*.conf
+<% end -%>
+Include <%= @ports_file %>
+
+LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
+LogFormat "%h %l %u %t \"%r\" %>s %b" common
+LogFormat "%{Referer}i -> %U" referer
+LogFormat "%{User-agent}i" agent
+
+Include <%= @confd_dir %>/*.conf
+<% if @vhost_load_dir != @confd_dir -%>
+Include <%= @vhost_load_dir %>/*.conf
+<% end -%>
+
+<% if @error_documents -%>
+# /usr/share/apache2/error on debian
+Alias /error/ "<%= @error_documents_path %>/"
+
+<Directory "<%= @error_documents_path %>">
+ AllowOverride None
+ Options IncludesNoExec
+ AddOutputFilter Includes html
+ AddHandler type-map var
+ Order allow,deny
+ Allow from all
+ LanguagePriority en cs de es fr it nl sv pt-br ro
+ ForceLanguagePriority Prefer Fallback
+</Directory>
+
+ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
+ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
+ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
+ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
+ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
+ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
+ErrorDocument 410 /error/HTTP_GONE.html.var
+ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
+ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
+ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
+ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
+ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
+ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
+ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
+ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
+ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
+ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
+<% end -%>
diff --git a/puppet/modules/apache/templates/listen.erb b/puppet/modules/apache/templates/listen.erb
new file mode 100644
index 0000000..8fc871b
--- /dev/null
+++ b/puppet/modules/apache/templates/listen.erb
@@ -0,0 +1,6 @@
+<%# Listen should always be one of:
+ - <port>
+ - <ipv4>:<port>
+ - [<ipv6]:<port>
+-%>
+Listen <%= @listen_addr_port %>
diff --git a/puppet/modules/apache/templates/mod/alias.conf.erb b/puppet/modules/apache/templates/mod/alias.conf.erb
new file mode 100644
index 0000000..9e8b0de
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/alias.conf.erb
@@ -0,0 +1,7 @@
+Alias /icons/ "<%= @icons_path %>/"
+<Directory "<%= @icons_path %>">
+ Options Indexes MultiViews
+ AllowOverride None
+ Order allow,deny
+ Allow from all
+</Directory>
diff --git a/puppet/modules/apache/templates/mod/autoindex.conf.erb b/puppet/modules/apache/templates/mod/autoindex.conf.erb
new file mode 100644
index 0000000..ef6bbeb
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/autoindex.conf.erb
@@ -0,0 +1,56 @@
+IndexOptions FancyIndexing VersionSort HTMLTable NameWidth=* DescriptionWidth=* Charset=UTF-8
+AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip x-bzip2
+
+AddIconByType (TXT,/icons/text.gif) text/*
+AddIconByType (IMG,/icons/image2.gif) image/*
+AddIconByType (SND,/icons/sound2.gif) audio/*
+AddIconByType (VID,/icons/movie.gif) video/*
+
+AddIcon /icons/binary.gif .bin .exe
+AddIcon /icons/binhex.gif .hqx
+AddIcon /icons/tar.gif .tar
+AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
+AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
+AddIcon /icons/a.gif .ps .ai .eps
+AddIcon /icons/layout.gif .html .shtml .htm .pdf
+AddIcon /icons/text.gif .txt
+AddIcon /icons/c.gif .c
+AddIcon /icons/p.gif .pl .py
+AddIcon /icons/f.gif .for
+AddIcon /icons/dvi.gif .dvi
+AddIcon /icons/uuencoded.gif .uu
+AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
+AddIcon /icons/tex.gif .tex
+AddIcon /icons/bomb.gif /core
+AddIcon (SND,/icons/sound2.gif) .ogg
+AddIcon (VID,/icons/movie.gif) .ogm
+
+AddIcon /icons/back.gif ..
+AddIcon /icons/hand.right.gif README
+AddIcon /icons/folder.gif ^^DIRECTORY^^
+AddIcon /icons/blank.gif ^^BLANKICON^^
+
+AddIcon /icons/odf6odt-20x22.png .odt
+AddIcon /icons/odf6ods-20x22.png .ods
+AddIcon /icons/odf6odp-20x22.png .odp
+AddIcon /icons/odf6odg-20x22.png .odg
+AddIcon /icons/odf6odc-20x22.png .odc
+AddIcon /icons/odf6odf-20x22.png .odf
+AddIcon /icons/odf6odb-20x22.png .odb
+AddIcon /icons/odf6odi-20x22.png .odi
+AddIcon /icons/odf6odm-20x22.png .odm
+
+AddIcon /icons/odf6ott-20x22.png .ott
+AddIcon /icons/odf6ots-20x22.png .ots
+AddIcon /icons/odf6otp-20x22.png .otp
+AddIcon /icons/odf6otg-20x22.png .otg
+AddIcon /icons/odf6otc-20x22.png .otc
+AddIcon /icons/odf6otf-20x22.png .otf
+AddIcon /icons/odf6oti-20x22.png .oti
+AddIcon /icons/odf6oth-20x22.png .oth
+
+DefaultIcon /icons/unknown.gif
+ReadmeName README.html
+HeaderName HEADER.html
+
+IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
diff --git a/puppet/modules/apache/templates/mod/cgid.conf.erb b/puppet/modules/apache/templates/mod/cgid.conf.erb
new file mode 100644
index 0000000..d771012
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/cgid.conf.erb
@@ -0,0 +1 @@
+ScriptSock <%= @cgisock_path %>
diff --git a/puppet/modules/apache/templates/mod/dav_fs.conf.erb b/puppet/modules/apache/templates/mod/dav_fs.conf.erb
new file mode 100644
index 0000000..50edf00
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/dav_fs.conf.erb
@@ -0,0 +1 @@
+DAVLockDB <%= @dav_lock %>
diff --git a/puppet/modules/apache/templates/mod/deflate.conf.erb b/puppet/modules/apache/templates/mod/deflate.conf.erb
new file mode 100644
index 0000000..d0997df
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/deflate.conf.erb
@@ -0,0 +1,4 @@
+AddOutputFilterByType DEFLATE text/html text/plain text/xml
+AddOutputFilterByType DEFLATE text/css
+AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
+AddOutputFilterByType DEFLATE application/rss+xml
diff --git a/puppet/modules/apache/templates/mod/dir.conf.erb b/puppet/modules/apache/templates/mod/dir.conf.erb
new file mode 100644
index 0000000..741f6ae
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/dir.conf.erb
@@ -0,0 +1 @@
+DirectoryIndex <%= @indexes.join(' ') %>
diff --git a/puppet/modules/apache/templates/mod/disk_cache.conf.erb b/puppet/modules/apache/templates/mod/disk_cache.conf.erb
new file mode 100644
index 0000000..0c7e2c4
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/disk_cache.conf.erb
@@ -0,0 +1,8 @@
+<IfModule mod_proxy.c>
+ <IfModule mod_disk_cache.c>
+ CacheEnable disk /
+ CacheRoot "<%= @cache_root %>"
+ CacheDirLevels 2
+ CacheDirLength 1
+ </IfModule>
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/info.conf.erb b/puppet/modules/apache/templates/mod/info.conf.erb
new file mode 100644
index 0000000..01ffe95
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/info.conf.erb
@@ -0,0 +1,6 @@
+<Location /server-info>
+ SetHandler server-info
+ Order deny,allow
+ Deny from all
+ Allow from <%= Array(@allow_from).join(" ") %>
+</Location>
diff --git a/puppet/modules/apache/templates/mod/itk.conf.erb b/puppet/modules/apache/templates/mod/itk.conf.erb
new file mode 100644
index 0000000..f45f2b3
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/itk.conf.erb
@@ -0,0 +1,8 @@
+<IfModule mpm_itk_module>
+ StartServers <%= @startservers %>
+ MinSpareServers <%= @minspareservers %>
+ MaxSpareServers <%= @maxspareservers %>
+ ServerLimit <%= @serverlimit %>
+ MaxClients <%= @maxclients %>
+ MaxRequestsPerChild <%= @maxrequestsperchild %>
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/ldap.conf.erb b/puppet/modules/apache/templates/mod/ldap.conf.erb
new file mode 100644
index 0000000..14f33ab
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/ldap.conf.erb
@@ -0,0 +1,7 @@
+<Location /ldap-status>
+ SetHandler ldap-status
+ Order deny,allow
+ Deny from all
+ Allow from 127.0.0.1 ::1
+ Satisfy all
+</Location>
diff --git a/puppet/modules/apache/templates/mod/mime.conf.erb b/puppet/modules/apache/templates/mod/mime.conf.erb
new file mode 100644
index 0000000..34f4add
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/mime.conf.erb
@@ -0,0 +1,36 @@
+TypesConfig /etc/mime.types
+
+AddType application/x-compress .Z
+AddType application/x-gzip .gz .tgz
+AddType application/x-bzip2 .bz2
+
+AddLanguage ca .ca
+AddLanguage cs .cz .cs
+AddLanguage da .dk
+AddLanguage de .de
+AddLanguage el .el
+AddLanguage en .en
+AddLanguage eo .eo
+AddLanguage es .es
+AddLanguage et .et
+AddLanguage fr .fr
+AddLanguage he .he
+AddLanguage hr .hr
+AddLanguage it .it
+AddLanguage ja .ja
+AddLanguage ko .ko
+AddLanguage ltz .ltz
+AddLanguage nl .nl
+AddLanguage nn .nn
+AddLanguage no .no
+AddLanguage pl .po
+AddLanguage pt .pt
+AddLanguage pt-BR .pt-br
+AddLanguage ru .ru
+AddLanguage sv .sv
+AddLanguage zh-CN .zh-cn
+AddLanguage zh-TW .zh-tw
+
+AddHandler type-map var
+AddType text/html .shtml
+AddOutputFilter INCLUDES .shtml
diff --git a/puppet/modules/apache/templates/mod/mime_magic.conf.erb b/puppet/modules/apache/templates/mod/mime_magic.conf.erb
new file mode 100644
index 0000000..ee69bca
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/mime_magic.conf.erb
@@ -0,0 +1 @@
+MIMEMagicFile conf/magic
diff --git a/puppet/modules/apache/templates/mod/mpm_event.conf.erb b/puppet/modules/apache/templates/mod/mpm_event.conf.erb
new file mode 100644
index 0000000..eb6f1ff
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/mpm_event.conf.erb
@@ -0,0 +1,9 @@
+<IfModule mpm_event_module>
+ StartServers 2
+ MinSpareThreads 25
+ MaxSpareThreads 75
+ ThreadLimit 64
+ ThreadsPerChild 25
+ MaxClients 150
+ MaxRequestsPerChild 0
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/negotiation.conf.erb b/puppet/modules/apache/templates/mod/negotiation.conf.erb
new file mode 100644
index 0000000..5092101
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/negotiation.conf.erb
@@ -0,0 +1,2 @@
+LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
+ForceLanguagePriority Prefer Fallback
diff --git a/puppet/modules/apache/templates/mod/passenger.conf.erb b/puppet/modules/apache/templates/mod/passenger.conf.erb
new file mode 100644
index 0000000..0be2c99
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/passenger.conf.erb
@@ -0,0 +1,27 @@
+# The Passanger Apache module configuration file is being
+# managed by Puppet and changes will be overwritten.
+<IfModule mod_passenger.c>
+ PassengerRoot <%= @passenger_root %>
+ PassengerRuby <%= @passenger_ruby %>
+ <%- if @passenger_high_performance -%>
+ PassengerHighPerformance <%= @passenger_high_performance %>
+ <%- end -%>
+ <%- if @passenger_max_pool_size -%>
+ PassengerMaxPoolSize <%= @passenger_max_pool_size %>
+ <%- end -%>
+ <%- if @passenger_pool_idle_time -%>
+ PassengerPoolIdleTime <%= @passenger_pool_idle_time %>
+ <%- end -%>
+ <%- if @passenger_max_requests -%>
+ PassengerMaxRequests <%= @passenger_max_requests %>
+ <%- end -%>
+ <%- if @passenger_stat_throttle_rate -%>
+ PassengerStatThrottleRate <%= @passenger_stat_throttle_rate %>
+ <%- end -%>
+ <%- if @rack_autodetect -%>
+ RackAutoDetect <%= @rack_autodetect %>
+ <%- end -%>
+ <%- if @rails_autodetect -%>
+ RailsAutoDetect <%= @rails_autodetect %>
+ <%- end -%>
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/php5.conf.erb b/puppet/modules/apache/templates/mod/php5.conf.erb
new file mode 100644
index 0000000..9eef762
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/php5.conf.erb
@@ -0,0 +1,30 @@
+#
+# PHP is an HTML-embedded scripting language which attempts to make it
+# easy for developers to write dynamically generated webpages.
+#
+#<IfModule prefork.c>
+# LoadModule php5_module modules/libphp5.so
+#</IfModule>
+#<IfModule worker.c>
+# # Use of the "ZTS" build with worker is experimental, and no shared
+# # modules are supported.
+# LoadModule php5_module modules/libphp5-zts.so
+#</IfModule>
+
+#
+# Cause the PHP interpreter to handle files with a .php extension.
+#
+AddHandler php5-script .php
+AddType text/html .php
+
+#
+# Add index.php to the list of files that will be served as directory
+# indexes.
+#
+DirectoryIndex index.php
+
+#
+# Uncomment the following line to allow PHP to pretty-print .phps
+# files as PHP source code:
+#
+#AddType application/x-httpd-php-source .phps
diff --git a/puppet/modules/apache/templates/mod/prefork.conf.erb b/puppet/modules/apache/templates/mod/prefork.conf.erb
new file mode 100644
index 0000000..aabfdf7
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/prefork.conf.erb
@@ -0,0 +1,8 @@
+<IfModule mpm_prefork_module>
+ StartServers <%= @startservers %>
+ MinSpareServers <%= @minspareservers %>
+ MaxSpareServers <%= @maxspareservers %>
+ ServerLimit <%= @serverlimit %>
+ MaxClients <%= @maxclients %>
+ MaxRequestsPerChild <%= @maxrequestsperchild %>
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/proxy.conf.erb b/puppet/modules/apache/templates/mod/proxy.conf.erb
new file mode 100644
index 0000000..d4531a5
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/proxy.conf.erb
@@ -0,0 +1,21 @@
+#
+# Proxy Server directives. Uncomment the following lines to
+# enable the proxy server:
+#
+<IfModule mod_proxy.c>
+ # Do not enable proxying with ProxyRequests until you have secured your
+ # server. Open proxy servers are dangerous both to your network and to the
+ # Internet at large.
+ ProxyRequests <%= @proxy_requests %>
+
+ <Proxy *>
+ Order deny,allow
+ Deny from all
+ Allow from <%= Array(@allow_from).join(" ") %>
+ </Proxy>
+
+ # Enable/disable the handling of HTTP/1.1 "Via:" headers.
+ # ("Full" adds the server version; "Block" removes all outgoing Via: headers)
+ # Set to one of: Off | On | Full | Block
+ ProxyVia On
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/proxy_html.conf.erb b/puppet/modules/apache/templates/mod/proxy_html.conf.erb
new file mode 100644
index 0000000..7f5898e
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/proxy_html.conf.erb
@@ -0,0 +1,24 @@
+<% if @proxy_html_loadfiles -%>
+<% Array(@proxy_html_loadfiles).each do |loadfile| -%>
+LoadFile <%= loadfile %>
+<% end -%>
+
+<% end -%>
+ProxyHTMLLinks a href
+ProxyHTMLLinks area href
+ProxyHTMLLinks link href
+ProxyHTMLLinks img src longdesc usemap
+ProxyHTMLLinks object classid codebase data usemap
+ProxyHTMLLinks q cite
+ProxyHTMLLinks blockquote cite
+ProxyHTMLLinks ins cite
+ProxyHTMLLinks del cite
+ProxyHTMLLinks form action
+ProxyHTMLLinks input src usemap
+ProxyHTMLLinks head profileProxyHTMLLinks base href
+ProxyHTMLLinks script src for
+
+ProxyHTMLEvents onclick ondblclick onmousedown onmouseup \
+ onmouseover onmousemove onmouseout onkeypress \
+ onkeydown onkeyup onfocus onblur onload \
+ onunload onsubmit onreset onselect onchange
diff --git a/puppet/modules/apache/templates/mod/reqtimeout.conf.erb b/puppet/modules/apache/templates/mod/reqtimeout.conf.erb
new file mode 100644
index 0000000..9a18800
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/reqtimeout.conf.erb
@@ -0,0 +1,2 @@
+RequestReadTimeout header=20-40,minrate=500
+RequestReadTimeout body=10,minrate=500
diff --git a/puppet/modules/apache/templates/mod/setenvif.conf.erb b/puppet/modules/apache/templates/mod/setenvif.conf.erb
new file mode 100644
index 0000000..d31c79f
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/setenvif.conf.erb
@@ -0,0 +1,34 @@
+#
+# The following directives modify normal HTTP response behavior to
+# handle known problems with browser implementations.
+#
+BrowserMatch "Mozilla/2" nokeepalive
+BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
+BrowserMatch "RealPlayer 4\.0" force-response-1.0
+BrowserMatch "Java/1\.0" force-response-1.0
+BrowserMatch "JDK/1\.0" force-response-1.0
+
+#
+# The following directive disables redirects on non-GET requests for
+# a directory that does not include the trailing slash. This fixes a
+# problem with Microsoft WebFolders which does not appropriately handle
+# redirects for folders with DAV methods.
+# Same deal with Apple's DAV filesystem and Gnome VFS support for DAV.
+#
+BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
+BrowserMatch "MS FrontPage" redirect-carefully
+BrowserMatch "^WebDrive" redirect-carefully
+BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
+BrowserMatch "^gnome-vfs/1.0" redirect-carefully
+BrowserMatch "^gvfs/1" redirect-carefully
+BrowserMatch "^XML Spy" redirect-carefully
+BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully
+BrowserMatch " Konqueror/4" redirect-carefully
+
+<IfModule mod_ssl.c>
+ BrowserMatch "MSIE [2-6]" \
+ nokeepalive ssl-unclean-shutdown \
+ downgrade-1.0 force-response-1.0
+ # MSIE 7 and newer should be able to use keepalive
+ BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/ssl.conf.erb b/puppet/modules/apache/templates/mod/ssl.conf.erb
new file mode 100644
index 0000000..854a0d0
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/ssl.conf.erb
@@ -0,0 +1,21 @@
+<IfModule mod_ssl.c>
+ SSLRandomSeed startup builtin
+ SSLRandomSeed startup file:/dev/urandom 512
+ SSLRandomSeed connect builtin
+ SSLRandomSeed connect file:/dev/urandom 512
+
+ AddType application/x-x509-ca-cert .crt
+ AddType application/x-pkcs7-crl .crl
+
+ SSLPassPhraseDialog builtin
+ SSLSessionCache shmcb:<%= @session_cache %>
+ SSLSessionCacheTimeout 300
+<% if @ssl_compression -%>
+ SSLCompression Off
+<% end -%>
+ SSLMutex <%= @ssl_mutex %>
+ SSLCryptoDevice builtin
+ SSLHonorCipherOrder On
+ SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
+ SSLProtocol all -SSLv2
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/status.conf.erb b/puppet/modules/apache/templates/mod/status.conf.erb
new file mode 100644
index 0000000..b29324e
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/status.conf.erb
@@ -0,0 +1,12 @@
+<Location /server-status>
+ SetHandler server-status
+ Order deny,allow
+ Deny from all
+ Allow from 127.0.0.1 ::1
+</Location>
+ExtendedStatus On
+
+<IfModule mod_proxy.c>
+ # Show Proxy LoadBalancer status in mod_status
+ ProxyStatus On
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/suphp.conf.erb b/puppet/modules/apache/templates/mod/suphp.conf.erb
new file mode 100644
index 0000000..95fbf97
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/suphp.conf.erb
@@ -0,0 +1,19 @@
+<IfModule mod_suphp.c>
+ AddType application/x-httpd-suphp .php .php3 .php4 .php5 .phtml
+ suPHP_AddHandler application/x-httpd-suphp
+
+ <Directory />
+ suPHP_Engine on
+ </Directory>
+
+ # By default, disable suPHP for debian packaged web applications as files
+ # are owned by root and cannot be executed by suPHP because of min_uid.
+ <Directory /usr/share>
+ suPHP_Engine off
+ </Directory>
+
+# # Use a specific php config file (a dir which contains a php.ini file)
+# suPHP_ConfigPath /etc/php4/cgi/suphp/
+# # Tells mod_suphp NOT to handle requests with the type <mime-type>.
+# suPHP_RemoveHandler <mime-type>
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/userdir.conf.erb b/puppet/modules/apache/templates/mod/userdir.conf.erb
new file mode 100644
index 0000000..cfe2e38
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/userdir.conf.erb
@@ -0,0 +1,19 @@
+<IfModule mod_userdir.c>
+<% if @disable_root -%>
+ UserDir disabled root
+<% end -%>
+ UserDir <%= @dir %>
+
+ <Directory <%= @home %>/*/<%= @dir %>>
+ AllowOverride FileInfo AuthConfig Limit Indexes
+ Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
+ <Limit GET POST OPTIONS>
+ Order allow,deny
+ Allow from all
+ </Limit>
+ <LimitExcept GET POST OPTIONS>
+ Order deny,allow
+ Deny from all
+ </LimitExcept>
+ </Directory>
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/worker.conf.erb b/puppet/modules/apache/templates/mod/worker.conf.erb
new file mode 100644
index 0000000..f0bba39
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/worker.conf.erb
@@ -0,0 +1,9 @@
+<IfModule mpm_worker_module>
+ ServerLimit <%= @serverlimit %>
+ StartServers <%= @startservers %>
+ MaxClients <%= @maxclients %>
+ MinSpareThreads <%= @minsparethreads %>
+ MaxSpareThreads <%= @maxsparethreads %>
+ ThreadsPerChild <%= @threadsperchild %>
+ MaxRequestsPerChild <%= @maxrequestsperchild %>
+</IfModule>
diff --git a/puppet/modules/apache/templates/mod/wsgi.conf.erb b/puppet/modules/apache/templates/mod/wsgi.conf.erb
new file mode 100644
index 0000000..f0611fc
--- /dev/null
+++ b/puppet/modules/apache/templates/mod/wsgi.conf.erb
@@ -0,0 +1,10 @@
+# The WSGI Apache module configuration file is being
+# managed by Puppet an changes will be overwritten.
+<IfModule mod_wsgi.c>
+ <%- if @wsgi_socket_prefix -%>
+ WSGISocketPrefix <%= @wsgi_socket_prefix %>
+ <%- end -%>
+ <%- if @wsgi_python_home -%>
+ WSGIPythonHome <%= @wsgi_python_home %>
+ <%- end -%>
+</IfModule>
diff --git a/puppet/modules/apache/templates/namevirtualhost.erb b/puppet/modules/apache/templates/namevirtualhost.erb
new file mode 100644
index 0000000..cf76768
--- /dev/null
+++ b/puppet/modules/apache/templates/namevirtualhost.erb
@@ -0,0 +1,8 @@
+<%# NameVirtualHost should always be one of:
+ - *
+ - *:<port>
+ - _default_:<port>
+ - <ip>
+ - <ip>:<port>
+-%>
+NameVirtualHost <%= @addr_port %>
diff --git a/puppet/modules/apache/templates/ports_header.erb b/puppet/modules/apache/templates/ports_header.erb
new file mode 100644
index 0000000..4908db4
--- /dev/null
+++ b/puppet/modules/apache/templates/ports_header.erb
@@ -0,0 +1,5 @@
+# ************************************
+# Listen & NameVirtualHost resources in module puppetlabs-apache
+# Managed by Puppet
+# ************************************
+
diff --git a/puppet/modules/apache/templates/vhost.conf.erb b/puppet/modules/apache/templates/vhost.conf.erb
new file mode 100644
index 0000000..83317e2
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost.conf.erb
@@ -0,0 +1,47 @@
+# ************************************
+# Vhost template in module puppetlabs-apache
+# Managed by Puppet
+# ************************************
+
+<VirtualHost <%= @nvh_addr_port %>>
+ ServerName <%= @servername %>
+<% if @serveradmin -%>
+ ServerAdmin <%= @serveradmin %>
+<% end -%>
+
+ ## Vhost docroot
+<% if @virtual_docroot -%>
+ VirtualDocumentRoot <%= @virtual_docroot %>
+<% else -%>
+ DocumentRoot <%= @docroot %>
+<% end -%>
+<%= scope.function_template(['apache/vhost/_aliases.erb']) -%>
+
+<%= scope.function_template(['apache/vhost/_itk.erb']) -%>
+
+ ## Directories, there should at least be a declaration for <%= @docroot %>
+<%= scope.function_template(['apache/vhost/_directories.erb']) -%>
+
+ ## Logging
+<% if @error_log -%>
+ ErrorLog <%= @error_log_destination %>
+<% end -%>
+ LogLevel warn
+ ServerSignature Off
+<% if @access_log -%>
+ CustomLog <%= @access_log_destination %> <%= @_access_log_format %>
+<% end -%>
+<%= scope.function_template(['apache/vhost/_block.erb']) -%>
+<%= scope.function_template(['apache/vhost/_proxy.erb']) -%>
+<%= scope.function_template(['apache/vhost/_rack.erb']) -%>
+<%= scope.function_template(['apache/vhost/_redirect.erb']) -%>
+<%= scope.function_template(['apache/vhost/_rewrite.erb']) -%>
+<%= scope.function_template(['apache/vhost/_scriptalias.erb']) -%>
+<%= scope.function_template(['apache/vhost/_serveralias.erb']) -%>
+<%= scope.function_template(['apache/vhost/_setenv.erb']) -%>
+<%= scope.function_template(['apache/vhost/_ssl.erb']) -%>
+<%= scope.function_template(['apache/vhost/_suphp.erb']) -%>
+<%= scope.function_template(['apache/vhost/_requestheader.erb']) -%>
+<%= scope.function_template(['apache/vhost/_wsgi.erb']) -%>
+<%= scope.function_template(['apache/vhost/_custom_fragment.erb']) -%>
+</VirtualHost>
diff --git a/puppet/modules/apache/templates/vhost/_aliases.erb b/puppet/modules/apache/templates/vhost/_aliases.erb
new file mode 100644
index 0000000..90c7d16
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_aliases.erb
@@ -0,0 +1,8 @@
+<% if @aliases and ! @aliases.empty? -%>
+ ## Alias declarations for resources outside the DocumentRoot
+ <%- [@aliases].flatten.compact.each do |alias_statement| -%>
+ <%- if alias_statement["alias"] != '' and alias_statement["path"] != ''-%>
+ Alias <%= alias_statement["alias"] %> <%= alias_statement["path"] %>
+ <%- end -%>
+ <%- end -%>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_block.erb b/puppet/modules/apache/templates/vhost/_block.erb
new file mode 100644
index 0000000..f235f89
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_block.erb
@@ -0,0 +1,10 @@
+<% if @block and ! @block.empty? -%>
+
+ ## Block access statements
+<% if @block.include? 'scm' -%>
+ # Block access to SCM directories.
+ <DirectoryMatch .*\.(svn|git|bzr)/.*>
+ Deny From All
+ </DirectoryMatch>
+<% end -%>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_custom_fragment.erb b/puppet/modules/apache/templates/vhost/_custom_fragment.erb
new file mode 100644
index 0000000..9739646
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_custom_fragment.erb
@@ -0,0 +1,5 @@
+<% if @custom_fragment -%>
+
+ ## Custom fragment
+<%= @custom_fragment %>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_directories.erb b/puppet/modules/apache/templates/vhost/_directories.erb
new file mode 100644
index 0000000..3f4405e
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_directories.erb
@@ -0,0 +1,89 @@
+<% if @_directories and ! @_directories.empty? -%>
+ <%- [@_directories].flatten.compact.each do |directory| -%>
+ <%- if directory['path'] and directory['path'] != ''-%>
+
+ <%- provider = 'Directory' -%>
+ <%- if directory['provider'] and [ 'directory', 'location', 'files' ].include?(directory['provider']) -%>
+ <%- provider = directory['provider'].capitalize -%>
+ <%- end -%>
+ <<%= provider + ' ' + directory['path'] %>>
+ <%- if directory['headers'] -%>
+ <%- Array(directory['headers']).each do |header| -%>
+ Header <%= header %>
+ <%- end -%>
+ <%- end -%>
+ <%- if directory['options'] -%>
+ Options <%= Array(directory['options']).join(' ') %>
+ <%- end -%>
+ <%- if directory['allow_override'] -%>
+ AllowOverride <%= Array(directory['allow_override']).join(' ') %>
+ <%- else -%>
+ AllowOverride None
+ <%- end -%>
+ <%- if directory['order'] and directory['order'] != '' -%>
+ Order <%= Array(directory['order']).join(',') %>
+ <%- else -%>
+ Order allow,deny
+ <%- end -%>
+ <%- if directory['deny'] and directory['deny'] != '' -%>
+ Deny <%= directory['deny'] %>
+ <%- end -%>
+ <%- if directory['allow'] and directory['allow'] != '' -%>
+ Allow <%= directory['allow'] %>
+ <%- else -%>
+ Allow from all
+ <%- end -%>
+ <%- if directory['addhandlers'] and ! directory['addhandlers'].empty? -%>
+ <%- [directory['addhandlers']].flatten.compact.each do |addhandler| -%>
+ AddHandler <%= addhandler['handler'] %> <%= Array(addhandler['extensions']).join(' ') %>
+ <%- end -%>
+ <%- end -%>
+ <%- if directory['passenger_enabled'] and directory['passenger_enabled'] != '' -%>
+ PassengerEnabled <%= directory['passenger_enabled'] %>
+ <%- end -%>
+ <%- if directory['auth_type'] -%>
+ AuthType <%= directory['auth_type'] %>
+ <%- end -%>
+ <%- if directory['auth_name'] -%>
+ AuthName "<%= directory['auth_name'] %>"
+ <%- end -%>
+ <%- if directory['auth_digest_algorithm'] -%>
+ AuthDigestAlgorithm <%= directory['auth_digest_algorithm'] %>
+ <%- end -%>
+ <%- if directory['auth_digest_domain'] -%>
+ AuthDigestDomain <%= Array(directory['auth_digest_domain']).join(' ') %>
+ <%- end -%>
+ <%- if directory['auth_digest_nonce_lifetime'] -%>
+ AuthDigestNonceLifetime <%= directory['auth_digest_nonce_lifetime'] %>
+ <%- end -%>
+ <%- if directory['auth_digest_provider'] -%>
+ AuthDigestProvider <%= directory['auth_digest_provider'] %>
+ <%- end -%>
+ <%- if directory['auth_digest_qop'] -%>
+ AuthDigestQop <%= directory['auth_digest_qop'] %>
+ <%- end -%>
+ <%- if directory['auth_digest_shmem_size'] -%>
+ AuthDigestShmemSize <%= directory['auth_digest_shmem_size'] %>
+ <%- end -%>
+ <%- if directory['auth_basic_authoritative'] -%>
+ AuthBasicAuthoritative <%= directory['auth_basic_authoritative'] %>
+ <%- end -%>
+ <%- if directory['auth_basic_fake'] -%>
+ AuthBasicFake <%= directory['auth_basic_fake'] %>
+ <%- end -%>
+ <%- if directory['auth_basic_provider'] -%>
+ AuthBasicProvider <%= directory['auth_basic_provider'] %>
+ <%- end -%>
+ <%- if directory['auth_user_file'] -%>
+ AuthUserFile <%= directory['auth_user_file'] %>
+ <%- end -%>
+ <%- if directory['auth_require'] -%>
+ Require <%= directory['auth_require'] %>
+ <%- end -%>
+ <%- if directory['custom_fragment'] -%>
+ <%= directory['custom_fragment'] %>
+ <%- end -%>
+ </<%= provider %>>
+ <%- end -%>
+ <%- end -%>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_itk.erb b/puppet/modules/apache/templates/vhost/_itk.erb
new file mode 100644
index 0000000..7d3bb51
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_itk.erb
@@ -0,0 +1,28 @@
+<% if @itk and ! @itk.empty? -%>
+ ## ITK statement
+ <IfModule mpm_itk_module>
+ <%- if @itk["user"] and @itk["group"] -%>
+ AssignUserId <%= @itk["user"] %> <%= @itk["group"] %>
+ <%- end -%>
+ <%- if @itk["assignuieridexpr"] -%>
+ AssignUserIdExpr <%= @itk["assignuieridexpr"] %>
+ <%- end -%>
+ <%- if @itk["assignuiergroupexpr"] -%>
+ AssignGroupIdExpr <%= @itk["assignuiergroupexpr"] %>
+ <%- end -%>
+ <%- if @itk["maxclientvhost"] -%>
+ MaxClientsVHost <%= @itk["maxclientvhost"] %>
+ <%- end -%>
+ <%- if @itk["nice"] -%>
+ NiceValue <%= @itk["nice"] %>
+ <%- end -%>
+ <%- if @kernelversion >= '3.5.0' -%>
+ <%- if @itk["limituidrange"] -%>
+ LimitUIDRange <%= @itk["limituidrange"] %>
+ <%- end -%>
+ <%- if @itk["limitgidrange"] -%>
+ LimitGIDRange <%= @itk["limitgidrange"] %>
+ <%- end -%>
+ <%- end -%>
+ </IfModule>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_proxy.erb b/puppet/modules/apache/templates/vhost/_proxy.erb
new file mode 100644
index 0000000..badf73a
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_proxy.erb
@@ -0,0 +1,21 @@
+<% if @proxy_dest or @proxy_pass -%>
+
+ ## Proxy rules
+ ProxyRequests Off
+ <Proxy *>
+ Order deny,allow
+ Allow from all
+ </Proxy>
+<%- end -%>
+<% [@proxy_pass].flatten.compact.each do |proxy| %>
+ ProxyPass <%= proxy['path'] %> <%= proxy['url'] %>
+ ProxyPassReverse <%= proxy['path'] %> <%= proxy['url'] %>
+<% end %>
+<% if @proxy_dest -%>
+<% Array(@no_proxy_uris).each do |uri| %>
+ ProxyPass <%= uri %> !
+<% end %>
+ ProxyPass / <%= @proxy_dest %>/
+ ProxyPassReverse / <%= @proxy_dest %>/
+ ProxyPreserveHost On
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_rack.erb b/puppet/modules/apache/templates/vhost/_rack.erb
new file mode 100644
index 0000000..4a5b5f1
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_rack.erb
@@ -0,0 +1,7 @@
+<% if @rack_base_uris -%>
+
+ ## Enable rack
+<% Array(@rack_base_uris).each do |uri| -%>
+ RackBaseURI <%= uri %>
+<% end -%>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_redirect.erb b/puppet/modules/apache/templates/vhost/_redirect.erb
new file mode 100644
index 0000000..66eee5e
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_redirect.erb
@@ -0,0 +1,12 @@
+<% if @redirect_source and @redirect_dest -%>
+<% @redirect_dest_a = Array(@redirect_dest) -%>
+<% @redirect_source_a = Array(@redirect_source) -%>
+<% @redirect_status_a = Array(@redirect_status) -%>
+
+ ## Redirect rules
+<% @redirect_source_a.each_with_index do |source, i| -%>
+<% @redirect_dest_a[i] ||= @redirect_dest_a[0] -%>
+<% @redirect_status_a[i] ||= @redirect_status_a[0] -%>
+ Redirect <%= "#{@redirect_status_a[i]} " %><%= source %> <%= @redirect_dest_a[i] %>
+<% end -%>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_requestheader.erb b/puppet/modules/apache/templates/vhost/_requestheader.erb
new file mode 100644
index 0000000..9f17505
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_requestheader.erb
@@ -0,0 +1,10 @@
+<% if @request_headers and ! @request_headers.empty? -%>
+
+ ## Request header rules
+ ## as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader
+ <%- Array(@request_headers).each do |request_statement| -%>
+ <%- if request_statement != '' -%>
+ RequestHeader <%= request_statement %>
+ <%- end -%>
+ <%- end -%>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_rewrite.erb b/puppet/modules/apache/templates/vhost/_rewrite.erb
new file mode 100644
index 0000000..a39db1c
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_rewrite.erb
@@ -0,0 +1,14 @@
+<% if @rewrite_rule -%>
+
+ ## Rewrite rules
+ RewriteEngine On
+<% if @rewrite_base -%>
+ RewriteBase <%= @rewrite_base %>
+<% end -%>
+<% if @rewrite_cond -%>
+<% Array(@rewrite_cond).each do |cond| -%>
+ RewriteCond <%= cond %>
+<% end -%>
+<% end -%>
+ RewriteRule <%= @rewrite_rule %>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_scriptalias.erb b/puppet/modules/apache/templates/vhost/_scriptalias.erb
new file mode 100644
index 0000000..0262055
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_scriptalias.erb
@@ -0,0 +1,14 @@
+<% if @scriptalias -%>
+
+ ## Script alias directives
+ ScriptAlias /cgi-bin/ "<%= @scriptalias %>/"
+ <Directory "<%= @scriptalias %>">
+ AllowOverride None
+ Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
+ Order allow,deny
+ Allow from all
+<% if @ssl -%>
+ SSLOptions +StdEnvVars
+<% end -%>
+ </Directory>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_serveralias.erb b/puppet/modules/apache/templates/vhost/_serveralias.erb
new file mode 100644
index 0000000..278b6dd
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_serveralias.erb
@@ -0,0 +1,7 @@
+<% if @serveraliases and ! @serveraliases.empty? -%>
+
+ ## Server aliases
+<% Array(@serveraliases).each do |serveralias| -%>
+ ServerAlias <%= serveralias %>
+<% end -%>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_setenv.erb b/puppet/modules/apache/templates/vhost/_setenv.erb
new file mode 100644
index 0000000..d5f9ea8
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_setenv.erb
@@ -0,0 +1,12 @@
+<% if @setenv and ! @setenv.empty? -%>
+
+ ## SetEnv/SetEnvIf for environment variables
+<% Array(@setenv).each do |envvar| -%>
+ SetEnv <%= envvar %>
+<% end -%>
+<% end -%>
+<% if @setenvif and ! @setenvif.empty? -%>
+<% Array(@setenvif).each do |envifvar| -%>
+ SetEnvIf <%= envifvar %>
+<% end -%>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_ssl.erb b/puppet/modules/apache/templates/vhost/_ssl.erb
new file mode 100644
index 0000000..239c304
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_ssl.erb
@@ -0,0 +1,26 @@
+<% if @ssl -%>
+
+ ## SSL directives
+ SSLEngine on
+ SSLCertificateFile <%= @ssl_cert %>
+ SSLCertificateKeyFile <%= @ssl_key %>
+<% if @ssl_chain -%>
+ SSLCertificateChainFile <%= @ssl_chain %>
+<% end -%>
+ SSLCACertificatePath <%= @ssl_certs_dir %>
+<% if @ssl_ca -%>
+ SSLCACertificateFile <%= @ssl_ca %>
+<% end -%>
+<% if @ssl_crl_path -%>
+ SSLCARevocationPath <%= @ssl_crl_path %>
+<% end -%>
+<% if @ssl_crl -%>
+ SSLCARevocationFile <%= @ssl_crl %>
+<% end -%>
+<% if @sslproxyengine -%>
+ SSLProxyEngine On
+<% end -%>
+ <FilesMatch "\.(cgi|shtml|phtml|php)$">
+ SSLOptions +StdEnvVars
+ </FilesMatch>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_suphp.erb b/puppet/modules/apache/templates/vhost/_suphp.erb
new file mode 100644
index 0000000..37aa299
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_suphp.erb
@@ -0,0 +1,11 @@
+<% if @suphp_engine == 'on' -%>
+<% if @suphp_addhandler -%>
+ suPHP_AddHandler <%= @suphp_addhandler %>
+<% end -%>
+<% if @suphp_engine -%>
+ suPHP_Engine <%= @suphp_engine %>
+<% end -%>
+<% if @suphp_configpath -%>
+ suPHP_ConfigPath <%= @suphp_configpath %>
+<% end -%>
+<% end -%>
diff --git a/puppet/modules/apache/templates/vhost/_wsgi.erb b/puppet/modules/apache/templates/vhost/_wsgi.erb
new file mode 100644
index 0000000..d9970bd
--- /dev/null
+++ b/puppet/modules/apache/templates/vhost/_wsgi.erb
@@ -0,0 +1,15 @@
+<% if @wsgi_daemon_process and @wsgi_daemon_process_options -%>
+ WSGIDaemonProcess <%= @wsgi_daemon_process %> <%= @wsgi_daemon_process_options.collect { |k,v| "#{k}=#{v}"}.sort.join(' ') %>
+<% elsif @wsgi_daemon_process and !@wsgi_daemon_process_options -%>
+ WSGIDaemonProcess <%= @wsgi_daemon_process %>
+<% end -%>
+<% if @wsgi_process_group -%>
+ WSGIProcessGroup <%= @wsgi_process_group %>
+<% end -%>
+<% if @wsgi_script_aliases and ! @wsgi_script_aliases.empty? -%>
+ <%- @wsgi_script_aliases.each do |a, p| -%>
+ <%- if a != '' and p != ''-%>
+ WSGIScriptAlias <%= a %> <%= p %>
+ <%- end -%>
+ <%- end -%>
+<% end -%>
diff --git a/puppet/modules/apache/tests/apache.pp b/puppet/modules/apache/tests/apache.pp
new file mode 100644
index 0000000..0d45435
--- /dev/null
+++ b/puppet/modules/apache/tests/apache.pp
@@ -0,0 +1,6 @@
+include apache
+include apache::mod::php
+include apache::mod::cgi
+include apache::mod::userdir
+include apache::mod::disk_cache
+include apache::mod::proxy_http
diff --git a/puppet/modules/apache/tests/dev.pp b/puppet/modules/apache/tests/dev.pp
new file mode 100644
index 0000000..805ad7e
--- /dev/null
+++ b/puppet/modules/apache/tests/dev.pp
@@ -0,0 +1 @@
+include apache::dev
diff --git a/puppet/modules/apache/tests/init.pp b/puppet/modules/apache/tests/init.pp
new file mode 100644
index 0000000..b3f9f13
--- /dev/null
+++ b/puppet/modules/apache/tests/init.pp
@@ -0,0 +1 @@
+include apache
diff --git a/puppet/modules/apache/tests/mods.pp b/puppet/modules/apache/tests/mods.pp
new file mode 100644
index 0000000..59362bd
--- /dev/null
+++ b/puppet/modules/apache/tests/mods.pp
@@ -0,0 +1,9 @@
+## Default mods
+
+# Base class. Declares default vhost on port 80 and default ssl
+# vhost on port 443 listening on all interfaces and serving
+# $apache::docroot, and declaring our default set of modules.
+class { 'apache':
+ default_mods => true,
+}
+
diff --git a/puppet/modules/apache/tests/mods_custom.pp b/puppet/modules/apache/tests/mods_custom.pp
new file mode 100644
index 0000000..0ae699c
--- /dev/null
+++ b/puppet/modules/apache/tests/mods_custom.pp
@@ -0,0 +1,16 @@
+## custom mods
+
+# Base class. Declares default vhost on port 80 and default ssl
+# vhost on port 443 listening on all interfaces and serving
+# $apache::docroot, and declaring a custom set of modules.
+class { 'apache':
+ default_mods => [
+ 'info',
+ 'alias',
+ 'mime',
+ 'env',
+ 'setenv',
+ 'expires',
+ ],
+}
+
diff --git a/puppet/modules/apache/tests/php.pp b/puppet/modules/apache/tests/php.pp
new file mode 100644
index 0000000..618e0eb
--- /dev/null
+++ b/puppet/modules/apache/tests/php.pp
@@ -0,0 +1 @@
+include apache::php
diff --git a/puppet/modules/apache/tests/vhost.pp b/puppet/modules/apache/tests/vhost.pp
new file mode 100644
index 0000000..10aa9e3
--- /dev/null
+++ b/puppet/modules/apache/tests/vhost.pp
@@ -0,0 +1,185 @@
+## Default vhosts, and custom vhosts
+# NB: Please see the other vhost_*.pp example files for further
+# examples.
+
+# Base class. Declares default vhost on port 80 and default ssl
+# vhost on port 443 listening on all interfaces and serving
+# $apache::docroot
+class { 'apache': }
+
+# Most basic vhost
+apache::vhost { 'first.example.com':
+ port => '80',
+ docroot => '/var/www/first',
+}
+
+# Vhost with different docroot owner/group
+apache::vhost { 'second.example.com':
+ port => '80',
+ docroot => '/var/www/second',
+ docroot_owner => 'third',
+ docroot_group => 'third',
+}
+
+# Vhost with serveradmin
+apache::vhost { 'third.example.com':
+ port => '80',
+ docroot => '/var/www/third',
+ serveradmin => 'admin@example.com',
+}
+
+# Vhost with ssl (uses default ssl certs)
+apache::vhost { 'ssl.example.com':
+ port => '443',
+ docroot => '/var/www/ssl',
+ ssl => true,
+}
+
+# Vhost with ssl and specific ssl certs
+apache::vhost { 'fourth.example.com':
+ port => '443',
+ docroot => '/var/www/fourth',
+ ssl => true,
+ ssl_cert => '/etc/ssl/fourth.example.com.cert',
+ ssl_key => '/etc/ssl/fourth.example.com.key',
+}
+
+# Vhost with english title and servername parameter
+apache::vhost { 'The fifth vhost':
+ servername => 'fifth.example.com',
+ port => '80',
+ docroot => '/var/www/fifth',
+}
+
+# Vhost with server aliases
+apache::vhost { 'sixth.example.com':
+ serveraliases => [
+ 'sixth.example.org',
+ 'sixth.example.net',
+ ],
+ port => '80',
+ docroot => '/var/www/fifth',
+}
+
+# Vhost with alternate options
+apache::vhost { 'seventh.example.com':
+ port => '80',
+ docroot => '/var/www/seventh',
+ options => [
+ 'Indexes',
+ 'MultiViews',
+ ],
+}
+
+# Vhost with AllowOverride for .htaccess
+apache::vhost { 'eighth.example.com':
+ port => '80',
+ docroot => '/var/www/eighth',
+ override => 'All',
+}
+
+# Vhost with access and error logs disabled
+apache::vhost { 'ninth.example.com':
+ port => '80',
+ docroot => '/var/www/ninth',
+ access_log => false,
+ error_log => false,
+}
+
+# Vhost with custom access and error logs and logroot
+apache::vhost { 'tenth.example.com':
+ port => '80',
+ docroot => '/var/www/tenth',
+ access_log_file => 'tenth_vhost.log',
+ error_log_file => 'tenth_vhost_error.log',
+ logroot => '/var/log',
+}
+
+# Vhost with a cgi-bin
+apache::vhost { 'eleventh.example.com':
+ port => '80',
+ docroot => '/var/www/eleventh',
+ scriptalias => '/usr/lib/cgi-bin',
+}
+
+# Vhost with a proxypass configuration
+apache::vhost { 'twelfth.example.com':
+ port => '80',
+ docroot => '/var/www/twelfth',
+ proxy_dest => 'http://internal.example.com:8080/twelfth',
+ no_proxy_uris => ['/login','/logout'],
+}
+
+# Vhost to redirect /login and /logout
+apache::vhost { 'thirteenth.example.com':
+ port => '80',
+ docroot => '/var/www/thirteenth',
+ redirect_source => [
+ '/login',
+ '/logout',
+ ],
+ redirect_dest => [
+ 'http://10.0.0.10/login',
+ 'http://10.0.0.10/logout',
+ ],
+}
+
+# Vhost to permamently redirect
+apache::vhost { 'fourteenth.example.com':
+ port => '80',
+ docroot => '/var/www/fourteenth',
+ redirect_source => '/blog',
+ redirect_dest => 'http://blog.example.com',
+ redirect_status => 'permanent',
+}
+
+# Vhost with a rack configuration
+apache::vhost { 'fifteenth.example.com':
+ port => '80',
+ docroot => '/var/www/fifteenth',
+ rack_base_uris => ['/rackapp1', '/rackapp2'],
+}
+
+# Vhost to redirect non-ssl to ssl
+apache::vhost { 'sixteenth.example.com non-ssl':
+ servername => 'sixteenth.example.com',
+ port => '80',
+ docroot => '/var/www/sixteenth',
+ rewrite_cond => '%{HTTPS} off',
+ rewrite_rule => '(.*) https://%{HTTPS_HOST}%{REQUEST_URI}',
+}
+apache::vhost { 'sixteenth.example.com ssl':
+ servername => 'sixteenth.example.com',
+ port => '443',
+ docroot => '/var/www/sixteenth',
+ ssl => true,
+}
+
+# Vhost to block repository files
+apache::vhost { 'seventeenth.example.com':
+ port => '80',
+ docroot => '/var/www/seventeenth',
+ block => 'scm',
+}
+
+# Vhost with special environment variables
+apache::vhost { 'eighteenth.example.com':
+ port => '80',
+ docroot => '/var/www/eighteenth',
+ setenv => ['SPECIAL_PATH /foo/bin','KILROY was_here'],
+}
+apache::vhost { 'nineteenth.example.com':
+ port => '80',
+ docroot => '/var/www/nineteenth',
+ setenvif => 'Host "^([^\.]*)\.website\.com$" CLIENT_NAME=$1',
+}
+
+# Vhost with alias for subdomain mapped to same named directory
+# http://example.com.loc => /var/www/example.com
+apache::vhost { 'subdomain.loc':
+ vhost_name => '*',
+ port => '80',
+ virtual_docroot => '/var/www/%-2+',
+ docroot => '/var/www',
+ serveraliases => ['*.loc',],
+}
diff --git a/puppet/modules/apache/tests/vhost_directories.pp b/puppet/modules/apache/tests/vhost_directories.pp
new file mode 100644
index 0000000..d8fcc0f
--- /dev/null
+++ b/puppet/modules/apache/tests/vhost_directories.pp
@@ -0,0 +1,30 @@
+# Base class. Declares default vhost on port 80 and default ssl
+# vhost on port 443 listening on all interfaces and serving
+# $apache::docroot
+class { 'apache': }
+
+# Example from README adapted.
+apache::vhost { 'readme.example.net':
+ docroot => '/var/www/readme',
+ directories => [
+ { path => '/var/www/readme', 'ServerTokens' => 'prod' },
+ { path => '/usr/share/empty', 'allow' => 'from all' },
+ ],
+}
+
+# location test
+apache::vhost { 'location.example.net':
+ docroot => '/var/www/location',
+ directories => [
+ { path => '/location', 'provider' => 'location', 'ServerTokens' => 'prod' },
+ ],
+}
+
+# files test, curedly disable access to accidental backup files.
+apache::vhost { 'files.example.net':
+ docroot => '/var/www/files',
+ directories => [
+ { path => '~ (\.swp|\.bak|~)$', 'provider' => 'files', 'deny' => 'from all' },
+ ],
+}
+
diff --git a/puppet/modules/apache/tests/vhost_ip_based.pp b/puppet/modules/apache/tests/vhost_ip_based.pp
new file mode 100644
index 0000000..dc0fa4f
--- /dev/null
+++ b/puppet/modules/apache/tests/vhost_ip_based.pp
@@ -0,0 +1,25 @@
+## IP-based vhosts on any listen port
+# IP-based vhosts respond to requests on specific IP addresses.
+
+# Base class. Turn off the default vhosts; we will be declaring
+# all vhosts below.
+class { 'apache':
+ default_vhost => false,
+}
+
+# Listen on port 80 and 81; required because the following vhosts
+# are not declared with a port parameter.
+apache::listen { '80': }
+apache::listen { '81': }
+
+# IP-based vhosts
+apache::vhost { 'first.example.com':
+ ip => '10.0.0.10',
+ docroot => '/var/www/first',
+ ip_based => true,
+}
+apache::vhost { 'second.example.com':
+ ip => '10.0.0.11',
+ docroot => '/var/www/second',
+ ip_based => true,
+}
diff --git a/puppet/modules/apache/tests/vhost_ssl.pp b/puppet/modules/apache/tests/vhost_ssl.pp
new file mode 100644
index 0000000..8e7a2b2
--- /dev/null
+++ b/puppet/modules/apache/tests/vhost_ssl.pp
@@ -0,0 +1,23 @@
+## SSL-enabled vhosts
+# SSL-enabled vhosts respond only to HTTPS queries.
+
+# Base class. Turn off the default vhosts; we will be declaring
+# all vhosts below.
+class { 'apache':
+ default_vhost => false,
+}
+
+# Non-ssl vhost
+apache::vhost { 'first.example.com non-ssl':
+ servername => 'first.example.com',
+ port => '80',
+ docroot => '/var/www/first',
+}
+
+# SSL vhost at the same domain
+apache::vhost { 'first.example.com ssl':
+ servername => 'first.example.com',
+ port => '443',
+ docroot => '/var/www/first',
+ ssl => true,
+}
diff --git a/puppet/modules/apache/tests/vhosts_without_listen.pp b/puppet/modules/apache/tests/vhosts_without_listen.pp
new file mode 100644
index 0000000..e7d6cc0
--- /dev/null
+++ b/puppet/modules/apache/tests/vhosts_without_listen.pp
@@ -0,0 +1,53 @@
+## Declare ip-based and name-based vhosts
+# Mixing Name-based vhost with IP-specific vhosts requires `add_listen =>
+# 'false'` on the non-IP vhosts
+
+# Base class. Turn off the default vhosts; we will be declaring
+# all vhosts below.
+class { 'apache':
+ default_vhost => false,
+}
+
+
+# Add two an IP-based vhost on 10.0.0.10, ssl and non-ssl
+apache::vhost { 'The first IP-based vhost, non-ssl':
+ servername => 'first.example.com',
+ ip => '10.0.0.10',
+ port => '80',
+ ip_based => true,
+ docroot => '/var/www/first',
+}
+apache::vhost { 'The first IP-based vhost, ssl':
+ servername => 'first.example.com',
+ ip => '10.0.0.10',
+ port => '443',
+ ip_based => true,
+ docroot => '/var/www/first-ssl',
+ ssl => true,
+}
+
+# Two name-based vhost listening on 10.0.0.20
+apache::vhost { 'second.example.com':
+ ip => '10.0.0.20',
+ port => '80',
+ docroot => '/var/www/second',
+}
+apache::vhost { 'third.example.com':
+ ip => '10.0.0.20',
+ port => '80',
+ docroot => '/var/www/third',
+}
+
+# Two name-based vhosts without IPs specified, so that they will answer on either 10.0.0.10 or 10.0.0.20 . It is requried to declare
+# `add_listen => 'false'` to disable declaring "Listen 80" which will conflict
+# with the IP-based preceeding vhosts.
+apache::vhost { 'fourth.example.com':
+ port => '80',
+ docroot => '/var/www/fourth',
+ add_listen => false,
+}
+apache::vhost { 'fifth.example.com':
+ port => '80',
+ docroot => '/var/www/fifth',
+ add_listen => false,
+}
diff --git a/puppet/modules/apt/.bundle/config b/puppet/modules/apt/.bundle/config
new file mode 100644
index 0000000..2ddd802
--- /dev/null
+++ b/puppet/modules/apt/.bundle/config
@@ -0,0 +1,2 @@
+---
+BUNDLE_WITHOUT: development
diff --git a/puppet/modules/apt/.fixtures.yml b/puppet/modules/apt/.fixtures.yml
new file mode 100644
index 0000000..dbd5621
--- /dev/null
+++ b/puppet/modules/apt/.fixtures.yml
@@ -0,0 +1,5 @@
+fixtures:
+ repositories:
+ "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
+ symlinks:
+ "apt": "#{source_dir}"
diff --git a/puppet/modules/apt/.forge-release/pom.xml b/puppet/modules/apt/.forge-release/pom.xml
new file mode 100644
index 0000000..b788e86
--- /dev/null
+++ b/puppet/modules/apt/.forge-release/pom.xml
@@ -0,0 +1,29 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>puppetlabs</groupId>
+ <artifactId>ghpublisher</artifactId>
+ <version>1.0.0</version>
+ <packaging>puppet-module</packaging>
+ <name>ghpublisher</name>
+
+ <properties>
+ <forge.login>${env.PUBLISHER_LOGIN}</forge.login>
+ <forge.password>${env.PUBLISHER_PASSWORD}</forge.password>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.cloudsmith.geppetto</groupId>
+ <artifactId>forge-maven-plugin</artifactId>
+ <version>3.2.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <enablePuppetLintValidation>false</enablePuppetLintValidation>
+ <cacheLocation>${project.build.directory}/forgeCache</cacheLocation>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/puppet/modules/apt/.forge-release/publish b/puppet/modules/apt/.forge-release/publish
new file mode 100644
index 0000000..7d8665f
--- /dev/null
+++ b/puppet/modules/apt/.forge-release/publish
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# Perform GitHub publish
+if [ -z "$PUBLISHER_LOGIN" ]
+then
+ echo "Environment variable PUBLISHER_LOGIN must be set"
+ exit 1
+fi
+
+if [ -z "$PUBLISHER_PASSWORD" ]
+then
+ echo "Environment variable PUBLISHER_PASSWORD must be set"
+ exit 1
+fi
+
+MODULES_ROOT=`pwd`
+cd $(dirname $0)
+mvn -q -s settings.xml -Dforge.modules.root="$MODULES_ROOT" deploy
\ No newline at end of file
diff --git a/puppet/modules/apt/.forge-release/settings.xml b/puppet/modules/apt/.forge-release/settings.xml
new file mode 100644
index 0000000..3ec7de2
--- /dev/null
+++ b/puppet/modules/apt/.forge-release/settings.xml
@@ -0,0 +1,34 @@
+<settings>
+ <profiles>
+ <profile>
+ <id>cloudsmith</id>
+ <repositories>
+ <repository>
+ <id>cloudsmith</id>
+ <url>https://am0.cloudsmith.com/nexus/content/repositories/releases/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>cloudsmith</id>
+ <url>https://am0.cloudsmith.com/nexus/content/repositories/releases/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+ <activeProfiles>
+ <activeProfile>cloudsmith</activeProfile>
+ </activeProfiles>
+</settings>
diff --git a/puppet/modules/apt/.forge-release/validate b/puppet/modules/apt/.forge-release/validate
new file mode 100644
index 0000000..190ed33
--- /dev/null
+++ b/puppet/modules/apt/.forge-release/validate
@@ -0,0 +1,6 @@
+#!/bin/sh
+#
+# Perform GitHub publish
+MODULES_ROOT=`pwd`
+cd $(dirname $0)
+mvn -q -s settings.xml -Dforge.modules.root="$MODULES_ROOT" compile
\ No newline at end of file
diff --git a/puppet/modules/apt/.nodeset.yml b/puppet/modules/apt/.nodeset.yml
new file mode 100644
index 0000000..ad056fe
--- /dev/null
+++ b/puppet/modules/apt/.nodeset.yml
@@ -0,0 +1,19 @@
+---
+default_set: 'ubuntu-server-12042-x64'
+sets:
+ 'debian-607-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'debian-607-x64'
+ 'debian-70rc1-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'debian-70rc1-x64'
+ 'ubuntu-server-10044-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'ubuntu-server-10044-x64'
+ 'ubuntu-server-12042-x64':
+ nodes:
+ "main.foo.vm":
+ prefab: 'ubuntu-server-12042-x64'
diff --git a/puppet/modules/apt/.travis.yml b/puppet/modules/apt/.travis.yml
new file mode 100644
index 0000000..00924ba
--- /dev/null
+++ b/puppet/modules/apt/.travis.yml
@@ -0,0 +1,40 @@
+---
+branches:
+ only:
+ - master
+language: ruby
+bundler_args: --without development
+script: bundle exec rake spec SPEC_OPTS='--format documentation'
+after_success:
+ - git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-release
+ - .forge-release/publish
+rvm:
+ - 1.8.7
+ - 1.9.3
+ - 2.0.0
+env:
+ matrix:
+ - PUPPET_GEM_VERSION="~> 2.7.0"
+ - PUPPET_GEM_VERSION="~> 3.0.0"
+ - PUPPET_GEM_VERSION="~> 3.1.0"
+ - PUPPET_GEM_VERSION="~> 3.2.0"
+ global:
+ - PUBLISHER_LOGIN=puppetlabs
+ - secure: |-
+ ipB/CV1rVSTXU9ZDuzrFOlzJrRmJob36tKns2xszuH4r9s5P9qivNAngRGdV
+ msb69xvOlzQykM0WRF+4kJ6TZ7AbMiDI+VZ8GDtsRaU5/q3BpsvFe8aato+6
+ QeyFtBG62OsosTEhGws4mqiFsPDu3dHlakuJc9zevlTuhNwbKSs=
+matrix:
+ exclude:
+ - rvm: 1.9.3
+ env: PUPPET_GEM_VERSION="~> 2.7.0"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 2.7.0"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 3.0.0"
+ - rvm: 2.0.0
+ env: PUPPET_GEM_VERSION="~> 3.1.0"
+ - rvm: 1.8.7
+ env: PUPPET_GEM_VERSION="~> 3.2.0"
+notifications:
+ email: false
diff --git a/puppet/modules/apt/CHANGELOG b/puppet/modules/apt/CHANGELOG
new file mode 100644
index 0000000..0d321bc
--- /dev/null
+++ b/puppet/modules/apt/CHANGELOG
@@ -0,0 +1,183 @@
+2013-10-08 1.4.0
+
+Summary:
+
+Minor bugfix and allow the timeout to be adjusted.
+
+Features:
+- Add an `updates_timeout` to apt::params
+
+Fixes:
+- Ensure apt::ppa can readd a ppa removed by hand.
+
+Summary
+
+1.3.0
+=====
+
+Summary:
+
+This major feature in this release is the new apt::unattended_upgrades class,
+allowing you to handle Ubuntu's unattended feature. This allows you to select
+specific packages to automatically upgrade without any further user
+involvement.
+
+In addition we extend our Wheezy support, add proxy support to apt:ppa and do
+various cleanups and tweaks.
+
+Features:
+- Add apt::unattended_upgrades support for Ubuntu.
+- Add wheezy backports support.
+- Use the geoDNS http.debian.net instead of the main debian ftp server.
+- Add `options` parameter to apt::ppa in order to pass options to apt-add-repository command.
+- Add proxy support for apt::ppa (uses proxy_host and proxy_port from apt).
+
+Bugfixes:
+- Fix regsubst() calls to quote single letters (for future parser).
+- Fix lint warnings and other misc cleanup.
+
+1.2.0
+=====
+
+Features:
+- Add geppetto `.project` natures
+- Add GH auto-release
+- Add `apt::key::key_options` parameter
+- Add complex pin support using distribution properties for `apt::pin` via new properties:
+ - `apt::pin::codename`
+ - `apt::pin::release_version`
+ - `apt::pin::component`
+ - `apt::pin::originator`
+ - `apt::pin::label`
+- Add source architecture support to `apt::source::architecture`
+
+Bugfixes:
+- Use apt-get instead of aptitude in apt::force
+- Update default backports location
+- Add dependency for required packages before apt-get update
+
+
+1.1.1
+=====
+
+This is a bug fix release that resolves a number of issues:
+
+* By changing template variable usage, we remove the deprecation warnings
+ for Puppet 3.2.x
+* Fixed proxy file removal, when proxy absent
+
+Some documentation, style and whitespaces changes were also merged. This
+release also introduced proper rspec-puppet unit testing on Travis-CI to help
+reduce regression.
+
+Thanks to all the community contributors below that made this patch possible.
+
+#### Detail Changes
+
+* fix minor comment type (Chris Rutter)
+* whitespace fixes (Michael Moll)
+* Update travis config file (William Van Hevelingen)
+* Build all branches on travis (William Van Hevelingen)
+* Standardize travis.yml on pattern introduced in stdlib (William Van Hevelingen)
+* Updated content to conform to README best practices template (Lauren Rother)
+* Fix apt::release example in readme (Brian Galey)
+* add @ to variables in template (Peter Hoeg)
+* Remove deprecation warnings for pin.pref.erb as well (Ken Barber)
+* Update travis.yml to latest versions of puppet (Ken Barber)
+* Fix proxy file removal (Scott Barber)
+* Add spec test for removing proxy configuration (Dean Reilly)
+* Fix apt::key listing longer than 8 chars (Benjamin Knofe)
+
+
+---------------------------------------
+
+1.1.0
+=====
+
+This release includes Ubuntu 12.10 (Quantal) support for PPAs.
+
+---------------------------------------
+
+2012-05-25 Puppet Labs <info@puppetlabs.com> - 0.0.4
+ * Fix ppa list filename when there is a period in the PPA name
+ * Add .pref extension to apt preferences files
+ * Allow preferences to be purged
+ * Extend pin support
+
+2012-05-04 Puppet Labs <info@puppetlabs.com> - 0.0.3
+ * only invoke apt-get update once
+ * only install python-software-properties if a ppa is added
+ * support 'ensure => absent' for all defined types
+ * add apt::conf
+ * add apt::backports
+ * fixed Modulefile for module tool dependency resolution
+ * configure proxy before doing apt-get update
+ * use apt-get update instead of aptitude for apt::ppa
+ * add support to pin release
+
+
+2012-03-26 Puppet Labs <info@puppetlabs.com> - 0.0.2
+41cedbb (#13261) Add real examples to smoke tests.
+d159a78 (#13261) Add key.pp smoke test
+7116c7a (#13261) Replace foo source with puppetlabs source
+1ead0bf Ignore pkg directory.
+9c13872 (#13289) Fix some more style violations
+0ea4ffa (#13289) Change test scaffolding to use a module & manifest dir fixture path
+a758247 (#13289) Clean up style violations and fix corresponding tests
+99c3fd3 (#13289) Add puppet lint tests to Rakefile
+5148cbf (#13125) Apt keys should be case insensitive
+b9607a4 Convert apt::key to use anchors
+
+2012-03-07 Puppet Labs <info@puppetlabs.com> - 0.0.1
+d4fec56 Modify apt::source release parameter test
+1132a07 (#12917) Add contributors to README
+8cdaf85 (#12823) Add apt::key defined type and modify apt::source to use it
+7c0d10b (#12809) $release should use $lsbdistcodename and fall back to manual input
+be2cc3e (#12522) Adjust spec test for splitting purge
+7dc60ae (#12522) Split purge option to spare sources.list
+9059c4e Fix source specs to test all key permutations
+8acb202 Add test for python-software-properties package
+a4af11f Check if python-software-properties is defined before attempting to define it.
+1dcbf3d Add tests for required_packages change
+f3735d2 Allow duplicate $required_packages
+74c8371 (#12430) Add tests for changes to apt module
+97ebb2d Test two sources with the same key
+1160bcd (#12526) Add ability to reverse apt { disable_keys => true }
+2842d73 Add Modulefile to puppet-apt
+c657742 Allow the use of the same key in multiple sources
+8c27963 (#12522) Adding purge option to apt class
+997c9fd (#12529) Add unit test for apt proxy settings
+50f3cca (#12529) Add parameter to support setting a proxy for apt
+d522877 (#12094) Replace chained .with_* with a hash
+8cf1bd0 (#12094) Remove deprecated spec.opts file
+2d688f4 (#12094) Add rspec-puppet tests for apt
+0fb5f78 (#12094) Replace name with path in file resources
+f759bc0 (#11953) Apt::force passes $version to aptitude
+f71db53 (#11413) Add spec test for apt::force to verify changes to unless
+2f5d317 (#11413) Update dpkg query used by apt::force
+cf6caa1 (#10451) Add test coverage to apt::ppa
+0dd697d include_src parameter in example; Whitespace cleanup
+b662eb8 fix typos in "repositories"
+1be7457 Fix (#10451) - apt::ppa fails to "apt-get update" when new PPA source is added
+864302a Set the pin priority before adding the source (Fix #10449)
+1de4e0a Refactored as per mlitteken
+1af9a13 Added some crazy bash madness to check if the ppa is installed already. Otherwise the manifest tries to add it on every run!
+52ca73e (#8720) Replace Apt::Ppa with Apt::Builddep
+5c05fa0 added builddep command.
+a11af50 added the ability to specify the content of a key
+c42db0f Fixes ppa test.
+77d2b0d reformatted whitespace to match recommended style of 2 space indentation.
+27ebdfc ignore swap files.
+377d58a added smoke tests for module.
+18f614b reformatted apt::ppa according to recommended style.
+d8a1e4e Created a params class to hold global data.
+636ae85 Added two params for apt class
+148fc73 Update LICENSE.
+ed2d19e Support ability to add more than one PPA
+420d537 Add call to apt-update after add-apt-repository in apt::ppa
+945be77 Add package definition for python-software-properties
+71fc425 Abs paths for all commands
+9d51cd1 Adding LICENSE
+71796e3 Heading fix in README
+87777d8 Typo in README
+f848bac First commit
diff --git a/puppet/modules/apt/Gemfile b/puppet/modules/apt/Gemfile
new file mode 100644
index 0000000..15bd29d
--- /dev/null
+++ b/puppet/modules/apt/Gemfile
@@ -0,0 +1,16 @@
+source 'https://rubygems.org'
+
+group :development, :test do
+ gem 'rake', :require => false
+ gem 'rspec-puppet', :require => false
+ gem 'puppetlabs_spec_helper', :require => false
+ gem 'rspec-system', :require => false
+ gem 'rspec-system-puppet', :require => false
+ gem 'rspec-system-serverspec', :require => false
+end
+
+if puppetversion = ENV['PUPPET_GEM_VERSION']
+ gem 'puppet', puppetversion, :require => false
+else
+ gem 'puppet', :require => false
+end
diff --git a/puppet/modules/apt/Gemfile.lock b/puppet/modules/apt/Gemfile.lock
new file mode 100644
index 0000000..9932e16
--- /dev/null
+++ b/puppet/modules/apt/Gemfile.lock
@@ -0,0 +1,70 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ builder (3.2.2)
+ diff-lcs (1.2.4)
+ facter (1.6.18)
+ hiera (1.0.0)
+ highline (1.6.19)
+ kwalify (0.7.2)
+ metaclass (0.0.1)
+ mocha (0.14.0)
+ metaclass (~> 0.0.1)
+ net-scp (1.1.2)
+ net-ssh (>= 2.6.5)
+ net-ssh (2.7.0)
+ nokogiri (1.5.10)
+ puppet (3.0.2)
+ facter (~> 1.6.11)
+ hiera (~> 1.0.0)
+ puppetlabs_spec_helper (0.4.1)
+ mocha (>= 0.10.5)
+ rake
+ rspec (>= 2.9.0)
+ rspec-puppet (>= 0.1.1)
+ rake (10.1.0)
+ rbvmomi (1.6.0)
+ builder
+ nokogiri (>= 1.4.1)
+ trollop
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.5)
+ rspec-expectations (2.14.3)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.3)
+ rspec-puppet (0.1.6)
+ rspec
+ rspec-system (2.3.0)
+ kwalify (~> 0.7.2)
+ net-scp (~> 1.1)
+ net-ssh (~> 2.6)
+ nokogiri (~> 1.5.9)
+ rbvmomi (~> 1.6)
+ rspec (~> 2.13)
+ systemu (~> 2.5)
+ rspec-system-puppet (2.2.0)
+ rspec-system (~> 2.0)
+ rspec-system-serverspec (1.0.1)
+ rspec-system (~> 2.0)
+ serverspec (~> 0.0)
+ serverspec (0.10.5)
+ highline
+ net-ssh
+ rspec (>= 2.13.0)
+ systemu (2.5.2)
+ trollop (2.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ puppet (~> 3.0.0)
+ puppetlabs_spec_helper
+ rake
+ rspec-puppet
+ rspec-system
+ rspec-system-puppet
+ rspec-system-serverspec
diff --git a/puppet/modules/apt/LICENSE b/puppet/modules/apt/LICENSE
new file mode 100644
index 0000000..638c347
--- /dev/null
+++ b/puppet/modules/apt/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2011 Evolving Web Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/puppet/modules/apt/Modulefile b/puppet/modules/apt/Modulefile
new file mode 100644
index 0000000..72aa142
--- /dev/null
+++ b/puppet/modules/apt/Modulefile
@@ -0,0 +1,14 @@
+name 'puppetlabs-apt'
+version '1.4.0'
+source 'https://github.com/puppetlabs/puppetlabs-apt'
+author 'Evolving Web / Puppet Labs'
+license 'Apache License 2.0'
+summary 'Puppet Labs Apt Module'
+description 'APT Module for Puppet'
+project_page 'https://github.com/puppetlabs/puppetlabs-apt'
+
+## Add dependencies, if any:
+#dependency 'puppetlabs/stdlib', '2.x'
+# The dependency should be written as above but librarian-puppet
+# does not support the expression as the PMT does.
+dependency 'puppetlabs/stdlib', '>= 2.2.1'
diff --git a/puppet/modules/apt/README.md b/puppet/modules/apt/README.md
new file mode 100644
index 0000000..2ce5340
--- /dev/null
+++ b/puppet/modules/apt/README.md
@@ -0,0 +1,226 @@
+apt
+===
+
+[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-apt.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-apt)
+
+## Description
+Provides helpful definitions for dealing with Apt.
+=======
+Overview
+--------
+
+The APT module provides a simple interface for managing APT source, key, and definitions with Puppet.
+
+Module Description
+------------------
+
+APT automates obtaining and installing software packages on *nix systems.
+
+Setup
+-----
+
+**What APT affects:**
+
+* package/service/configuration files for APT
+* your system's `sources.list` file and `sources.list.d` directory
+ * NOTE: Setting the `purge_sources_list` and `purge_sources_list_d` parameters to 'true' will destroy any existing content that was not declared with Puppet. The default for these parameters is 'false'.
+* system repositories
+* authentication keys
+* wget (optional)
+
+###Beginning with APT
+
+To begin using the APT module with default parameters, declare the class
+
+ class { 'apt': }
+
+Puppet code that uses anything from the APT module requires that the core apt class be declared.
+
+Usage
+-----
+
+Using the APT module consists predominantly in declaring classes that provide desired functionality and features.
+
+###apt
+
+`apt` provides a number of common resources and options that are shared by the various defined types in this module, so you MUST always include this class in your manifests.
+
+The parameters for `apt` are not required in general and are predominantly for development environment use-cases.
+
+ class { 'apt':
+ always_apt_update => false,
+ disable_keys => undef,
+ proxy_host => false,
+ proxy_port => '8080',
+ purge_sources_list => false,
+ purge_sources_list_d => false,
+ purge_preferences_d => false,
+ update_timeout => undef
+ }
+
+Puppet will manage your system's `sources.list` file and `sources.list.d` directory but will do its best to respect existing content.
+
+If you declare your apt class with `purge_sources_list` and `purge_sources_list_d` set to 'true', Puppet will unapologetically purge any existing content it finds that wasn't declared with Puppet.
+
+###apt::builddep
+
+Installs the build depends of a specified package.
+
+ apt::builddep { 'glusterfs-server': }
+
+###apt::force
+
+Forces a package to be installed from a specific release. This class is particularly useful when using repositories, like Debian, that are unstable in Ubuntu.
+
+ apt::force { 'glusterfs-server':
+ release => 'unstable',
+ version => '3.0.3',
+ require => Apt::Source['debian_unstable'],
+ }
+
+###apt::key
+
+Adds a key to the list of keys used by APT to authenticate packages.
+
+ apt::key { 'puppetlabs':
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ }
+
+ apt::key { 'jenkins':
+ key => 'D50582E6',
+ key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
+ }
+
+Note that use of `key_source` requires wget to be installed and working.
+
+###apt::pin
+
+Adds an apt pin for a certain release.
+
+ apt::pin { 'karmic': priority => 700 }
+ apt::pin { 'karmic-updates': priority => 700 }
+ apt::pin { 'karmic-security': priority => 700 }
+
+Note you can also specifying more complex pins using distribution properties.
+
+ apt::pin { 'stable':
+ priority => -10,
+ originator => 'Debian',
+ release_version => '3.0',
+ component => 'main',
+ label => 'Debian'
+ }
+
+###apt::ppa
+
+Adds a ppa repository using `add-apt-repository`.
+
+ apt::ppa { 'ppa:drizzle-developers/ppa': }
+
+###apt::release
+
+Sets the default apt release. This class is particularly useful when using repositories, like Debian, that are unstable in Ubuntu.
+
+ class { 'apt::release':
+ release_id => 'precise',
+ }
+
+###apt::source
+
+Adds an apt source to `/etc/apt/sources.list.d/`.
+
+ apt::source { 'debian_unstable':
+ location => 'http://debian.mirror.iweb.ca/debian/',
+ release => 'unstable',
+ repos => 'main contrib non-free',
+ required_packages => 'debian-keyring debian-archive-keyring',
+ key => '55BE302B',
+ key_server => 'subkeys.pgp.net',
+ pin => '-10',
+ include_src => true
+ }
+
+If you would like to configure your system so the source is the Puppet Labs APT repository
+
+ apt::source { 'puppetlabs':
+ location => 'http://apt.puppetlabs.com',
+ repos => 'main',
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ }
+
+###Testing
+
+The APT module is mostly a collection of defined resource types, which provide reusable logic that can be leveraged to manage APT. It does provide smoke tests for testing functionality on a target system, as well as spec tests for checking a compiled catalog against an expected set of resources.
+
+####Example Test
+
+This test will set up a Puppet Labs apt repository. Start by creating a new smoke test in the apt module's test folder. Call it puppetlabs-apt.pp. Inside, declare a single resource representing the Puppet Labs APT source and gpg key
+
+ apt::source { 'puppetlabs':
+ location => 'http://apt.puppetlabs.com',
+ repos => 'main',
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ }
+
+This resource creates an apt source named puppetlabs and gives Puppet information about the repository's location and key used to sign its packages. Puppet leverages Facter to determine the appropriate release, but you can set it directly by adding the release type.
+
+Check your smoke test for syntax errors
+
+ $ puppet parser validate tests/puppetlabs-apt.pp
+
+If you receive no output from that command, it means nothing is wrong. Then apply the code
+
+ $ puppet apply --verbose tests/puppetlabs-apt.pp
+ notice: /Stage[main]//Apt::Source[puppetlabs]/File[puppetlabs.list]/ensure: defined content as '{md5}3be1da4923fb910f1102a233b77e982e'
+ info: /Stage[main]//Apt::Source[puppetlabs]/File[puppetlabs.list]: Scheduling refresh of Exec[puppetlabs apt update]
+ notice: /Stage[main]//Apt::Source[puppetlabs]/Exec[puppetlabs apt update]: Triggered 'refresh' from 1 events>
+
+The above example used a smoke test to easily lay out a resource declaration and apply it on your system. In production, you may want to declare your APT sources inside the classes where they’re needed.
+
+Implementation
+--------------
+
+###apt::backports
+
+Adds the necessary components to get backports for Ubuntu and Debian. The release name defaults to `$lsbdistcodename`. Setting this manually can cause undefined behavior (read: universe exploding).
+
+Limitations
+-----------
+
+This module should work across all versions of Debian/Ubuntu and support all major APT repository management features.
+
+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.
+
+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.
+
+You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing)
+
+Contributors
+------------
+
+A lot of great people have contributed to this module. A somewhat current list follows:
+
+* Ben Godfrey <ben.godfrey@wonga.com>
+* Branan Purvine-Riley <branan@puppetlabs.com>
+* Christian G. Warden <cwarden@xerus.org>
+* Dan Bode <bodepd@gmail.com> <dan@puppetlabs.com>
+* Garrett Honeycutt <github@garretthoneycutt.com>
+* Jeff Wallace <jeff@evolvingweb.ca> <jeff@tjwallace.ca>
+* Ken Barber <ken@bob.sh>
+* Matthaus Litteken <matthaus@puppetlabs.com> <mlitteken@gmail.com>
+* Matthias Pigulla <mp@webfactory.de>
+* Monty Taylor <mordred@inaugust.com>
+* Peter Drake <pdrake@allplayers.com>
+* Reid Vandewiele <marut@cat.pdx.edu>
+* Robert Navarro <rnavarro@phiivo.com>
+* Ryan Coleman <ryan@puppetlabs.com>
+* Scott McLeod <scott.mcleod@theice.com>
+* Spencer Krum <spencer@puppetlabs.com>
+* William Van Hevelingen <blkperl@cat.pdx.edu> <wvan13@gmail.com>
+* Zach Leslie <zach@puppetlabs.com>
diff --git a/puppet/modules/apt/Rakefile b/puppet/modules/apt/Rakefile
new file mode 100644
index 0000000..bb60173
--- /dev/null
+++ b/puppet/modules/apt/Rakefile
@@ -0,0 +1,2 @@
+require 'puppetlabs_spec_helper/rake_tasks'
+require 'rspec-system/rake_task'
diff --git a/puppet/modules/apt/manifests/backports.pp b/puppet/modules/apt/manifests/backports.pp
new file mode 100644
index 0000000..e9180c4
--- /dev/null
+++ b/puppet/modules/apt/manifests/backports.pp
@@ -0,0 +1,48 @@
+# This adds the necessary components to get backports for ubuntu and debian
+#
+# == Parameters
+#
+# [*release*]
+# The ubuntu/debian release name. Defaults to $lsbdistcodename. Setting this
+# manually can cause undefined behavior. (Read: universe exploding)
+#
+# == Examples
+#
+# include apt::backports
+#
+# class { 'apt::backports':
+# release => 'natty',
+# }
+#
+# == Authors
+#
+# Ben Hughes, I think. At least blame him if this goes wrong.
+# I just added puppet doc.
+#
+# == Copyright
+#
+# Copyright 2011 Puppet Labs Inc, unless otherwise noted.
+class apt::backports(
+ $release = $::lsbdistcodename,
+ $location = $apt::params::backports_location
+) inherits apt::params {
+
+ $release_real = downcase($release)
+ $key = $::lsbdistid ? {
+ 'debian' => '55BE302B',
+ 'ubuntu' => '437D05B5',
+ }
+ $repos = $::lsbdistid ? {
+ 'debian' => 'main contrib non-free',
+ 'ubuntu' => 'main universe multiverse restricted',
+ }
+
+ apt::source { 'backports':
+ location => $location,
+ release => "${release_real}-backports",
+ repos => $repos,
+ key => $key,
+ key_server => 'pgp.mit.edu',
+ pin => '200',
+ }
+}
diff --git a/puppet/modules/apt/manifests/builddep.pp b/puppet/modules/apt/manifests/builddep.pp
new file mode 100644
index 0000000..3294f71
--- /dev/null
+++ b/puppet/modules/apt/manifests/builddep.pp
@@ -0,0 +1,16 @@
+# builddep.pp
+
+define apt::builddep() {
+ include apt::update
+
+ exec { "apt-builddep-${name}":
+ command => "/usr/bin/apt-get -y --force-yes build-dep ${name}",
+ logoutput => 'on_failure',
+ notify => Exec['apt_update'],
+ }
+
+ # Need anchor to provide containment for dependencies.
+ anchor { "apt::builddep::${name}":
+ require => Class['apt::update'],
+ }
+}
diff --git a/puppet/modules/apt/manifests/conf.pp b/puppet/modules/apt/manifests/conf.pp
new file mode 100644
index 0000000..3c4cb19
--- /dev/null
+++ b/puppet/modules/apt/manifests/conf.pp
@@ -0,0 +1,18 @@
+define apt::conf (
+ $content,
+ $ensure = present,
+ $priority = '50'
+) {
+
+ include apt::params
+
+ $apt_conf_d = $apt::params::apt_conf_d
+
+ file { "${apt_conf_d}/${priority}${name}":
+ ensure => $ensure,
+ content => $content,
+ owner => root,
+ group => root,
+ mode => '0644',
+ }
+}
diff --git a/puppet/modules/apt/manifests/debian/testing.pp b/puppet/modules/apt/manifests/debian/testing.pp
new file mode 100644
index 0000000..4513347
--- /dev/null
+++ b/puppet/modules/apt/manifests/debian/testing.pp
@@ -0,0 +1,21 @@
+# testing.pp
+
+class apt::debian::testing {
+ include apt
+
+ # deb http://debian.mirror.iweb.ca/debian/ testing main contrib non-free
+ # deb-src http://debian.mirror.iweb.ca/debian/ testing main contrib non-free
+ # Key: 55BE302B Server: subkeys.pgp.net
+ # debian-keyring
+ # debian-archive-keyring
+
+ apt::source { 'debian_testing':
+ location => 'http://debian.mirror.iweb.ca/debian/',
+ release => 'testing',
+ repos => 'main contrib non-free',
+ required_packages => 'debian-keyring debian-archive-keyring',
+ key => '55BE302B',
+ key_server => 'subkeys.pgp.net',
+ pin => '-10',
+ }
+}
diff --git a/puppet/modules/apt/manifests/debian/unstable.pp b/puppet/modules/apt/manifests/debian/unstable.pp
new file mode 100644
index 0000000..401c9c5
--- /dev/null
+++ b/puppet/modules/apt/manifests/debian/unstable.pp
@@ -0,0 +1,21 @@
+# unstable.pp
+
+class apt::debian::unstable {
+ include apt
+
+ # deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
+ # deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
+ # Key: 55BE302B Server: subkeys.pgp.net
+ # debian-keyring
+ # debian-archive-keyring
+
+ apt::source { 'debian_unstable':
+ location => 'http://debian.mirror.iweb.ca/debian/',
+ release => 'unstable',
+ repos => 'main contrib non-free',
+ required_packages => 'debian-keyring debian-archive-keyring',
+ key => '55BE302B',
+ key_server => 'subkeys.pgp.net',
+ pin => '-10',
+ }
+}
diff --git a/puppet/modules/apt/manifests/force.pp b/puppet/modules/apt/manifests/force.pp
new file mode 100644
index 0000000..2d33e94
--- /dev/null
+++ b/puppet/modules/apt/manifests/force.pp
@@ -0,0 +1,24 @@
+# force.pp
+# force a package from a specific release
+
+define apt::force(
+ $release = 'testing',
+ $version = false,
+ $timeout = 300
+) {
+
+ $version_string = $version ? {
+ false => undef,
+ default => "=${version}",
+ }
+
+ $install_check = $version ? {
+ false => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'",
+ default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'",
+ }
+ exec { "/usr/bin/apt-get -y -t ${release} install ${name}${version_string}":
+ unless => $install_check,
+ logoutput => 'on_failure',
+ timeout => $timeout,
+ }
+}
diff --git a/puppet/modules/apt/manifests/init.pp b/puppet/modules/apt/manifests/init.pp
new file mode 100644
index 0000000..b106ad4
--- /dev/null
+++ b/puppet/modules/apt/manifests/init.pp
@@ -0,0 +1,121 @@
+# Class: apt
+#
+# This module manages the initial configuration of apt.
+#
+# Parameters:
+# The parameters listed here are not required in general and were
+# added for use cases related to development environments.
+# disable_keys - disables the requirement for all packages to be signed
+# always_apt_update - rather apt should be updated on every run (intended
+# for development environments where package updates are frequent)
+# purge_sources_list - Accepts true or false. Defaults to false If set to
+# true, Puppet will purge all unmanaged entries from sources.list
+# purge_sources_list_d - Accepts true or false. Defaults to false. If set
+# to true, Puppet will purge all unmanaged entries from sources.list.d
+# update_timeout - Overrides the exec timeout in seconds for apt-get update.
+# If not set defaults to Exec's default (300)
+#
+# Actions:
+#
+# Requires:
+# puppetlabs/stdlib
+# Sample Usage:
+# class { 'apt': }
+
+class apt(
+ $always_apt_update = false,
+ $disable_keys = undef,
+ $proxy_host = false,
+ $proxy_port = '8080',
+ $purge_sources_list = false,
+ $purge_sources_list_d = false,
+ $purge_preferences_d = false,
+ $update_timeout = undef
+) {
+
+ include apt::params
+ include apt::update
+
+ validate_bool($purge_sources_list, $purge_sources_list_d, $purge_preferences_d)
+
+ $sources_list_content = $purge_sources_list ? {
+ false => undef,
+ true => "# Repos managed by puppet.\n",
+ }
+
+ if $always_apt_update == true {
+ Exec <| title=='apt_update' |> {
+ refreshonly => false,
+ }
+ }
+
+ $root = $apt::params::root
+ $apt_conf_d = $apt::params::apt_conf_d
+ $sources_list_d = $apt::params::sources_list_d
+ $preferences_d = $apt::params::preferences_d
+ $provider = $apt::params::provider
+
+ file { 'sources.list':
+ ensure => present,
+ path => "${root}/sources.list",
+ owner => root,
+ group => root,
+ mode => '0644',
+ content => $sources_list_content,
+ notify => Exec['apt_update'],
+ }
+
+ file { 'sources.list.d':
+ ensure => directory,
+ path => $sources_list_d,
+ owner => root,
+ group => root,
+ purge => $purge_sources_list_d,
+ recurse => $purge_sources_list_d,
+ notify => Exec['apt_update'],
+ }
+
+ file { 'preferences.d':
+ ensure => directory,
+ path => $preferences_d,
+ owner => root,
+ group => root,
+ purge => $purge_preferences_d,
+ recurse => $purge_preferences_d,
+ }
+
+ case $disable_keys {
+ true: {
+ file { '99unauth':
+ ensure => present,
+ content => "APT::Get::AllowUnauthenticated 1;\n",
+ path => "${apt_conf_d}/99unauth",
+ }
+ }
+ false: {
+ file { '99unauth':
+ ensure => absent,
+ path => "${apt_conf_d}/99unauth",
+ }
+ }
+ undef: { } # do nothing
+ default: { fail('Valid values for disable_keys are true or false') }
+ }
+
+ $proxy_set = $proxy_host ? {
+ false => absent,
+ default => present
+ }
+
+ file { 'configure-apt-proxy':
+ ensure => $proxy_set,
+ path => "${apt_conf_d}/proxy",
+ content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
+ notify => Exec['apt_update'],
+ }
+
+ # Need anchor to provide containment for dependencies.
+ anchor { 'apt::update':
+ require => Class['apt::update'],
+ }
+}
diff --git a/puppet/modules/apt/manifests/key.pp b/puppet/modules/apt/manifests/key.pp
new file mode 100644
index 0000000..c78bf65
--- /dev/null
+++ b/puppet/modules/apt/manifests/key.pp
@@ -0,0 +1,90 @@
+define apt::key (
+ $key = $title,
+ $ensure = present,
+ $key_content = false,
+ $key_source = false,
+ $key_server = 'keyserver.ubuntu.com',
+ $key_options = false
+) {
+
+ include apt::params
+
+ $upkey = upcase($key)
+ # trim the key to the last 8 chars so we can match longer keys with apt-key list too
+ $trimmedkey = regsubst($upkey, '^.*(.{8})$', '\1')
+
+ if $key_content {
+ $method = 'content'
+ } elsif $key_source {
+ $method = 'source'
+ } elsif $key_server {
+ $method = 'server'
+ }
+
+ # This is a hash of the parts of the key definition that we care about.
+ # It is used as a unique identifier for this instance of apt::key. It gets
+ # hashed to ensure that the resource name doesn't end up being pages and
+ # pages (e.g. in the situation where key_content is specified).
+ $digest = sha1("${upkey}/${key_content}/${key_source}/${key_server}/")
+
+ # Allow multiple ensure => present for the same key to account for many
+ # apt::source resources that all reference the same key.
+ case $ensure {
+ present: {
+
+ anchor { "apt::key/${title}": }
+
+ if defined(Exec["apt::key ${upkey} absent"]) {
+ fail("Cannot ensure Apt::Key[${upkey}] present; ${upkey} already ensured absent")
+ }
+
+ if !defined(Anchor["apt::key ${upkey} present"]) {
+ anchor { "apt::key ${upkey} present": }
+ }
+
+ if $key_options{
+ $options_string = "--keyserver-options ${key_options}"
+ }
+ else{
+ $options_string = ''
+ }
+
+ if !defined(Exec[$digest]) {
+ $digest_command = $method ? {
+ 'content' => "echo '${key_content}' | /usr/bin/apt-key add -",
+ 'source' => "wget -q '${key_source}' -O- | apt-key add -",
+ 'server' => "apt-key adv --keyserver '${key_server}' ${options_string} --recv-keys '${upkey}'",
+ }
+ exec { $digest:
+ command => $digest_command,
+ path => '/bin:/usr/bin',
+ unless => "/usr/bin/apt-key list | /bin/grep '${trimmedkey}'",
+ logoutput => 'on_failure',
+ before => Anchor["apt::key ${upkey} present"],
+ }
+ }
+
+ Anchor["apt::key ${upkey} present"] -> Anchor["apt::key/${title}"]
+
+ }
+ absent: {
+
+ if defined(Anchor["apt::key ${upkey} present"]) {
+ fail("Cannot ensure Apt::Key[${upkey}] absent; ${upkey} already ensured present")
+ }
+
+ exec { "apt::key ${upkey} absent":
+ command => "apt-key del '${upkey}'",
+ path => '/bin:/usr/bin',
+ onlyif => "apt-key list | grep '${trimmedkey}'",
+ user => 'root',
+ group => 'root',
+ logoutput => 'on_failure',
+ }
+ }
+
+ default: {
+ fail "Invalid 'ensure' value '${ensure}' for aptkey"
+ }
+ }
+}
diff --git a/puppet/modules/apt/manifests/params.pp b/puppet/modules/apt/manifests/params.pp
new file mode 100644
index 0000000..955954f
--- /dev/null
+++ b/puppet/modules/apt/manifests/params.pp
@@ -0,0 +1,33 @@
+class apt::params {
+ $root = '/etc/apt'
+ $provider = '/usr/bin/apt-get'
+ $sources_list_d = "${root}/sources.list.d"
+ $apt_conf_d = "${root}/apt.conf.d"
+ $preferences_d = "${root}/preferences.d"
+
+ case $::lsbdistid {
+ 'debian': {
+ case $::lsbdistcodename {
+ 'squeeze': {
+ $backports_location = 'http://backports.debian.org/debian-backports'
+ }
+ 'wheezy': {
+ $backports_location = 'http://ftp.debian.org/debian/'
+ }
+ default: {
+ $backports_location = 'http://http.debian.net/debian/'
+ }
+ }
+ }
+ 'ubuntu': {
+ case $::lsbdistcodename {
+ 'hardy','lucid','maverick','natty','oneiric','precise': {
+ $backports_location = 'http://us.archive.ubuntu.com/ubuntu'
+ }
+ default: {
+ $backports_location = 'http://old-releases.ubuntu.com/ubuntu'
+ }
+ }
+ }
+ }
+}
diff --git a/puppet/modules/apt/manifests/pin.pp b/puppet/modules/apt/manifests/pin.pp
new file mode 100644
index 0000000..402e79e
--- /dev/null
+++ b/puppet/modules/apt/manifests/pin.pp
@@ -0,0 +1,73 @@
+# pin.pp
+# pin a release in apt, useful for unstable repositories
+
+define apt::pin(
+ $ensure = present,
+ $explanation = "${::caller_module_name}: ${name}",
+ $order = '',
+ $packages = '*',
+ $priority = 0,
+ $release = '', # a=
+ $origin = '',
+ $version = '',
+ $codename = '', # n=
+ $release_version = '', # v=
+ $component = '', # c=
+ $originator = '', # o=
+ $label = '' # l=
+) {
+
+ include apt::params
+
+ $preferences_d = $apt::params::preferences_d
+
+ if $order != '' and !is_integer($order) {
+ fail('Only integers are allowed in the apt::pin order param')
+ }
+
+ $pin_release_array = [
+ $release,
+ $codename,
+ $release_version,
+ $component,
+ $originator,
+ $label]
+ $pin_release = join($pin_release_array, '')
+
+ # Read the manpage 'apt_preferences(5)', especially the chapter
+ # 'Thea Effect of APT Preferences' to understand the following logic
+ # and the difference between specific and general form
+ if $packages != '*' { # specific form
+
+ if ( $pin_release != '' and ( $origin != '' or $version != '' )) or
+ ( $origin != '' and ( $pin_release != '' or $version != '' )) or
+ ( $version != '' and ( $pin_release != '' or $origin != '' )) {
+ fail('parameters release, origin, and version are mutually exclusive')
+ }
+
+ } else { # general form
+
+ if $version != '' {
+ fail('parameter version cannot be used in general form')
+ }
+
+ if ( $pin_release != '' and $origin != '' ) or
+ ( $origin != '' and $pin_release != '' ) {
+ fail('parmeters release and origin are mutually exclusive')
+ }
+
+ }
+
+ $path = $order ? {
+ '' => "${preferences_d}/${name}.pref",
+ default => "${preferences_d}/${order}-${name}.pref",
+ }
+ file { "${name}.pref":
+ ensure => $ensure,
+ path => $path,
+ owner => root,
+ group => root,
+ mode => '0644',
+ content => template('apt/pin.pref.erb'),
+ }
+}
diff --git a/puppet/modules/apt/manifests/ppa.pp b/puppet/modules/apt/manifests/ppa.pp
new file mode 100644
index 0000000..7cb88c8
--- /dev/null
+++ b/puppet/modules/apt/manifests/ppa.pp
@@ -0,0 +1,63 @@
+# ppa.pp
+
+define apt::ppa(
+ $release = $::lsbdistcodename,
+ $options = '-y'
+) {
+ include apt::params
+ include apt::update
+
+ $sources_list_d = $apt::params::sources_list_d
+
+ if ! $release {
+ fail('lsbdistcodename fact not available: release parameter required')
+ }
+
+ $filename_without_slashes = regsubst($name, '/', '-', 'G')
+ $filename_without_dots = regsubst($filename_without_slashes, '\.', '_', 'G')
+ $filename_without_ppa = regsubst($filename_without_dots, '^ppa:', '', 'G')
+ $sources_list_d_filename = "${filename_without_ppa}-${release}.list"
+
+ $package = $::lsbdistrelease ? {
+ /^[1-9]\..*|1[01]\..*|12.04$/ => 'python-software-properties',
+ default => 'software-properties-common',
+ }
+
+ if ! defined(Package[$package]) {
+ package { $package: }
+ }
+
+ if defined(Class[apt]) {
+ $proxy_host = getparam(Class[apt], 'proxy_host')
+ $proxy_port = getparam(Class[apt], 'proxy_port')
+ case $proxy_host {
+ false, '': {
+ $proxy_env = []
+ }
+ default: {$proxy_env = ["http_proxy=http://${proxy_host}:${proxy_port}", "https_proxy=http://${proxy_host}:${proxy_port}"]}
+ }
+ } else {
+ $proxy_env = []
+ }
+ exec { "add-apt-repository-${name}":
+ environment => $proxy_env,
+ command => "/usr/bin/add-apt-repository ${options} ${name}",
+ unless => "/usr/bin/test -s ${sources_list_d}/${sources_list_d_filename}",
+ logoutput => 'on_failure',
+ notify => Exec['apt_update'],
+ require => [
+ File[$sources_list_d],
+ Package[$package],
+ ],
+ }
+
+ file { "${sources_list_d}/${sources_list_d_filename}":
+ ensure => file,
+ require => Exec["add-apt-repository-${name}"],
+ }
+
+ # Need anchor to provide containment for dependencies.
+ anchor { "apt::ppa::${name}":
+ require => Class['apt::update'],
+ }
+}
diff --git a/puppet/modules/apt/manifests/release.pp b/puppet/modules/apt/manifests/release.pp
new file mode 100644
index 0000000..6e0a38f
--- /dev/null
+++ b/puppet/modules/apt/manifests/release.pp
@@ -0,0 +1,17 @@
+# release.pp
+
+class apt::release (
+ $release_id
+) {
+
+ include apt::params
+
+ $root = $apt::params::root
+
+ file { "${root}/apt.conf.d/01release":
+ owner => root,
+ group => root,
+ mode => '0644',
+ content => "APT::Default-Release \"${release_id}\";"
+ }
+}
diff --git a/puppet/modules/apt/manifests/source.pp b/puppet/modules/apt/manifests/source.pp
new file mode 100644
index 0000000..713c7e9
--- /dev/null
+++ b/puppet/modules/apt/manifests/source.pp
@@ -0,0 +1,85 @@
+# source.pp
+# add an apt source
+
+define apt::source(
+ $ensure = present,
+ $location = '',
+ $release = 'UNDEF',
+ $repos = 'main',
+ $include_src = true,
+ $required_packages = false,
+ $key = false,
+ $key_server = 'keyserver.ubuntu.com',
+ $key_content = false,
+ $key_source = false,
+ $pin = false,
+ $architecture = undef
+) {
+
+ include apt::params
+ include apt::update
+
+ $sources_list_d = $apt::params::sources_list_d
+ $provider = $apt::params::provider
+
+ if $release == 'UNDEF' {
+ if $::lsbdistcodename == undef {
+ fail('lsbdistcodename fact not available: release parameter required')
+ } else {
+ $release_real = $::lsbdistcodename
+ }
+ } else {
+ $release_real = $release
+ }
+
+ file { "${name}.list":
+ ensure => $ensure,
+ path => "${sources_list_d}/${name}.list",
+ owner => root,
+ group => root,
+ mode => '0644',
+ content => template("${module_name}/source.list.erb"),
+ notify => Exec['apt_update'],
+ }
+
+
+ if ($pin != false) {
+ # Get the host portion out of the url so we can pin to origin
+ $url_split = split($location, '/')
+ $host = $url_split[2]
+
+ apt::pin { $name:
+ ensure => $ensure,
+ priority => $pin,
+ before => File["${name}.list"],
+ origin => $host,
+ }
+ }
+
+ if ($required_packages != false) and ($ensure == 'present') {
+ exec { "Required packages: '${required_packages}' for ${name}":
+ command => "${provider} -y install ${required_packages}",
+ logoutput => 'on_failure',
+ refreshonly => true,
+ subscribe => File["${name}.list"],
+ before => Exec['apt_update'],
+ }
+ }
+
+ # We do not want to remove keys when the source is absent.
+ if ($key != false) and ($ensure == 'present') {
+ apt::key { "Add key: ${key} from Apt::Source ${title}":
+ ensure => present,
+ key => $key,
+ key_server => $key_server,
+ key_content => $key_content,
+ key_source => $key_source,
+ before => File["${name}.list"],
+ }
+ }
+
+ # Need anchor to provide containment for dependencies.
+ anchor { "apt::source::${name}":
+ require => Class['apt::update'],
+ }
+}
diff --git a/puppet/modules/apt/manifests/unattended_upgrades.pp b/puppet/modules/apt/manifests/unattended_upgrades.pp
new file mode 100644
index 0000000..f006bd5
--- /dev/null
+++ b/puppet/modules/apt/manifests/unattended_upgrades.pp
@@ -0,0 +1,68 @@
+# Class: apt::unattended_upgrades
+#
+# This class manages the unattended-upgrades package and related configuration
+# files for ubuntu
+#
+# origins are the repositories to automatically upgrade included packages
+# blacklist is a list of packages to not automatically upgrade
+# update is how often to run "apt-get update" in days
+# download is how often to run "apt-get upgrade --download-only" in days
+# upgrade is how often to upgrade packages included in the origins list in days
+# autoclean is how often to run "apt-get autoclean" in days
+#
+# information on the other options can be found in the 50unattended-upgrades
+# file and in /etc/cron.daily/apt
+#
+class apt::unattended_upgrades (
+ $origins = ['${distro_id}:${distro_codename}-security'],
+ $blacklist = [],
+ $update = "1",
+ $download = "1",
+ $upgrade = "1",
+ $autoclean = "7",
+ $auto_fix = true,
+ $minimal_steps = false,
+ $install_on_shutdown = false,
+ $mail_to = "NONE",
+ $mail_only_on_error = false,
+ $remove_unused = true,
+ $auto_reboot = false,
+ $dl_limit = "NONE",
+ $enable = "1",
+ $backup_interval = "0",
+ $backup_level = "3",
+ $max_age = "0",
+ $min_age = "0",
+ $max_size = "0",
+ $download_delta = "0",
+ $verbose = "0",
+) {
+
+ validate_bool(
+ $auto_fix,
+ $minimal_steps,
+ $install_on_shutdown,
+ $mail_only_on_error,
+ $remove_unused,
+ $auto_reboot
+ )
+
+ package { 'unattended-upgrades':
+ ensure => present,
+ }
+
+ File {
+ ensure => file,
+ owner => 'root',
+ group => 'root',
+ mode => '0644',
+ require => Package['unattended-upgrades'],
+ }
+
+ file {
+ '/etc/apt/apt.conf.d/50unattended-upgrades':
+ content => template('apt/50unattended-upgrades.erb');
+ '/etc/apt/apt.conf.d/10periodic':
+ content => template('apt/10periodic.erb');
+ }
+}
diff --git a/puppet/modules/apt/manifests/update.pp b/puppet/modules/apt/manifests/update.pp
new file mode 100644
index 0000000..ce0b78f
--- /dev/null
+++ b/puppet/modules/apt/manifests/update.pp
@@ -0,0 +1,10 @@
+class apt::update {
+ include apt::params
+
+ exec { 'apt_update':
+ command => "${apt::params::provider} update",
+ logoutput => 'on_failure',
+ refreshonly => true,
+ timeout => $apt::update_timeout,
+ }
+}
diff --git a/puppet/modules/apt/metadata.json b/puppet/modules/apt/metadata.json
new file mode 100644
index 0000000..3e4c992
--- /dev/null
+++ b/puppet/modules/apt/metadata.json
@@ -0,0 +1,87 @@
+{
+ "name": "puppetlabs-apt",
+ "version": "1.4.0",
+ "summary": "Puppet Labs Apt Module",
+ "author": "Evolving Web / Puppet Labs",
+ "description": "APT Module for Puppet",
+ "dependencies": [
+ {
+ "name": "puppetlabs/stdlib",
+ "version_requirement": "\u003e\u003d 2.2.1"
+ }
+ ],
+ "types": [],
+ "checksums": {
+ ".bundle/config": "7f1c988748783d2a8d455376eed1470c",
+ ".fixtures.yml": "0c43f56b0bb8e8d04e8051a0e7aa37a5",
+ ".forge-release/pom.xml": "c650a84961ad88de03192e23b63b3549",
+ ".forge-release/publish": "1c1d6dd64ef52246db485eb5459aa941",
+ ".forge-release/settings.xml": "06d768a57d582fe1ee078b563427e750",
+ ".forge-release/validate": "7fffde8112f42a1ec986d49ba80ac219",
+ ".nodeset.yml": "78d78c172336a387a1067464434ffbcb",
+ ".travis.yml": "782420dcc9d6412c79c30f03b1f3613c",
+ "CHANGELOG": "f5488e1e891a8f8c47143dac790ddab3",
+ "Gemfile": "1bfa7eb6e30346c9ddb4a8b144b0d255",
+ "Gemfile.lock": "8ff8bc3d32bb7412bd97e48190a93b2f",
+ "LICENSE": "20bcc606fc61ffba2b8cea840e8dce4d",
+ "Modulefile": "b34e93626fbc137cbb651952e7509839",
+ "README.md": "65176b395f7202fe5d222ae7b0de4e05",
+ "Rakefile": "0428ea3759a4692c91604396c406a9c1",
+ "manifests/backports.pp": "09f1d86603d0f44a2169acb3eeea2a70",
+ "manifests/builddep.pp": "4f313b5140c84aa7d5793b5a073c30dd",
+ "manifests/conf.pp": "5ddf258195d414d93284dfd281a8d6e3",
+ "manifests/debian/testing.pp": "aeb625bacb6a8df46c864ee9ee1cb5a5",
+ "manifests/debian/unstable.pp": "108038596b05dc1d28975884693f73f5",
+ "manifests/force.pp": "cf871e869f4114f32ab164de2a67e7e2",
+ "manifests/init.pp": "5ec106a7a03313c544159a9a1f6b78e6",
+ "manifests/key.pp": "3cf082ed91a3933ab7218d1be3464f4f",
+ "manifests/params.pp": "ca4ce3730a65c43f884ab3e6445f1661",
+ "manifests/pin.pp": "dea8cbaabc37010ce25838080608802b",
+ "manifests/ppa.pp": "754a83944ae79b5001fc0c0a8c775985",
+ "manifests/release.pp": "427f3ee70a6a1e55fa291e58655bd5d9",
+ "manifests/source.pp": "6eab8d33c173a066f5dec8474efdedb6",
+ "manifests/unattended_upgrades.pp": "e97f908b42010ff9a85be4afd2c721ab",
+ "manifests/update.pp": "436c79f160f2cb603710795a9ec71ac7",
+ "spec/classes/apt_spec.rb": "54841b04b42026770ed6d744a82c55df",
+ "spec/classes/backports_spec.rb": "7d2454a881cc26edd3dcd3acb7ffd20f",
+ "spec/classes/debian_testing_spec.rb": "fad1384cb9d3c99b2663d7df4762dc0e",
+ "spec/classes/debian_unstable_spec.rb": "11131efffd18db3c96e2bbe3d98a2fb7",
+ "spec/classes/params_spec.rb": "a25396d3f0bbac784a7951f03ad7e8f4",
+ "spec/classes/release_spec.rb": "d8f01a3cf0c2f6f6952b835196163ce4",
+ "spec/classes/unattended_upgrades_spec.rb": "a2e206bda79d24cdb43312d035eff66f",
+ "spec/defines/builddep_spec.rb": "e1300bb4f3abbd34029b11d8b733a6e5",
+ "spec/defines/conf_spec.rb": "b7fc9fb6cb270c276aacbfa4a43f228c",
+ "spec/defines/force_spec.rb": "97098c5b123be49e321e71cda288fe53",
+ "spec/defines/key_spec.rb": "7800c30647b1ddf799b991110109cba0",
+ "spec/defines/pin_spec.rb": "c912e59e9e3d1145280d659cccabe72b",
+ "spec/defines/ppa_spec.rb": "72ce037a1d6ea0a33f369b1f3d98b3d6",
+ "spec/defines/source_spec.rb": "e553bb9598dbe2becba6ae7f91d4deb0",
+ "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc",
+ "spec/spec_helper_system.rb": "e67d2574baae312f1095f90d78fdf5e9",
+ "spec/system/apt_builddep_spec.rb": "97be5a48d2d16d96cb7c35ccdbcdcb69",
+ "spec/system/apt_key_spec.rb": "098835d0c53c69390d4c3b6ea8ef3815",
+ "spec/system/apt_ppa_spec.rb": "c96f6d0bbdafac39beaf0d5e6eba9010",
+ "spec/system/apt_source_spec.rb": "df5aa98b03688884903c564bb507469f",
+ "spec/system/basic_spec.rb": "0a5b33d18254bedcb7886e34846ebff6",
+ "spec/system/class_spec.rb": "2ba4265236f00685c23cb00f908defc1",
+ "templates/10periodic.erb": "2aeea866a39f19a62254abbb4f1bc59d",
+ "templates/50unattended-upgrades.erb": "ae995ade214fdaefab51d335c85819ae",
+ "templates/pin.pref.erb": "623249839cee7788fa0805a3474396db",
+ "templates/source.list.erb": "65a016e60daf065c481f3d5f2c883324",
+ "tests/builddep.pp": "4773f57072111e58f2ed833fa4489a88",
+ "tests/debian/testing.pp": "1cbee56baddd6a91d981db8fddec70fb",
+ "tests/debian/unstable.pp": "4b2a090afeb315752262386f4dbcd8ca",
+ "tests/force.pp": "2bb6cf0b3d655cb51f95aeb79035e600",
+ "tests/init.pp": "551138eb704e71ab3687932dda429a81",
+ "tests/key.pp": "371a695e1332d51a38e283a87be52798",
+ "tests/params.pp": "900db40f3fc84b0be173278df2ebff35",
+ "tests/pin.pp": "4b4c3612d75a19dba8eb7227070fa4ab",
+ "tests/ppa.pp": "b902cce8159128b5e8b21bed540743ff",
+ "tests/release.pp": "53ce5debe6fa5bee42821767599cc768",
+ "tests/source.pp": "9cecd9aa0dcde250fe49be9e26971a98",
+ "tests/unattended-upgrades.pp": "cdc853f1b58e5206c5a538621ddca161"
+ },
+ "source": "https://github.com/puppetlabs/puppetlabs-apt",
+ "project_page": "https://github.com/puppetlabs/puppetlabs-apt",
+ "license": "Apache License 2.0"
+}
\ No newline at end of file
diff --git a/puppet/modules/apt/spec/classes/apt_spec.rb b/puppet/modules/apt/spec/classes/apt_spec.rb
new file mode 100644
index 0000000..a66feac
--- /dev/null
+++ b/puppet/modules/apt/spec/classes/apt_spec.rb
@@ -0,0 +1,133 @@
+require 'spec_helper'
+describe 'apt', :type => :class do
+ let :default_params do
+ {
+ :disable_keys => :undef,
+ :always_apt_update => false,
+ :purge_sources_list => false,
+ :purge_sources_list_d => false,
+ }
+ end
+
+ [{},
+ {
+ :disable_keys => true,
+ :always_apt_update => true,
+ :proxy_host => true,
+ :proxy_port => '3128',
+ :purge_sources_list => true,
+ :purge_sources_list_d => true,
+ },
+ {
+ :disable_keys => false
+ }
+ ].each do |param_set|
+ describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
+ let :param_hash do
+ default_params.merge(param_set)
+ end
+
+ let :params do
+ param_set
+ end
+
+ let :refresh_only_apt_update do
+ if param_hash[:always_apt_update]
+ false
+ else
+ true
+ end
+ end
+
+ it { should include_class("apt::params") }
+
+ it {
+ if param_hash[:purge_sources_list]
+ should contain_file("sources.list").with({
+ 'path' => "/etc/apt/sources.list",
+ 'ensure' => "present",
+ 'owner' => "root",
+ 'group' => "root",
+ 'mode' => "0644",
+ "content" => "# Repos managed by puppet.\n"
+ })
+ else
+ should contain_file("sources.list").with({
+ 'path' => "/etc/apt/sources.list",
+ 'ensure' => "present",
+ 'owner' => "root",
+ 'group' => "root",
+ 'mode' => "0644",
+ 'content' => nil
+ })
+ end
+ }
+ it {
+ if param_hash[:purge_sources_list_d]
+ should create_file("sources.list.d").with({
+ 'path' => "/etc/apt/sources.list.d",
+ 'ensure' => "directory",
+ 'owner' => "root",
+ 'group' => "root",
+ 'purge' => true,
+ 'recurse' => true,
+ 'notify' => 'Exec[apt_update]'
+ })
+ else
+ should create_file("sources.list.d").with({
+ 'path' => "/etc/apt/sources.list.d",
+ 'ensure' => "directory",
+ 'owner' => "root",
+ 'group' => "root",
+ 'purge' => false,
+ 'recurse' => false,
+ 'notify' => 'Exec[apt_update]'
+ })
+ end
+ }
+
+ it {
+ should contain_exec("apt_update").with({
+ 'command' => "/usr/bin/apt-get update",
+ 'refreshonly' => refresh_only_apt_update
+ })
+ }
+
+ it {
+ if param_hash[:disable_keys] == true
+ should create_file("99unauth").with({
+ 'content' => "APT::Get::AllowUnauthenticated 1;\n",
+ 'ensure' => "present",
+ 'path' => "/etc/apt/apt.conf.d/99unauth"
+ })
+ elsif param_hash[:disable_keys] == false
+ should create_file("99unauth").with({
+ 'ensure' => "absent",
+ 'path' => "/etc/apt/apt.conf.d/99unauth"
+ })
+ elsif param_hash[:disable_keys] != :undef
+ should_not create_file("99unauth").with({
+ 'path' => "/etc/apt/apt.conf.d/99unauth"
+ })
+ end
+ }
+ describe 'when setting a proxy' do
+ it {
+ if param_hash[:proxy_host]
+ should contain_file('configure-apt-proxy').with(
+ 'path' => '/etc/apt/apt.conf.d/proxy',
+ 'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";",
+ 'notify' => "Exec[apt_update]"
+ )
+ else
+ should contain_file('configure-apt-proxy').with(
+ 'path' => '/etc/apt/apt.conf.d/proxy',
+ 'notify' => 'Exec[apt_update]',
+ 'ensure' => 'absent'
+ )
+ end
+ }
+ end
+ end
+ end
+end
diff --git a/puppet/modules/apt/spec/classes/backports_spec.rb b/puppet/modules/apt/spec/classes/backports_spec.rb
new file mode 100644
index 0000000..27c6708
--- /dev/null
+++ b/puppet/modules/apt/spec/classes/backports_spec.rb
@@ -0,0 +1,71 @@
+require 'spec_helper'
+describe 'apt::backports', :type => :class do
+
+ describe 'when turning on backports for ubuntu karmic' do
+
+ let :facts do
+ {
+ 'lsbdistcodename' => 'Karmic',
+ 'lsbdistid' => 'Ubuntu'
+ }
+ end
+
+ it { should contain_apt__source('backports').with({
+ 'location' => 'http://old-releases.ubuntu.com/ubuntu',
+ 'release' => 'karmic-backports',
+ 'repos' => 'main universe multiverse restricted',
+ 'key' => '437D05B5',
+ 'key_server' => 'pgp.mit.edu',
+ 'pin' => '200',
+ })
+ }
+ end
+
+ describe "when turning on backports for debian squeeze" do
+
+ let :facts do
+ {
+ 'lsbdistcodename' => 'Squeeze',
+ 'lsbdistid' => 'Debian',
+ }
+ end
+
+ it { should contain_apt__source('backports').with({
+ 'location' => 'http://backports.debian.org/debian-backports',
+ 'release' => 'squeeze-backports',
+ 'repos' => 'main contrib non-free',
+ 'key' => '55BE302B',
+ 'key_server' => 'pgp.mit.edu',
+ 'pin' => '200',
+ })
+ }
+ end
+
+ describe "when turning on backports for debian squeeze but using your own mirror" do
+
+ let :facts do
+ {
+ 'lsbdistcodename' => 'Squeeze',
+ 'lsbdistid' => 'Debian'
+ }
+ end
+
+ let :location do
+ 'http://mirrors.example.com/debian-backports'
+ end
+
+ let :params do
+ { 'location' => location }
+ end
+
+ it { should contain_apt__source('backports').with({
+ 'location' => location,
+ 'release' => 'squeeze-backports',
+ 'repos' => 'main contrib non-free',
+ 'key' => '55BE302B',
+ 'key_server' => 'pgp.mit.edu',
+ 'pin' => '200',
+ })
+ }
+ end
+end
diff --git a/puppet/modules/apt/spec/classes/debian_testing_spec.rb b/puppet/modules/apt/spec/classes/debian_testing_spec.rb
new file mode 100644
index 0000000..6006afb
--- /dev/null
+++ b/puppet/modules/apt/spec/classes/debian_testing_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+describe 'apt::debian::testing', :type => :class do
+ it {
+ should contain_apt__source("debian_testing").with({
+ "location" => "http://debian.mirror.iweb.ca/debian/",
+ "release" => "testing",
+ "repos" => "main contrib non-free",
+ "required_packages" => "debian-keyring debian-archive-keyring",
+ "key" => "55BE302B",
+ "key_server" => "subkeys.pgp.net",
+ "pin" => "-10"
+ })
+ }
+end
diff --git a/puppet/modules/apt/spec/classes/debian_unstable_spec.rb b/puppet/modules/apt/spec/classes/debian_unstable_spec.rb
new file mode 100644
index 0000000..411182d
--- /dev/null
+++ b/puppet/modules/apt/spec/classes/debian_unstable_spec.rb
@@ -0,0 +1,14 @@
+require 'spec_helper'
+describe 'apt::debian::unstable', :type => :class do
+ it {
+ should contain_apt__source("debian_unstable").with({
+ "location" => "http://debian.mirror.iweb.ca/debian/",
+ "release" => "unstable",
+ "repos" => "main contrib non-free",
+ "required_packages" => "debian-keyring debian-archive-keyring",
+ "key" => "55BE302B",
+ "key_server" => "subkeys.pgp.net",
+ "pin" => "-10"
+ })
+ }
+end
diff --git a/puppet/modules/apt/spec/classes/params_spec.rb b/puppet/modules/apt/spec/classes/params_spec.rb
new file mode 100644
index 0000000..f2790b0
--- /dev/null
+++ b/puppet/modules/apt/spec/classes/params_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper'
+describe 'apt::params', :type => :class do
+ let (:title) { 'my_package' }
+
+ it { should contain_apt__params }
+
+ # There are 4 resources in this class currently
+ # there should not be any more resources because it is a params class
+ # The resources are class[apt::params], class[main], class[settings], stage[main]
+ it "Should not contain any resources" do
+ subject.resources.size.should == 4
+ end
+end
diff --git a/puppet/modules/apt/spec/classes/release_spec.rb b/puppet/modules/apt/spec/classes/release_spec.rb
new file mode 100644
index 0000000..d131b22
--- /dev/null
+++ b/puppet/modules/apt/spec/classes/release_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+describe 'apt::release', :type => :class do
+ let (:title) { 'my_package' }
+
+ let :param_set do
+ { :release_id => 'precise' }
+ end
+
+ let (:params) { param_set }
+
+ it { should include_class("apt::params") }
+
+ it {
+ should contain_file("/etc/apt/apt.conf.d/01release").with({
+ "mode" => "0644",
+ "owner" => "root",
+ "group" => "root",
+ "content" => "APT::Default-Release \"#{param_set[:release_id]}\";"
+ })
+ }
+end
+
diff --git a/puppet/modules/apt/spec/classes/unattended_upgrades_spec.rb b/puppet/modules/apt/spec/classes/unattended_upgrades_spec.rb
new file mode 100644
index 0000000..8abc603
--- /dev/null
+++ b/puppet/modules/apt/spec/classes/unattended_upgrades_spec.rb
@@ -0,0 +1,204 @@
+require 'spec_helper'
+describe 'apt::unattended_upgrades', :type => :class do
+ let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' }
+ let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' }
+
+ it { should contain_package("unattended-upgrades") }
+
+ it {
+ should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({
+ "owner" => "root",
+ "group" => "root",
+ "mode" => "0644",
+ "require" => "Package[unattended-upgrades]",
+ })
+ }
+
+ it {
+ should create_file("/etc/apt/apt.conf.d/10periodic").with({
+ "owner" => "root",
+ "group" => "root",
+ "mode" => "0644",
+ "require" => "Package[unattended-upgrades]",
+ })
+ }
+
+ describe "origins" do
+ describe "with param defaults" do
+ let(:params) {{ }}
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"\${distro_id}:\${distro_codename}-security";\n\};$/) }
+ end
+
+ describe "with origins => ['ubuntu:precise-security']" do
+ let :params do
+ { :origins => ['ubuntu:precise-security'] }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"ubuntu:precise-security";\n\};$/) }
+ end
+ end
+
+ describe "blacklist" do
+ describe "with param defaults" do
+ let(:params) {{ }}
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
+ end
+
+ describe "with blacklist => []" do
+ let :params do
+ { :blacklist => ['libc6', 'libc6-dev'] }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
+ end
+ end
+
+ describe "with update => 2" do
+ let :params do
+ { :update => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
+ end
+
+ describe "with download => 2" do
+ let :params do
+ { :download => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
+ end
+
+ describe "with upgrade => 2" do
+ let :params do
+ { :upgrade => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
+ end
+
+ describe "with autoclean => 2" do
+ let :params do
+ { :autoclean => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
+ end
+
+ describe "with auto_fix => false" do
+ let :params do
+ { :auto_fix => false }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
+ end
+
+ describe "with minimal_steps => true" do
+ let :params do
+ { :minimal_steps => true }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
+ end
+
+ describe "with install_on_shutdown => true" do
+ let :params do
+ { :install_on_shutdown => true }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
+ end
+
+ describe "mail_to" do
+ describe "param defaults" do
+ let(:params) {{ }}
+ it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
+ it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
+ end
+
+ describe "with mail_to => user@website, mail_only_on_error => true" do
+ let :params do
+ { :mail_to => "user@website",
+ :mail_only_on_error => true }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
+ end
+ end
+
+ describe "with remove_unused => false" do
+ let :params do
+ { :remove_unused => false }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
+ end
+
+ describe "with auto_reboot => true" do
+ let :params do
+ { :auto_reboot => true }
+ end
+ it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
+ end
+
+ describe "dl_limit" do
+ describe "param defaults" do
+ let(:params) {{ }}
+ it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
+ end
+
+ describe "with dl_limit => 70" do
+ let :params do
+ { :dl_limit => "70" }
+ end
+ it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
+ end
+ end
+
+ describe "with enable => 0" do
+ let :params do
+ { :enable => "0" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
+ end
+
+ describe "with backup_interval => 1" do
+ let :params do
+ { :backup_interval => "1" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
+ end
+
+ describe "with backup_level => 0" do
+ let :params do
+ { :backup_level => "0" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
+ end
+
+ describe "with max_age => 1" do
+ let :params do
+ { :max_age => "1" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
+ end
+
+ describe "with min_age => 1" do
+ let :params do
+ { :min_age => "1" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
+ end
+
+ describe "with max_size => 1" do
+ let :params do
+ { :max_size => "1" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
+ end
+
+ describe "with download_delta => 2" do
+ let :params do
+ { :download_delta => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
+ end
+
+ describe "with verbose => 2" do
+ let :params do
+ { :verbose => "2" }
+ end
+ it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }
+ end
+
+end
diff --git a/puppet/modules/apt/spec/defines/builddep_spec.rb b/puppet/modules/apt/spec/defines/builddep_spec.rb
new file mode 100644
index 0000000..4e2b698
--- /dev/null
+++ b/puppet/modules/apt/spec/defines/builddep_spec.rb
@@ -0,0 +1,18 @@
+require 'spec_helper'
+describe 'apt::builddep', :type => :define do
+
+ let(:title) { 'my_package' }
+
+ describe "should require apt-get update" do
+ it { should contain_exec("apt_update").with({
+ 'command' => "/usr/bin/apt-get update",
+ 'refreshonly' => true
+ })
+ }
+ it { should contain_anchor("apt::builddep::my_package").with({
+ 'require' => 'Class[Apt::Update]',
+ })
+ }
+ end
+
+end
diff --git a/puppet/modules/apt/spec/defines/conf_spec.rb b/puppet/modules/apt/spec/defines/conf_spec.rb
new file mode 100644
index 0000000..5a81b51
--- /dev/null
+++ b/puppet/modules/apt/spec/defines/conf_spec.rb
@@ -0,0 +1,57 @@
+require 'spec_helper'
+describe 'apt::conf', :type => :define do
+ let :title do
+ 'norecommends'
+ end
+
+ describe "when creating an apt preference" do
+ let :params do
+ {
+ :priority => '00',
+ :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+ }
+ end
+
+ let :filename do
+ "/etc/apt/apt.conf.d/00norecommends"
+ end
+
+ it { should contain_apt__conf('norecommends').with({
+ 'priority' => '00',
+ 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+ })
+ }
+
+ it { should contain_file(filename).with({
+ 'ensure' => 'present',
+ 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ })
+ }
+ end
+
+ describe "when removing an apt preference" do
+ let :params do
+ {
+ :ensure => 'absent',
+ :priority => '00',
+ :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+ }
+ end
+
+ let :filename do
+ "/etc/apt/apt.conf.d/00norecommends"
+ end
+
+ it { should contain_file(filename).with({
+ 'ensure' => 'absent',
+ 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ })
+ }
+ end
+end
diff --git a/puppet/modules/apt/spec/defines/force_spec.rb b/puppet/modules/apt/spec/defines/force_spec.rb
new file mode 100644
index 0000000..f5d6ac2
--- /dev/null
+++ b/puppet/modules/apt/spec/defines/force_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+describe 'apt::force', :type => :define do
+ let :title do
+ 'my_package'
+ end
+
+ let :default_params do
+ {
+ :release => 'testing',
+ :version => false
+ }
+ end
+
+ [{},
+ {
+ :release => 'stable',
+ :version => '1'
+ }
+ ].each do |param_set|
+ describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
+ let :param_hash do
+ default_params.merge(param_set)
+ end
+
+ let :params do
+ param_set
+ end
+
+ let :unless_query do
+ base_command = "/usr/bin/dpkg -s #{title} | grep -q "
+ base_command + (params[:version] ? "'Version: #{params[:version]}'" : "'Status: install'")
+ end
+
+ let :exec_title do
+ base_exec = "/usr/bin/apt-get -y -t #{param_hash[:release]} install #{title}"
+ base_exec + (params[:version] ? "=#{params[:version]}" : "")
+ end
+ it { should contain_exec(exec_title).with_unless(unless_query) }
+ end
+ end
+end
diff --git a/puppet/modules/apt/spec/defines/key_spec.rb b/puppet/modules/apt/spec/defines/key_spec.rb
new file mode 100644
index 0000000..aea197a
--- /dev/null
+++ b/puppet/modules/apt/spec/defines/key_spec.rb
@@ -0,0 +1,123 @@
+require 'spec_helper'
+describe 'apt::key', :type => :define do
+ let :title do
+ '8347A27F'
+ end
+
+ let :default_params do
+ {
+ :key => title,
+ :ensure => 'present',
+ :key_server => "keyserver.ubuntu.com",
+ :key_source => false,
+ :key_content => false
+ }
+ end
+
+ [{},
+ {
+ :ensure => 'absent'
+ },
+ {
+ :ensure => 'random'
+ },
+ {
+ :key_source => 'ftp://ftp.example.org/key',
+ },
+ {
+ :key_content => 'deadbeef',
+ }
+ ].each do |param_set|
+
+ let :param_hash do
+ param_hash = default_params.merge(param_set)
+ param_hash[:key].upcase! if param_hash[:key]
+ param_hash
+ end
+
+ let :params do
+ param_set
+ end
+
+ let :digest do
+ str = String.new
+ str << param_hash[:key].to_s << '/'
+ str << param_hash[:key_content].to_s << '/'
+ str << param_hash[:key_source].to_s << '/'
+ str << param_hash[:key_server].to_s << '/'
+ Digest::SHA1.hexdigest(str)
+ end
+
+ describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
+
+ it {
+ if [:present, 'present', :absent, 'absent'].include? param_hash[:ensure]
+ should contain_apt__params
+ end
+ }
+
+ it {
+ if [:present, 'present'].include? param_hash[:ensure]
+ should_not contain_exec("apt::key #{param_hash[:key]} absent")
+ should contain_anchor("apt::key #{param_hash[:key]} present")
+ should contain_exec(digest).with({
+ "path" => "/bin:/usr/bin",
+ "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'"
+ })
+ elsif [:absent, 'absent'].include? param_hash[:ensure]
+ should_not contain_anchor("apt::key #{param_hash[:key]} present")
+ should contain_exec("apt::key #{param_hash[:key]} absent").with({
+ "path" => "/bin:/usr/bin",
+ "onlyif" => "apt-key list | grep '#{param_hash[:key]}'",
+ "command" => "apt-key del '#{param_hash[:key]}'"
+ })
+ else
+ expect { should raise_error(Puppet::Error) }
+ end
+ }
+
+ it {
+ if [:present, 'present'].include? param_hash[:ensure]
+ if param_hash[:key_content]
+ should contain_exec(digest).with({
+ "command" => "echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -"
+ })
+ elsif param_hash[:key_source]
+ should contain_exec(digest).with({
+ "command" => "wget -q '#{param_hash[:key_source]}' -O- | apt-key add -"
+ })
+ elsif param_hash[:key_server]
+ should contain_exec(digest).with({
+ "command" => "apt-key adv --keyserver '#{param_hash[:key_server]}' --recv-keys '#{param_hash[:key]}'"
+ })
+ end
+ end
+ }
+
+ end
+ end
+
+ [{ :ensure => 'present' }, { :ensure => 'absent' }].each do |param_set|
+ describe "should correctly handle duplicate definitions" do
+
+ let :pre_condition do
+ "apt::key { 'duplicate': key => '#{title}'; }"
+ end
+
+ let(:params) { param_set }
+
+ it {
+ if param_set[:ensure] == 'present'
+ should contain_anchor("apt::key #{title} present")
+ should contain_apt__key(title)
+ should contain_apt__key("duplicate")
+ elsif param_set[:ensure] == 'absent'
+ expect { should raise_error(Puppet::Error) }
+ end
+ }
+
+ end
+ end
+
+end
+
diff --git a/puppet/modules/apt/spec/defines/pin_spec.rb b/puppet/modules/apt/spec/defines/pin_spec.rb
new file mode 100644
index 0000000..a4cb1e2
--- /dev/null
+++ b/puppet/modules/apt/spec/defines/pin_spec.rb
@@ -0,0 +1,101 @@
+require 'spec_helper'
+describe 'apt::pin', :type => :define do
+ let(:title) { 'my_pin' }
+
+ let :default_params do
+ {
+ :ensure => 'present',
+ :order => '',
+ :packages => '*',
+ :priority => '0',
+ :release => nil
+ }
+ end
+
+ [
+ { :params => {},
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: release a=my_pin\nPin-Priority: 0\n"
+ },
+ {
+ :params => {
+ :packages => 'apache',
+ :priority => '1'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :order => 50,
+ :packages => 'apache',
+ :priority => '1'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :ensure => 'absent',
+ :packages => 'apache',
+ :priority => '1'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :packages => 'apache',
+ :priority => '1',
+ :release => 'my_newpin'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_newpin\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :packages => 'apache',
+ :priority => '1',
+ :version => '2.2.16*'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: version 2.2.16*\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :priority => '1',
+ :origin => 'ftp.de.debian.org'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: origin \"ftp.de.debian.org\"\nPin-Priority: 1\n"
+ },
+ {
+ :params => {
+ :packages => 'apache',
+ :priority => '1',
+ :release => 'stable',
+ :codename => 'wheezy',
+ :release_version => '3.0',
+ :component => 'main',
+ :originator => 'Debian',
+ :label => 'Debian'
+ },
+ :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=stable, n=wheezy, v=3.0, c=main, o=Debian, l=Debian\nPin-Priority: 1\n"
+ },
+ ].each do |param_set|
+ describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
+ let :param_hash do
+ default_params.merge(param_set[:params])
+ end
+
+ let :params do
+ param_set[:params]
+ end
+
+ it { should include_class("apt::params") }
+
+ it { should contain_file("#{title}.pref").with({
+ 'ensure' => param_hash[:ensure],
+ 'path' => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ 'content' => param_set[:content],
+ })
+ }
+ end
+ end
+end
diff --git a/puppet/modules/apt/spec/defines/ppa_spec.rb b/puppet/modules/apt/spec/defines/ppa_spec.rb
new file mode 100644
index 0000000..5b59f57
--- /dev/null
+++ b/puppet/modules/apt/spec/defines/ppa_spec.rb
@@ -0,0 +1,143 @@
+require 'spec_helper'
+describe 'apt::ppa', :type => :define do
+ [ { :lsbdistrelease => '11.04',
+ :lsbdistcodename => 'natty',
+ :package => 'python-software-properties'},
+ { :lsbdistrelease => '12.10',
+ :lsbdistcodename => 'quantal',
+ :package => 'software-properties-common'},
+ ].each do |platform|
+ context "on #{platform[:lsbdistcodename]}" do
+ let :facts do
+ {
+ :lsbdistrelease => platform[:lsbdistrelease],
+ :lsbdistcodename => platform[:lsbdistcodename],
+ }
+ end
+ let :release do
+ "#{platform[:lsbdistcodename]}"
+ end
+ let :package do
+ "#{platform[:package]}"
+ end
+ let :options do
+ "-y"
+ end
+ ['ppa:dans_ppa', 'dans_ppa','ppa:dans-daily/ubuntu'].each do |t|
+ describe "with title #{t}" do
+ let :pre_condition do
+ 'class { "apt": }'
+ end
+ let :title do
+ t
+ end
+ let :filename do
+ t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list"
+ end
+
+ it { should contain_package("#{package}") }
+
+ it { should contain_exec("apt_update").with(
+ 'command' => '/usr/bin/apt-get update',
+ 'refreshonly' => true
+ )
+ }
+
+ it { should contain_exec("add-apt-repository-#{t}").with(
+ 'command' => "/usr/bin/add-apt-repository #{options} #{t}",
+ 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
+ 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"],
+ 'notify' => "Exec[apt_update]"
+ )
+ }
+
+ it { should create_file("/etc/apt/sources.list.d/#{filename}").with(
+ 'ensure' => 'file',
+ 'require' => "Exec[add-apt-repository-#{t}]"
+ )
+ }
+ end
+ end
+ describe 'without a proxy defined' do
+ let :title do
+ 'rspec_ppa'
+ end
+ let :pre_condition do
+ 'class { "apt":
+ proxy_host => false
+ }'
+ end
+ let :filename do
+ "#{title}-#{release}.list"
+ end
+
+ it { should contain_exec("add-apt-repository-#{title}").with(
+ 'environment' => [],
+ 'command' => "/usr/bin/add-apt-repository #{options} #{title}",
+ 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
+ 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"],
+ 'notify' => "Exec[apt_update]"
+ )
+ }
+ end
+
+ describe 'behind a proxy' do
+ let :title do
+ 'rspec_ppa'
+ end
+ let :pre_condition do
+ 'class { "apt":
+ proxy_host => "user:pass@proxy",
+ }'
+ end
+ let :filename do
+ "#{title}-#{release}.list"
+ end
+
+ it { should contain_exec("add-apt-repository-#{title}").with(
+ 'environment' => [
+ "http_proxy=http://user:pass@proxy:8080",
+ "https_proxy=http://user:pass@proxy:8080",
+ ],
+ 'command' => "/usr/bin/add-apt-repository #{options} #{title}",
+ 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
+ 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"],
+ 'notify' => "Exec[apt_update]"
+ )
+ }
+ end
+ end
+ end
+
+ [ { :lsbdistcodename => 'natty',
+ :package => 'python-software-properties' },
+ { :lsbdistcodename => 'quantal',
+ :package => 'software-properties-common'},
+ ].each do |platform|
+ context "on #{platform[:lsbdistcodename]}" do
+ describe "it should not error if package['#{platform[:package]}'] is already defined" do
+ let :pre_condition do
+ 'class {"apt": }' +
+ 'package { "#{platform[:package]}": }->Apt::Ppa["ppa"]'
+ end
+ let :facts do
+ {:lsbdistcodename => '#{platform[:lsbdistcodename]}'}
+ end
+ let(:title) { "ppa" }
+ let(:release) { "#{platform[:lsbdistcodename]}" }
+ it { should contain_package('#{platform[:package]}') }
+ end
+ end
+ end
+
+ describe "without Class[apt] should raise a Puppet::Error" do
+ let(:release) { "natty" }
+ let(:title) { "ppa" }
+ it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
+ end
+
+ describe "without release should raise a Puppet::Error" do
+ let(:title) { "ppa:" }
+ it { expect { should contain_apt__ppa(:release) }.to raise_error(Puppet::Error) }
+ end
+end
diff --git a/puppet/modules/apt/spec/defines/source_spec.rb b/puppet/modules/apt/spec/defines/source_spec.rb
new file mode 100644
index 0000000..9ad4d46
--- /dev/null
+++ b/puppet/modules/apt/spec/defines/source_spec.rb
@@ -0,0 +1,166 @@
+require 'spec_helper'
+describe 'apt::source', :type => :define do
+ let :title do
+ 'my_source'
+ end
+
+ let :default_params do
+ {
+ :ensure => 'present',
+ :location => '',
+ :release => 'karmic',
+ :repos => 'main',
+ :include_src => true,
+ :required_packages => false,
+ :key => false,
+ :key_server => 'keyserver.ubuntu.com',
+ :key_content => false,
+ :key_source => false,
+ :pin => false
+ }
+ end
+
+ [{},
+ {
+ :location => 'http://example.com',
+ :release => 'precise',
+ :repos => 'security',
+ :include_src => false,
+ :required_packages => 'apache',
+ :key => 'key_name',
+ :key_server => 'keyserver.debian.com',
+ :pin => '600',
+ :key_content => 'ABCD1234'
+ },
+ {
+ :key => 'key_name',
+ :key_server => 'keyserver.debian.com',
+ :key_content => false,
+ },
+ {
+ :ensure => 'absent',
+ :location => 'http://example.com',
+ :release => 'precise',
+ :repos => 'security',
+ },
+ {
+ :release => '',
+ },
+ {
+ :release => 'custom',
+ },
+ {
+ :architecture => 'amd64',
+ }
+ ].each do |param_set|
+ describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
+ let :param_hash do
+ default_params.merge(param_set)
+ end
+
+ let :facts do
+ {:lsbdistcodename => 'karmic'}
+ end
+
+ let :params do
+ param_set
+ end
+
+ let :filename do
+ "/etc/apt/sources.list.d/#{title}.list"
+ end
+
+ let :content do
+ content = "# #{title}"
+ if param_hash[:architecture]
+ arch = "[arch=#{param_hash[:architecture]}]"
+ end
+ content << "\ndeb #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
+
+ if param_hash[:include_src]
+ content << "deb-src #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
+ end
+ content
+ end
+
+ it { should contain_apt__params }
+
+ it { should contain_file("#{title}.list").with({
+ 'ensure' => param_hash[:ensure],
+ 'path' => filename,
+ 'owner' => 'root',
+ 'group' => 'root',
+ 'mode' => '0644',
+ 'content' => content,
+ })
+ }
+
+ it {
+ if param_hash[:pin]
+ should contain_apt__pin(title).with({
+ "priority" => param_hash[:pin],
+ "before" => "File[#{title}.list]"
+ })
+ else
+ should_not contain_apt__pin(title).with({
+ "priority" => param_hash[:pin],
+ "before" => "File[#{title}.list]"
+ })
+ end
+ }
+
+ it {
+ should contain_exec("apt_update").with({
+ "command" => "/usr/bin/apt-get update",
+ "refreshonly" => true
+ })
+ }
+
+ it {
+ if param_hash[:required_packages]
+ should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
+ "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
+ "subscribe" => "File[#{title}.list]",
+ "refreshonly" => true,
+ "before" => 'Exec[apt_update]',
+ })
+ else
+ should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
+ "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
+ "subscribe" => "File[#{title}.list]",
+ "refreshonly" => true
+ })
+ end
+ }
+
+ it {
+ if param_hash[:key]
+ should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
+ "key" => param_hash[:key],
+ "ensure" => :present,
+ "key_server" => param_hash[:key_server],
+ "key_content" => param_hash[:key_content],
+ "key_source" => param_hash[:key_source],
+ "before" => "File[#{title}.list]"
+ })
+ else
+ should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
+ "key" => param_hash[:key],
+ "ensure" => :present,
+ "key_server" => param_hash[:key_server],
+ "key_content" => param_hash[:key_content],
+ "key_source" => param_hash[:key_source],
+ "before" => "File[#{title}.list]"
+ })
+ end
+ }
+ end
+ end
+ describe "without release should raise a Puppet::Error" do
+ let(:default_params) { Hash.new }
+ let(:facts) { Hash.new }
+ it { expect { should raise_error(Puppet::Error) } }
+ let(:facts) { { :lsbdistcodename => 'lucid' } }
+ it { should contain_apt__source(title) }
+ end
+end
diff --git a/puppet/modules/apt/spec/spec_helper.rb b/puppet/modules/apt/spec/spec_helper.rb
new file mode 100644
index 0000000..2c6f566
--- /dev/null
+++ b/puppet/modules/apt/spec/spec_helper.rb
@@ -0,0 +1 @@
+require 'puppetlabs_spec_helper/module_spec_helper'
diff --git a/puppet/modules/apt/spec/spec_helper_system.rb b/puppet/modules/apt/spec/spec_helper_system.rb
new file mode 100644
index 0000000..490a601
--- /dev/null
+++ b/puppet/modules/apt/spec/spec_helper_system.rb
@@ -0,0 +1,30 @@
+require 'rspec-system/spec_helper'
+require 'rspec-system-puppet/helpers'
+require 'rspec-system-serverspec/helpers'
+
+include RSpecSystemPuppet::Helpers
+
+include Serverspec::Helper::RSpecSystem
+include Serverspec::Helper::DetectOS
+
+RSpec.configure do |c|
+ # Project root
+ proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+ # Enable colour
+ c.tty = true
+
+ c.include RSpecSystemPuppet::Helpers
+
+ # This is where we 'setup' the nodes before running our tests
+ c.before :suite do
+ # May as well update here as this can only run on apt-get machines.
+ shell('apt-get update')
+ # Install puppet
+ puppet_install
+
+ # Install modules and dependencies
+ puppet_module_install(:source => proj_root, :module_name => 'apt')
+ shell('puppet module install puppetlabs-stdlib')
+ end
+end
diff --git a/puppet/modules/apt/spec/system/apt_builddep_spec.rb b/puppet/modules/apt/spec/system/apt_builddep_spec.rb
new file mode 100644
index 0000000..fa16ab4
--- /dev/null
+++ b/puppet/modules/apt/spec/system/apt_builddep_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper_system'
+
+describe 'apt::builddep' do
+
+ context 'reset' do
+ it 'removes packages' do
+ shell('apt-get -y remove glusterfs-server')
+ shell('apt-get -y remove g++')
+ end
+ end
+
+ context 'apt::builddep' do
+ it 'should work with no errors' do
+ pp = <<-EOS
+ include '::apt'
+ apt::builddep { 'glusterfs-server': }
+ EOS
+
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ end
+ end
+
+ describe 'should install g++ as a dependency' do
+ describe package('g++') do
+ it { should be_installed }
+ end
+ end
+ end
+
+ context 'reset' do
+ it 'removes packages' do
+ shell('apt-get -y remove glusterfs-server')
+ shell('apt-get -y remove g++')
+ end
+ end
+
+end
diff --git a/puppet/modules/apt/spec/system/apt_key_spec.rb b/puppet/modules/apt/spec/system/apt_key_spec.rb
new file mode 100644
index 0000000..4842cb5
--- /dev/null
+++ b/puppet/modules/apt/spec/system/apt_key_spec.rb
@@ -0,0 +1,53 @@
+require 'spec_helper_system'
+
+describe 'apt::key' do
+
+ context 'reset' do
+ it 'clean up keys' do
+ shell('apt-key del 4BD6EC30')
+ shell('apt-key del D50582E6')
+ end
+ end
+
+ context 'apt::key' do
+ it 'should work with no errors' do
+ pp = <<-EOS
+ include '::apt'
+ apt::key { 'puppetlabs':
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ }
+
+ apt::key { 'jenkins':
+ key => 'D50582E6',
+ key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
+ }
+ EOS
+
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ end
+ end
+
+ describe 'keys should exist' do
+ it 'finds puppetlabs key' do
+ shell('apt-key list | grep 4BD6EC30') do |r|
+ r.exit_code.should be_zero
+ end
+ end
+ it 'finds jenkins key' do
+ shell('apt-key list | grep D50582E6') do |r|
+ r.exit_code.should be_zero
+ end
+ end
+ end
+ end
+
+ context 'reset' do
+ it 'clean up keys' do
+ shell('apt-key del 4BD6EC30')
+ shell('apt-key del D50582E6')
+ end
+ end
+
+end
diff --git a/puppet/modules/apt/spec/system/apt_ppa_spec.rb b/puppet/modules/apt/spec/system/apt_ppa_spec.rb
new file mode 100644
index 0000000..2e2baf5
--- /dev/null
+++ b/puppet/modules/apt/spec/system/apt_ppa_spec.rb
@@ -0,0 +1,59 @@
+require 'spec_helper_system'
+
+describe 'apt::ppa' do
+
+ context 'reset' do
+ it 'removes ppa' do
+ shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*')
+ shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*')
+ end
+ end
+
+ context 'adding a ppa that doesnt exist' do
+ it 'should work with no errors' do
+ pp = <<-EOS
+ include '::apt'
+ apt::ppa { 'ppa:drizzle-developers/ppa': }
+ EOS
+
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ end
+ end
+
+ describe 'contains the source file' do
+ it 'contains a drizzle ppa source' do
+ shell('ls /etc/apt/sources.list.d/drizzle-developers-ppa-*.list') do |r|
+ r.exit_code.should be_zero
+ end
+ end
+ end
+ end
+
+ context 'readding a removed ppa.' do
+ it 'setup' do
+ shell('add-apt-repository -y ppa:raravena80/collectd5')
+ # This leaves a blank file
+ shell('add-apt-repository --remove ppa:raravena80/collectd5')
+ end
+
+ it 'should readd it successfully' do
+ pp = <<-EOS
+ include '::apt'
+ apt::ppa { 'ppa:raravena80/collectd5': }
+ EOS
+
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ end
+ end
+ end
+
+ context 'reset' do
+ it 'removes added ppas' do
+ shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*')
+ shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*')
+ end
+ end
+
+end
diff --git a/puppet/modules/apt/spec/system/apt_source_spec.rb b/puppet/modules/apt/spec/system/apt_source_spec.rb
new file mode 100644
index 0000000..6a445e1
--- /dev/null
+++ b/puppet/modules/apt/spec/system/apt_source_spec.rb
@@ -0,0 +1,51 @@
+require 'spec_helper_system'
+
+describe 'apt::source' do
+
+ context 'reset' do
+ it 'clean up puppetlabs repo' do
+ shell('apt-key del 4BD6EC30')
+ shell('rm /etc/apt/sources.list.d/puppetlabs.list')
+ end
+ end
+
+ context 'apt::source' do
+ it 'should work with no errors' do
+ pp = <<-EOS
+ include '::apt'
+ apt::source { 'puppetlabs':
+ location => 'http://apt.puppetlabs.com',
+ repos => 'main',
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ }
+ EOS
+
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ end
+ end
+
+ describe 'key should exist' do
+ it 'finds puppetlabs key' do
+ shell('apt-key list | grep 4BD6EC30') do |r|
+ r.exit_code.should be_zero
+ end
+ end
+ end
+
+ describe 'source should exist' do
+ describe file('/etc/apt/sources.list.d/puppetlabs.list') do
+ it { should be_file }
+ end
+ end
+ end
+
+ context 'reset' do
+ it 'clean up puppetlabs repo' do
+ shell('apt-key del 4BD6EC30')
+ shell('rm /etc/apt/sources.list.d/puppetlabs.list')
+ end
+ end
+
+end
diff --git a/puppet/modules/apt/spec/system/basic_spec.rb b/puppet/modules/apt/spec/system/basic_spec.rb
new file mode 100644
index 0000000..3008356
--- /dev/null
+++ b/puppet/modules/apt/spec/system/basic_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper_system'
+
+describe 'basic tests:' do
+ # Using puppet_apply as a subject
+ context puppet_apply 'notice("foo")' do
+ its(:stdout) { should =~ /foo/ }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+end
diff --git a/puppet/modules/apt/spec/system/class_spec.rb b/puppet/modules/apt/spec/system/class_spec.rb
new file mode 100644
index 0000000..7bb6b8d
--- /dev/null
+++ b/puppet/modules/apt/spec/system/class_spec.rb
@@ -0,0 +1,20 @@
+require 'spec_helper_system'
+
+describe 'apt class' do
+
+ context 'default parameters' do
+ # Using puppet_apply as a helper
+ it 'should work with no errors' do
+ pp = <<-EOS
+ class { 'apt': }
+ EOS
+
+ # Run it twice and test for idempotency
+ puppet_apply(pp) do |r|
+ r.exit_code.should_not == 1
+ r.refresh
+ r.exit_code.should be_zero
+ end
+ end
+ end
+end
diff --git a/puppet/modules/apt/templates/10periodic.erb b/puppet/modules/apt/templates/10periodic.erb
new file mode 100644
index 0000000..5737c9a
--- /dev/null
+++ b/puppet/modules/apt/templates/10periodic.erb
@@ -0,0 +1,12 @@
+APT::Periodic::Enable "<%= @enable %>";
+APT::Periodic::BackUpArchiveInterval "<%= @backup_interval %>";
+APT::Periodic::BackUpLevel "<%= @backup_level %>";
+APT::Periodic::MaxAge "<%= @max_age %>";
+APT::Periodic::MinAge "<%= @min_age %>";
+APT::Periodic::MaxSize "<%= @max_size %>";
+APT::Periodic::Update-Package-Lists "<%= @update %>";
+APT::Periodic::Download-Upgradeable-Packages "<%= @download %>";
+APT::Periodic::Download-Upgradeable-Packages-Debdelta "<%= @download_delta %>";
+APT::Periodic::Unattended-Upgrade "<%= @upgrade %>";
+APT::Periodic::AutocleanInterval "<%= @autoclean %>";
+APT::Periodic::Verbose "<%= @verbose %>";
diff --git a/puppet/modules/apt/templates/50unattended-upgrades.erb b/puppet/modules/apt/templates/50unattended-upgrades.erb
new file mode 100644
index 0000000..4df0f74
--- /dev/null
+++ b/puppet/modules/apt/templates/50unattended-upgrades.erb
@@ -0,0 +1,53 @@
+// Automatically upgrade packages from these (origin:archive) pairs
+Unattended-Upgrade::Allowed-Origins {
+<% @origins.each do |origin| -%>
+ "<%= origin %>";
+<% end -%>
+};
+
+// List of packages to not update
+Unattended-Upgrade::Package-Blacklist {
+<% @blacklist.each do |package| -%>
+ "<%= package %>";
+<% end -%>
+};
+
+// This option allows you to control if on a unclean dpkg exit
+// unattended-upgrades will automatically run
+// dpkg --force-confold --configure -a
+// The default is true, to ensure updates keep getting installed
+Unattended-Upgrade::AutoFixInterruptedDpkg "<%= @auto_fix %>";
+
+// Split the upgrade into the smallest possible chunks so that
+// they can be interrupted with SIGUSR1. This makes the upgrade
+// a bit slower but it has the benefit that shutdown while a upgrade
+// is running is possible (with a small delay)
+Unattended-Upgrade::MinimalSteps "<%= @minimal_steps %>";
+
+// Install all unattended-upgrades when the machine is shuting down
+// instead of doing it in the background while the machine is running
+// This will (obviously) make shutdown slower
+Unattended-Upgrade::InstallOnShutdown "<%= @install_on_shutdown %>";
+
+// Send email to this address for problems or packages upgrades
+// If empty or unset then no email is sent, make sure that you
+// have a working mail setup on your system. A package that provides
+// 'mailx' must be installed.
+<% if @mail_to != "NONE" %>Unattended-Upgrade::Mail "<%= @mail_to %>";<% end %>
+
+// Set this value to "true" to get emails only on errors. Default
+// is to always send a mail if Unattended-Upgrade::Mail is set
+<% if @mail_to != "NONE" %>Unattended-Upgrade::MailOnlyOnError "<%= @mail_only_on_error %>";<% end %>
+
+// Do automatic removal of new unused dependencies after the upgrade
+// (equivalent to apt-get autoremove)
+Unattended-Upgrade::Remove-Unused-Dependencies "<%= @remove_unused %>";
+
+// Automatically reboot *WITHOUT CONFIRMATION* if a
+// the file /var/run/reboot-required is found after the upgrade
+Unattended-Upgrade::Automatic-Reboot "<%= @auto_reboot %>";
+
+
+// Use apt bandwidth limit feature, this example limits the download
+// speed to 70kb/sec
+<% if @dl_limit != "NONE" %>Acquire::http::Dl-Limit "<%= @dl_limit %>";<% end %>
diff --git a/puppet/modules/apt/templates/pin.pref.erb b/puppet/modules/apt/templates/pin.pref.erb
new file mode 100644
index 0000000..62c44c7
--- /dev/null
+++ b/puppet/modules/apt/templates/pin.pref.erb
@@ -0,0 +1,22 @@
+<%-
+@pin = "release a=#{@name}" # default value
+if @pin_release.length > 0
+ options = []
+ options.push("a=#{@release}") if @release.length > 0
+ options.push("n=#{@codename}") if @codename.length > 0
+ options.push("v=#{@release_version}") if @release_version.length > 0
+ options.push("c=#{@component}") if @component.length > 0
+ options.push("o=#{@originator}") if @originator.length > 0
+ options.push("l=#{@label}") if @label.length > 0
+ @pin = "release #{options.join(', ')}"
+elsif @version.length > 0
+ @pin = "version #{@version}"
+elsif @origin.length > 0
+ @pin = "origin \"#{@origin}\""
+end
+-%>
+# <%= @name %>
+Explanation: <%= @explanation %>
+Package: <%= @packages %>
+Pin: <%= @pin %>
+Pin-Priority: <%= @priority %>
diff --git a/puppet/modules/apt/templates/source.list.erb b/puppet/modules/apt/templates/source.list.erb
new file mode 100644
index 0000000..e8b6865
--- /dev/null
+++ b/puppet/modules/apt/templates/source.list.erb
@@ -0,0 +1,5 @@
+# <%= @name %>
+deb <% if @architecture %>[arch=<%= @architecture %>]<% end %><%= @location %> <%= @release_real %> <%= @repos %>
+<%- if @include_src then -%>
+deb-src <% if @architecture %>[arch=<%= @architecture %>]<% end %><%= @location %> <%= @release_real %> <%= @repos %>
+<%- end -%>
diff --git a/puppet/modules/apt/tests/builddep.pp b/puppet/modules/apt/tests/builddep.pp
new file mode 100644
index 0000000..8b4f796
--- /dev/null
+++ b/puppet/modules/apt/tests/builddep.pp
@@ -0,0 +1,2 @@
+class { 'apt': }
+apt::builddep{ 'glusterfs-server': }
diff --git a/puppet/modules/apt/tests/debian/testing.pp b/puppet/modules/apt/tests/debian/testing.pp
new file mode 100644
index 0000000..8245b3a
--- /dev/null
+++ b/puppet/modules/apt/tests/debian/testing.pp
@@ -0,0 +1,2 @@
+class { 'apt': }
+class { 'apt::debian::testing': }
diff --git a/puppet/modules/apt/tests/debian/unstable.pp b/puppet/modules/apt/tests/debian/unstable.pp
new file mode 100644
index 0000000..8605179
--- /dev/null
+++ b/puppet/modules/apt/tests/debian/unstable.pp
@@ -0,0 +1,2 @@
+class { 'apt': }
+class { 'apt::debian::unstable': }
diff --git a/puppet/modules/apt/tests/force.pp b/puppet/modules/apt/tests/force.pp
new file mode 100644
index 0000000..f331363
--- /dev/null
+++ b/puppet/modules/apt/tests/force.pp
@@ -0,0 +1,7 @@
+# force.pp
+# force a package from a specific release
+
+apt::force { 'package':
+ release => 'testing',
+ version => false
+}
diff --git a/puppet/modules/apt/tests/init.pp b/puppet/modules/apt/tests/init.pp
new file mode 100644
index 0000000..abc75af
--- /dev/null
+++ b/puppet/modules/apt/tests/init.pp
@@ -0,0 +1 @@
+class { 'apt': }
diff --git a/puppet/modules/apt/tests/key.pp b/puppet/modules/apt/tests/key.pp
new file mode 100644
index 0000000..79e0e1b
--- /dev/null
+++ b/puppet/modules/apt/tests/key.pp
@@ -0,0 +1,6 @@
+# Declare Apt key for apt.puppetlabs.com source
+apt::key { 'puppetlabs':
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+ key_options => 'http-proxy="http://proxyuser:proxypass@example.org:3128"',
+}
diff --git a/puppet/modules/apt/tests/params.pp b/puppet/modules/apt/tests/params.pp
new file mode 100644
index 0000000..5ddf3c6
--- /dev/null
+++ b/puppet/modules/apt/tests/params.pp
@@ -0,0 +1 @@
+include apt::params
diff --git a/puppet/modules/apt/tests/pin.pp b/puppet/modules/apt/tests/pin.pp
new file mode 100644
index 0000000..6a9024c
--- /dev/null
+++ b/puppet/modules/apt/tests/pin.pp
@@ -0,0 +1,5 @@
+# pin a release in apt, useful for unstable repositories
+apt::pin { 'foo':
+ packages => '*',
+ priority => 0,
+}
diff --git a/puppet/modules/apt/tests/ppa.pp b/puppet/modules/apt/tests/ppa.pp
new file mode 100644
index 0000000..e728f6f
--- /dev/null
+++ b/puppet/modules/apt/tests/ppa.pp
@@ -0,0 +1,4 @@
+class { 'apt': }
+
+# Example declaration of an Apt PPA
+apt::ppa{ 'ppa:openstack-ppa/bleeding-edge': }
diff --git a/puppet/modules/apt/tests/release.pp b/puppet/modules/apt/tests/release.pp
new file mode 100644
index 0000000..823f586
--- /dev/null
+++ b/puppet/modules/apt/tests/release.pp
@@ -0,0 +1,4 @@
+class { 'apt': }
+class { 'apt::release':
+ release_id => 'karmic'
+}
diff --git a/puppet/modules/apt/tests/source.pp b/puppet/modules/apt/tests/source.pp
new file mode 100644
index 0000000..d83cb97
--- /dev/null
+++ b/puppet/modules/apt/tests/source.pp
@@ -0,0 +1,29 @@
+# Declare the apt class to manage /etc/apt/sources.list and /etc/sources.list.d
+class { 'apt': }
+
+# Install the puppetlabs apt source
+# Release is automatically obtained from lsbdistcodename fact if available.
+apt::source { 'puppetlabs':
+ location => 'http://apt.puppetlabs.com',
+ repos => 'main',
+ key => '4BD6EC30',
+ key_server => 'pgp.mit.edu',
+}
+
+# test two sources with the same key
+apt::source { 'debian_testing':
+ location => 'http://debian.mirror.iweb.ca/debian/',
+ release => 'testing',
+ repos => 'main contrib non-free',
+ key => '55BE302B',
+ key_server => 'subkeys.pgp.net',
+ pin => '-10',
+}
+apt::source { 'debian_unstable':
+ location => 'http://debian.mirror.iweb.ca/debian/',
+ release => 'unstable',
+ repos => 'main contrib non-free',
+ key => '55BE302B',
+ key_server => 'subkeys.pgp.net',
+ pin => '-10',
+}
diff --git a/puppet/modules/apt/tests/unattended-upgrades.pp b/puppet/modules/apt/tests/unattended-upgrades.pp
new file mode 100644
index 0000000..7f65ab4
--- /dev/null
+++ b/puppet/modules/apt/tests/unattended-upgrades.pp
@@ -0,0 +1 @@
+include apt::unattended-upgrades
diff --git a/puppet/modules/composer/LICENSE b/puppet/modules/composer/LICENSE
new file mode 100644
index 0000000..4d0f5fb
--- /dev/null
+++ b/puppet/modules/composer/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2012-2013 William Durand <william.durand1@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/puppet/modules/composer/Modulefile b/puppet/modules/composer/Modulefile
new file mode 100644
index 0000000..96660be
--- /dev/null
+++ b/puppet/modules/composer/Modulefile
@@ -0,0 +1,8 @@
+name 'willdurand-composer'
+version '0.0.5'
+summary 'This module installs Composer, a dependency manager for PHP.'
+description 'This module installs Composer, a dependency manager for PHP.'
+license 'MIT'
+author 'William Durand'
+
+dependency 'maestrodev/wget'
diff --git a/puppet/modules/composer/README.md b/puppet/modules/composer/README.md
new file mode 100644
index 0000000..73a885b
--- /dev/null
+++ b/puppet/modules/composer/README.md
@@ -0,0 +1,71 @@
+puppet-composer
+===============
+
+[![Build
+Status](https://secure.travis-ci.org/willdurand/puppet-composer.png)](http://travis-ci.org/willdurand/puppet-composer)
+
+This module installs [Composer](http://getcomposer.org/), a dependency manager
+for PHP.
+
+Installation
+------------
+
+Using the Puppet Module Tool, install the
+[`willdurand/composer`](http://forge.puppetlabs.com/willdurand/composer) by
+running the following command:
+
+ puppet module install willdurand/composer
+
+Otherwise, close this repository and make sure to install the proper
+dependencies ([`puppet-wget`](https://github.com/maestrodev/puppet-wget)):
+
+ git clone git://github.com/willdurand/puppet-composer.git modules/composer
+
+
+Usage
+-----
+
+Include the `composer` class:
+
+ include composer
+
+You can specify the command name you want to get, and the target directory (aka
+where to install Composer):
+
+ class { 'composer':
+ command_name => 'composer',
+ target_dir => '/usr/local/bin'
+ }
+
+You can also auto update composer by using the `auto_update` parameter. This will
+update Composer **only** when you will run Puppet.
+
+ class { 'composer':
+ auto_update => true
+ }
+
+You can specify a particular `user` that will be the owner of the Composer
+executable:
+
+ class { 'composer':
+ user => 'foo',
+ }
+
+
+Running the tests
+-----------------
+
+Install the dependencies using [Bundler](http://gembundler.com):
+
+ BUNDLE_GEMFILE=.gemfile bundle install
+
+Run the following command:
+
+ BUNDLE_GEMFILE=.gemfile bundle exec rake spec
+
+
+License
+-------
+
+puppet-composer is released under the MIT License. See the bundled LICENSE file
+for details.
diff --git a/puppet/modules/composer/Rakefile b/puppet/modules/composer/Rakefile
new file mode 100644
index 0000000..01be97b
--- /dev/null
+++ b/puppet/modules/composer/Rakefile
@@ -0,0 +1,27 @@
+require 'puppetlabs_spec_helper/rake_tasks'
+require 'puppet-lint/tasks/puppet-lint'
+require 'puppet-syntax/tasks/puppet-syntax'
+
+if RUBY_VERSION !~ /^1.8/
+ require 'puppet_blacksmith/rake_tasks'
+end
+
+PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}"
+PuppetLint.configuration.fail_on_warnings = false
+PuppetLint.configuration.send("disable_80chars")
+
+exclude_paths = [
+ "pkg/**/*",
+ "vendor/**/*",
+ "spec/**/*",
+]
+
+PuppetLint.configuration.ignore_paths = exclude_paths
+PuppetSyntax.exclude_paths = exclude_paths
+
+desc "Run syntax, lint, and spec tests."
+task :test => [
+ :syntax,
+ :lint,
+ :spec,
+]
diff --git a/puppet/modules/composer/manifests/init.pp b/puppet/modules/composer/manifests/init.pp
new file mode 100644
index 0000000..4c876ab
--- /dev/null
+++ b/puppet/modules/composer/manifests/init.pp
@@ -0,0 +1,75 @@
+# = Class: composer
+#
+# == Parameters:
+#
+# [*target_dir*]
+# Where to install the composer executable.
+#
+# [*command_name*]
+# The name of the composer executable.
+#
+# [*user*]
+# The owner of the composer executable.
+#
+# [*auto_update*]
+# Whether to run `composer self-update`.
+#
+# == Example:
+#
+# include composer
+#
+# class { 'composer':
+# 'target_dir' => '/usr/local/bin',
+# 'user' => 'root',
+# 'command_name' => 'composer',
+# 'auto_update' => true
+# }
+#
+class composer (
+ $target_dir = 'UNDEF',
+ $command_name = 'UNDEF',
+ $user = 'UNDEF',
+ $auto_update = false
+) {
+
+ include composer::params
+
+ $composer_target_dir = $target_dir ? {
+ 'UNDEF' => $::composer::params::target_dir,
+ default => $target_dir
+ }
+
+ $composer_command_name = $command_name ? {
+ 'UNDEF' => $::composer::params::command_name,
+ default => $command_name
+ }
+
+ $composer_user = $user ? {
+ 'UNDEF' => $::composer::params::user,
+ default => $user
+ }
+
+ wget::fetch { 'composer-install':
+ source => $::composer::params::phar_location,
+ destination => "${composer_target_dir}/${composer_command_name}",
+ execuser => $composer_user,
+ }
+
+ exec { 'composer-fix-permissions':
+ command => "chmod a+x ${composer_command_name}",
+ path => '/usr/bin:/bin:/usr/sbin:/sbin',
+ cwd => $composer_target_dir,
+ user => $composer_user,
+ unless => "test -x ${composer_target_dir}/${composer_command_name}",
+ require => Wget::Fetch['composer-install'],
+ }
+
+ if $auto_update {
+ exec { 'composer-update':
+ command => "${composer_command_name} self-update",
+ path => "/usr/bin:/bin:/usr/sbin:/sbin:${composer_target_dir}",
+ user => $composer_user,
+ require => Exec['composer-fix-permissions'],
+ }
+ }
+}
diff --git a/puppet/modules/composer/manifests/params.pp b/puppet/modules/composer/manifests/params.pp
new file mode 100644
index 0000000..7e479bf
--- /dev/null
+++ b/puppet/modules/composer/manifests/params.pp
@@ -0,0 +1,20 @@
+# = Class: composer::params
+#
+# This class defines default parameters used by the main module class composer.
+# Operating Systems differences in names and paths are addressed here.
+#
+# == Variables:
+#
+# Refer to composer class for the variables defined here.
+#
+# == Usage:
+#
+# This class is not intended to be used directly.
+# It may be imported or inherited by other classes.
+#
+class composer::params {
+ $phar_location = 'http://getcomposer.org/composer.phar'
+ $target_dir = '/usr/local/bin'
+ $command_name = 'composer'
+ $user = 'root'
+}
diff --git a/puppet/modules/composer/metadata.json b/puppet/modules/composer/metadata.json
new file mode 100644
index 0000000..2af821e
--- /dev/null
+++ b/puppet/modules/composer/metadata.json
@@ -0,0 +1,28 @@
+{
+ "name": "willdurand-composer",
+ "version": "0.0.5",
+ "source": "UNKNOWN",
+ "author": "William Durand",
+ "license": "MIT",
+ "summary": "This module installs Composer, a dependency manager for PHP.",
+ "description": "This module installs Composer, a dependency manager for PHP.",
+ "project_page": "UNKNOWN",
+ "dependencies": [
+ {
+ "name": "maestrodev/wget"
+ }
+ ],
+ "types": [
+
+ ],
+ "checksums": {
+ "LICENSE": "8e55fce2ff4cd1331f7c6bc602fe7370",
+ "Modulefile": "c2f377c231fc8e8825b13223e1123aa1",
+ "README.md": "71cf0b6ffa6b38a5e3d99e2e5702d75b",
+ "Rakefile": "a1a87b266213b03b33f5e006d4df7925",
+ "manifests/init.pp": "f0991dfec070ee55e21e77b0fc5c5e54",
+ "manifests/params.pp": "b76c6afd5ff070d7b27c13489511a46b",
+ "spec/classes/composer_spec.rb": "508a399efc16fecb0d680cb7de572e0c",
+ "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc"
+ }
+}
\ No newline at end of file
diff --git a/puppet/modules/composer/spec/classes/composer_spec.rb b/puppet/modules/composer/spec/classes/composer_spec.rb
new file mode 100644
index 0000000..ecb518b
--- /dev/null
+++ b/puppet/modules/composer/spec/classes/composer_spec.rb
@@ -0,0 +1,95 @@
+require 'spec_helper'
+
+describe 'composer', :type => :class do
+ let(:title) { 'composer' }
+
+ it { should contain_wget__fetch('composer-install') \
+ .with_source('http://getcomposer.org/composer.phar') \
+ .with_execuser('root') \
+ .with_destination('/usr/local/bin/composer')
+ }
+
+ it { should contain_exec('composer-fix-permissions') \
+ .with_command('chmod a+x composer') \
+ .with_user('root') \
+ .with_cwd('/usr/local/bin')
+ }
+
+ it { should_not contain_exec('composer-update') }
+
+ describe 'with a given target_dir' do
+ let(:params) {{ :target_dir => '/usr/bin' }}
+
+ it { should contain_wget__fetch('composer-install') \
+ .with_source('http://getcomposer.org/composer.phar') \
+ .with_execuser('root') \
+ .with_destination('/usr/bin/composer')
+ }
+
+ it { should contain_exec('composer-fix-permissions') \
+ .with_command('chmod a+x composer') \
+ .with_user('root') \
+ .with_cwd('/usr/bin')
+ }
+
+ it { should_not contain_exec('composer-update') }
+ end
+
+ describe 'with a given command_name' do
+ let(:params) {{ :command_name => 'c' }}
+
+ it { should contain_wget__fetch('composer-install') \
+ .with_source('http://getcomposer.org/composer.phar') \
+ .with_execuser('root') \
+ .with_destination('/usr/local/bin/c')
+ }
+
+ it { should contain_exec('composer-fix-permissions') \
+ .with_command('chmod a+x c') \
+ .with_user('root') \
+ .with_cwd('/usr/local/bin')
+ }
+
+ it { should_not contain_exec('composer-update') }
+ end
+
+ describe 'with auto_update => true' do
+ let(:params) {{ :auto_update => true }}
+
+ it { should contain_wget__fetch('composer-install') \
+ .with_source('http://getcomposer.org/composer.phar') \
+ .with_execuser('root') \
+ .with_destination('/usr/local/bin/composer')
+ }
+
+ it { should contain_exec('composer-fix-permissions') \
+ .with_command('chmod a+x composer') \
+ .with_user('root') \
+ .with_cwd('/usr/local/bin')
+ }
+
+ it { should contain_exec('composer-update') \
+ .with_command('composer self-update') \
+ .with_user('root') \
+ .with_path('/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin')
+ }
+ end
+
+ describe 'with a given user' do
+ let(:params) {{ :user => 'will' }}
+
+ it { should contain_wget__fetch('composer-install') \
+ .with_source('http://getcomposer.org/composer.phar') \
+ .with_execuser('will') \
+ .with_destination('/usr/local/bin/composer')
+ }
+
+ it { should contain_exec('composer-fix-permissions') \
+ .with_command('chmod a+x composer') \
+ .with_user('will') \
+ .with_cwd('/usr/local/bin')
+ }
+
+ it { should_not contain_exec('composer-update') }
+ end
+end
diff --git a/puppet/modules/composer/spec/spec_helper.rb b/puppet/modules/composer/spec/spec_helper.rb
new file mode 100644
index 0000000..2c6f566
--- /dev/null
+++ b/puppet/modules/composer/spec/spec_helper.rb
@@ -0,0 +1 @@
+require 'puppetlabs_spec_helper/module_spec_helper'
diff --git a/puppet/modules/concat/CHANGELOG b/puppet/modules/concat/CHANGELOG
new file mode 100644
index 0000000..f8141d7
--- /dev/null
+++ b/puppet/modules/concat/CHANGELOG
@@ -0,0 +1,66 @@
+2013-08-09 1.0.0
+
+Summary:
+
+Many new features and bugfixes in this release, and if you're a heavy concat
+user you should test carefully before upgrading. The features should all be
+backwards compatible but only light testing has been done from our side before
+this release.
+
+Features:
+- New parameters in concat:
+ - `replace`: specify if concat should replace existing files.
+ - `ensure_newline`: controls if fragments should contain a newline at the end.
+- Improved README documentation.
+- Add rspec:system tests (rake spec:system to test concat)
+
+Bugfixes
+- Gracefully handle \n in a fragment resource name.
+- Adding more helpful message for 'pluginsync = true'
+- Allow passing `source` and `content` directly to file resource, rather than
+defining resource defaults.
+- Added -r flag to read so that filenames with \ will be read correctly.
+- sort always uses LANG=C.
+- Allow WARNMSG to contain/start with '#'.
+- Replace while-read pattern with for-do in order to support Solaris.
+
+CHANGELOG:
+- 2010/02/19 - initial release
+- 2010/03/12 - add support for 0.24.8 and newer
+ - make the location of sort configurable
+ - add the ability to add shell comment based warnings to
+ top of files
+ - add the ablity to create empty files
+- 2010/04/05 - fix parsing of WARN and change code style to match rest
+ of the code
+ - Better and safer boolean handling for warn and force
+ - Don't use hard coded paths in the shell script, set PATH
+ top of the script
+ - Use file{} to copy the result and make all fragments owned
+ by root. This means we can chnage the ownership/group of the
+ resulting file at any time.
+ - You can specify ensure => "/some/other/file" in concat::fragment
+ to include the contents of a symlink into the final file.
+- 2010/04/16 - Add more cleaning of the fragment name - removing / from the $name
+- 2010/05/22 - Improve documentation and show the use of ensure =>
+- 2010/07/14 - Add support for setting the filebucket behavior of files
+- 2010/10/04 - Make the warning message configurable
+- 2010/12/03 - Add flags to make concat work better on Solaris - thanks Jonathan Boyett
+- 2011/02/03 - Make the shell script more portable and add a config option for root group
+- 2011/06/21 - Make base dir root readable only for security
+- 2011/06/23 - Set base directory using a fact instead of hardcoding it
+- 2011/06/23 - Support operating as non privileged user
+- 2011/06/23 - Support dash instead of bash or sh
+- 2011/07/11 - Better solaris support
+- 2011/12/05 - Use fully qualified variables
+- 2011/12/13 - Improve Nexenta support
+- 2012/04/11 - Do not use any GNU specific extensions in the shell script
+- 2012/03/24 - Comply to community style guides
+- 2012/05/23 - Better errors when basedir isnt set
+- 2012/05/31 - Add spec tests
+- 2012/07/11 - Include concat::setup in concat improving UX
+- 2012/08/14 - Puppet Lint improvements
+- 2012/08/30 - The target path can be different from the $name
+- 2012/08/30 - More Puppet Lint cleanup
+- 2012/09/04 - RELEASE 0.2.0
+- 2012/12/12 - Added (file) $replace parameter to concat
diff --git a/puppet/modules/concat/Gemfile b/puppet/modules/concat/Gemfile
new file mode 100644
index 0000000..783e522
--- /dev/null
+++ b/puppet/modules/concat/Gemfile
@@ -0,0 +1,21 @@
+source 'https://rubygems.org'
+
+group :development, :test do
+ gem 'rake', :require => false
+ gem 'rspec-puppet', :require => false
+ gem 'puppetlabs_spec_helper', :require => false
+ gem 'rspec-system-puppet', :require => false
+ gem 'puppet-lint', :require => false
+ gem 'serverspec', :require => false
+ gem 'rspec-system-serverspec', :require => false
+ gem 'pry', :require => false
+ gem 'vagrant-wrapper', :require => false
+end
+
+if puppetversion = ENV['PUPPET_GEM_VERSION']
+ gem 'puppet', puppetversion, :require => false
+else
+ gem 'puppet', :require => false
+end
+
+# vim:ft=ruby
diff --git a/puppet/modules/concat/LICENSE b/puppet/modules/concat/LICENSE
new file mode 100644
index 0000000..6a9e9a1
--- /dev/null
+++ b/puppet/modules/concat/LICENSE
@@ -0,0 +1,14 @@
+ Copyright 2012 R.I.Pienaar
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
diff --git a/puppet/modules/concat/Modulefile b/puppet/modules/concat/Modulefile
new file mode 100644
index 0000000..8515b17
--- /dev/null
+++ b/puppet/modules/concat/Modulefile
@@ -0,0 +1,8 @@
+name 'puppetlabs-concat'
+version '1.0.0'
+source 'git://github.com/puppetlabs/puppetlabs-concat.git'
+author 'Puppetlabs'
+license 'Apache 2.0'
+summary 'Concat module'
+description 'Concat module'
+project_page 'http://github.com/puppetlabs/puppetlabs-concat'
diff --git a/puppet/modules/concat/README b/puppet/modules/concat/README
new file mode 100644
index 0000000..650141c
--- /dev/null
+++ b/puppet/modules/concat/README
@@ -0,0 +1,91 @@
+== Module: concat
+
+A system to construct files using fragments from other files or templates.
+
+This requires at least puppet 0.25 to work correctly as we use some
+enhancements in recursive directory management and regular expressions
+to do the work here.
+
+=== Usage:
+
+The basic use case is as below:
+
+ concat{"/etc/named.conf":
+ notify => Service["named"]
+ }
+
+ concat::fragment{"foo.com_config":
+ target => "/etc/named.conf",
+ order => 10,
+ content => template("named_conf_zone.erb")
+ }
+
+ # add a fragment not managed by puppet so local users
+ # can add content to managed file
+ concat::fragment{"foo.com_user_config":
+ target => "/etc/named.conf",
+ order => 12,
+ ensure => "/etc/named.conf.local"
+ }
+
+This will use the template named_conf_zone.erb to build a single
+bit of config up and put it into the fragments dir. The file
+will have an number prefix of 10, you can use the order option
+to control that and thus control the order the final file gets built in.
+
+You can also specify a path and use a different name for your resources:
+
+ # You can make this something dynamic, based on whatever parameters your
+ # module/class for example.
+ $vhost_file = '/etc/httpd/vhosts/01-my-vhost.conf'
+
+ concat{'apache-vhost-myvhost':
+ path => $vhost_file,
+ }
+
+ # We don't care where the file is located, just what to put in it.
+ concat::fragment {'apache-vhost-myvhost-main':
+ target => 'apache-vhost-myvhost',
+ content => '<virtualhost *:80>',
+ order => 01,
+ }
+
+ concat::fragment {'apache-vhost-myvhost-close':
+ target => 'apache-vhost-myvhost',
+ content => '</virtualhost>',
+ order => 99,
+ }
+
+=== Setup:
+
+The class concat::setup uses the fact concat_basedir to define the variable
+$concatdir, where all the temporary files and fragments will be
+durably stored. The fact concat_basedir will be set up on the client to
+<Puppet[:vardir]>/concat, so you will be able to run different setup/flavours
+of puppet clients.
+However, since this requires the file lib/facter/concat_basedir.rb to be
+deployed on the clients, so you will have to set "pluginsync = true" on
+both the master and client, at least for the first run.
+
+There's some regular expression magic to figure out the puppet version but
+if you're on an older 0.24 version just set $puppetversion = 24
+
+=== Detail:
+
+We use a helper shell script called concatfragments.sh that gets placed
+in <Puppet[:vardir]>/concat/bin to do the concatenation. While this might
+seem more complex than some of the one-liner alternatives you might find on
+the net we do a lot of error checking and safety checks in the script to avoid
+problems that might be caused by complex escaping errors etc.
+
+=== License:
+
+Apache Version 2
+
+=== Latest:
+
+http://github.com/puppetlabs/puppetlabs-concat/
+
+=== Contact:
+
+Puppetlabs, via our puppet-users@ mailing list.
diff --git a/puppet/modules/concat/README.markdown b/puppet/modules/concat/README.markdown
new file mode 100644
index 0000000..c9a52b3
--- /dev/null
+++ b/puppet/modules/concat/README.markdown
@@ -0,0 +1,154 @@
+What is it?
+===========
+
+A Puppet module that can construct files from fragments.
+
+Please see the comments in the various .pp files for details
+as well as posts on my blog at http://www.devco.net/
+
+Released under the Apache 2.0 licence
+
+Usage:
+------
+
+If you wanted a /etc/motd file that listed all the major modules
+on the machine. And that would be maintained automatically even
+if you just remove the include lines for other modules you could
+use code like below, a sample /etc/motd would be:
+
+<pre>
+Puppet modules on this server:
+
+ -- Apache
+ -- MySQL
+</pre>
+
+Local sysadmins can also append to the file by just editing /etc/motd.local
+their changes will be incorporated into the puppet managed motd.
+
+<pre>
+# class to setup basic motd, include on all nodes
+class motd {
+ $motd = "/etc/motd"
+
+ concat{$motd:
+ owner => root,
+ group => root,
+ mode => '0644',
+ }
+
+ concat::fragment{"motd_header":
+ target => $motd,
+ content => "\nPuppet modules on this server:\n\n",
+ order => 01,
+ }
+
+ # local users on the machine can append to motd by just creating
+ # /etc/motd.local
+ concat::fragment{"motd_local":
+ target => $motd,
+ ensure => "/etc/motd.local",
+ order => 15
+ }
+}
+
+# used by other modules to register themselves in the motd
+define motd::register($content="", $order=10) {
+ if $content == "" {
+ $body = $name
+ } else {
+ $body = $content
+ }
+
+ concat::fragment{"motd_fragment_$name":
+ target => "/etc/motd",
+ content => " -- $body\n"
+ }
+}
+
+# a sample apache module
+class apache {
+ include apache::install, apache::config, apache::service
+
+ motd::register{"Apache": }
+}
+</pre>
+
+Detailed documentation of the class options can be found in the
+manifest files.
+
+Known Issues:
+-------------
+* Since puppet-concat now relies on a fact for the concat directory,
+ you will need to set up pluginsync = true on the [master] section of your
+ node's '/etc/puppet/puppet.conf' for at least the first run.
+ You have this issue if puppet fails to run on the client and you have
+ a message similar to
+ "err: Failed to apply catalog: Parameter path failed: File
+ paths must be fully qualified, not 'undef' at [...]/concat/manifests/setup.pp:44".
+
+Contributors:
+-------------
+**Paul Elliot**
+
+ * Provided 0.24.8 support, shell warnings and empty file creation support.
+
+**Chad Netzer**
+
+ * Various patches to improve safety of file operations
+ * Symlink support
+
+**David Schmitt**
+
+ * Patch to remove hard coded paths relying on OS path
+ * Patch to use file{} to copy the resulting file to the final destination. This means Puppet client will show diffs and that hopefully we can change file ownerships now
+
+**Peter Meier**
+
+ * Basedir as a fact
+ * Unprivileged user support
+
+**Sharif Nassar**
+
+ * Solaris/Nexenta support
+ * Better error reporting
+
+**Christian G. Warden**
+
+ * Style improvements
+
+**Reid Vandewiele**
+
+ * Support non GNU systems by default
+
+**Erik Dalén**
+
+ * Style improvements
+
+**Gildas Le Nadan**
+
+ * Documentation improvements
+
+**Paul Belanger**
+
+ * Testing improvements and Travis support
+
+**Branan Purvine-Riley**
+
+ * Support Puppet Module Tool better
+
+**Dustin J. Mitchell**
+
+ * Always include setup when using the concat define
+
+**Andreas Jaggi**
+
+ * Puppet Lint support
+
+**Jan Vansteenkiste**
+
+ * Configurable paths
+
+Contact:
+--------
+puppet-users@ mailing list.
diff --git a/puppet/modules/concat/Rakefile b/puppet/modules/concat/Rakefile
new file mode 100644
index 0000000..bb60173
--- /dev/null
+++ b/puppet/modules/concat/Rakefile
@@ -0,0 +1,2 @@
+require 'puppetlabs_spec_helper/rake_tasks'
+require 'rspec-system/rake_task'
diff --git a/puppet/modules/concat/files/concatfragments.sh b/puppet/modules/concat/files/concatfragments.sh
new file mode 100644
index 0000000..570d553
--- /dev/null
+++ b/puppet/modules/concat/files/concatfragments.sh
@@ -0,0 +1,140 @@
+#!/bin/sh
+
+# Script to concat files to a config file.
+#
+# Given a directory like this:
+# /path/to/conf.d
+# |-- fragments
+# | |-- 00_named.conf
+# | |-- 10_domain.net
+# | `-- zz_footer
+#
+# The script supports a test option that will build the concat file to a temp location and
+# use /usr/bin/cmp to verify if it should be run or not. This would result in the concat happening
+# twice on each run but gives you the option to have an unless option in your execs to inhibit rebuilds.
+#
+# Without the test option and the unless combo your services that depend on the final file would end up
+# restarting on each run, or in other manifest models some changes might get missed.
+#
+# OPTIONS:
+# -o The file to create from the sources
+# -d The directory where the fragments are kept
+# -t Test to find out if a build is needed, basically concats the files to a temp
+# location and compare with what's in the final location, return codes are designed
+# for use with unless on an exec resource
+# -w Add a shell style comment at the top of the created file to warn users that it
+# is generated by puppet
+# -f Enables the creation of empty output files when no fragments are found
+# -n Sort the output numerically rather than the default alpha sort
+#
+# the command:
+#
+# concatfragments.sh -o /path/to/conffile.cfg -d /path/to/conf.d
+#
+# creates /path/to/conf.d/fragments.concat and copies the resulting
+# file to /path/to/conffile.cfg. The files will be sorted alphabetically
+# pass the -n switch to sort numerically.
+#
+# The script does error checking on the various dirs and files to make
+# sure things don't fail.
+
+OUTFILE=""
+WORKDIR=""
+TEST=""
+FORCE=""
+WARN=""
+SORTARG=""
+ENSURE_NEWLINE=""
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+
+## Well, if there's ever a bad way to do things, Nexenta has it.
+## http://nexenta.org/projects/site/wiki/Personalities
+unset SUN_PERSONALITY
+
+while getopts "o:s:d:tnw:fl" options; do
+ case $options in
+ o ) OUTFILE=$OPTARG;;
+ d ) WORKDIR=$OPTARG;;
+ n ) SORTARG="-n";;
+ w ) WARNMSG="$OPTARG";;
+ f ) FORCE="true";;
+ t ) TEST="true";;
+ l ) ENSURE_NEWLINE="true";;
+ * ) echo "Specify output file with -o and fragments directory with -d"
+ exit 1;;
+ esac
+done
+
+# do we have -o?
+if [ x${OUTFILE} = "x" ]; then
+ echo "Please specify an output file with -o"
+ exit 1
+fi
+
+# do we have -d?
+if [ x${WORKDIR} = "x" ]; then
+ echo "Please fragments directory with -d"
+ exit 1
+fi
+
+# can we write to -o?
+if [ -f ${OUTFILE} ]; then
+ if [ ! -w ${OUTFILE} ]; then
+ echo "Cannot write to ${OUTFILE}"
+ exit 1
+ fi
+else
+ if [ ! -w `dirname ${OUTFILE}` ]; then
+ echo "Cannot write to `dirname ${OUTFILE}` to create ${OUTFILE}"
+ exit 1
+ fi
+fi
+
+# do we have a fragments subdir inside the work dir?
+if [ ! -d "${WORKDIR}/fragments" ] && [ ! -x "${WORKDIR}/fragments" ]; then
+ echo "Cannot access the fragments directory"
+ exit 1
+fi
+
+# are there actually any fragments?
+if [ ! "$(ls -A ${WORKDIR}/fragments)" ]; then
+ if [ x${FORCE} = "x" ]; then
+ echo "The fragments directory is empty, cowardly refusing to make empty config files"
+ exit 1
+ fi
+fi
+
+cd ${WORKDIR}
+
+if [ "x${WARNMSG}" = "x" ]; then
+ : > "fragments.concat"
+else
+ printf '%s\n' "$WARNMSG" > "fragments.concat"
+fi
+
+if [ x${ENSURE_NEWLINE} != x ]; then
+ find fragments/ -type f -follow -print0 | xargs -0 -I '{}' sh -c 'if [ -n "$(tail -c 1 < {} )" ]; then echo >> {} ; fi'
+fi
+
+# find all the files in the fragments directory, sort them numerically and concat to fragments.concat in the working dir
+IFS_BACKUP=$IFS
+IFS='
+'
+for fragfile in `find fragments/ -type f -follow | LANG=C sort ${SORTARG}`
+do
+ cat $fragfile >> "fragments.concat"
+done
+IFS=$IFS_BACKUP
+
+if [ x${TEST} = "x" ]; then
+ # This is a real run, copy the file to outfile
+ cp fragments.concat ${OUTFILE}
+ RETVAL=$?
+else
+ # Just compare the result to outfile to help the exec decide
+ cmp ${OUTFILE} fragments.concat
+ RETVAL=$?
+fi
+
+exit $RETVAL
diff --git a/puppet/modules/concat/files/null/.gitignore b/puppet/modules/concat/files/null/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/puppet/modules/concat/lib/facter/concat_basedir.rb b/puppet/modules/concat/lib/facter/concat_basedir.rb
new file mode 100644
index 0000000..ef5a689
--- /dev/null
+++ b/puppet/modules/concat/lib/facter/concat_basedir.rb
@@ -0,0 +1,11 @@
+# == Fact: concat_basedir
+#
+# A custom fact that sets the default location for fragments
+#
+# "${::vardir}/concat/"
+#
+Facter.add("concat_basedir") do
+ setcode do
+ File.join(Puppet[:vardir],"concat")
+ end
+end
diff --git a/puppet/modules/concat/manifests/fragment.pp b/puppet/modules/concat/manifests/fragment.pp
new file mode 100644
index 0000000..a6831f8
--- /dev/null
+++ b/puppet/modules/concat/manifests/fragment.pp
@@ -0,0 +1,67 @@
+# == Define: concat::fragment
+#
+# Puts a file fragment into a directory previous setup using concat
+#
+# === Options:
+#
+# [*target*]
+# The file that these fragments belong to
+# [*content*]
+# If present puts the content into the file
+# [*source*]
+# If content was not specified, use the source
+# [*order*]
+# By default all files gets a 10_ prefix in the directory you can set it to
+# anything else using this to influence the order of the content in the file
+# [*ensure*]
+# Present/Absent or destination to a file to include another file
+# [*mode*]
+# Mode for the file
+# [*owner*]
+# Owner of the file
+# [*group*]
+# Owner of the file
+# [*backup*]
+# Controls the filebucketing behavior of the final file and see File type
+# reference for its use. Defaults to 'puppet'
+#
+define concat::fragment(
+ $target,
+ $content=undef,
+ $source=undef,
+ $order=10,
+ $ensure = 'present',
+ $mode = '0644',
+ $owner = $::id,
+ $group = $concat::setup::root_group,
+ $backup = 'puppet') {
+ $safe_name = regsubst($name, '[/\n]', '_', 'GM')
+ $safe_target_name = regsubst($target, '[/\n]', '_', 'GM')
+ $concatdir = $concat::setup::concatdir
+ $fragdir = "${concatdir}/${safe_target_name}"
+
+ # if content is passed, use that, else if source is passed use that
+ # if neither passed, but $ensure is in symlink form, make a symlink
+ case $ensure {
+ '', 'absent', 'present', 'file', 'directory': {
+ if ! ($content or $source) {
+ crit('No content, source or symlink specified')
+ }
+ }
+ default: {
+ # do nothing, make puppet-lint happy
+ }
+ }
+
+ file{"${fragdir}/fragments/${order}_${safe_name}":
+ ensure => $ensure,
+ mode => $mode,
+ owner => $owner,
+ group => $group,
+ source => $source,
+ content => $content,
+ backup => $backup,
+ alias => "concat_fragment_${name}",
+ notify => Exec["concat_${target}"]
+ }
+}
diff --git a/puppet/modules/concat/manifests/init.pp b/puppet/modules/concat/manifests/init.pp
new file mode 100644
index 0000000..ed4068b
--- /dev/null
+++ b/puppet/modules/concat/manifests/init.pp
@@ -0,0 +1,190 @@
+# == Define: concat
+#
+# Sets up so that you can use fragments to build a final config file,
+#
+# === Options:
+#
+# [*path*]
+# The path to the final file. Use this in case you want to differentiate
+# between the name of a resource and the file path. Note: Use the name you
+# provided in the target of your fragments.
+# [*mode*]
+# The mode of the final file
+# [*owner*]
+# Who will own the file
+# [*group*]
+# Who will own the file
+# [*force*]
+# Enables creating empty files if no fragments are present
+# [*warn*]
+# Adds a normal shell style comment top of the file indicating that it is
+# built by puppet
+# [*backup*]
+# Controls the filebucketing behavior of the final file and see File type
+# reference for its use. Defaults to 'puppet'
+# [*replace*]
+# Whether to replace a file that already exists on the local system
+#
+# === Actions:
+# * Creates fragment directories if it didn't exist already
+# * Executes the concatfragments.sh script to build the final file, this
+# script will create directory/fragments.concat. Execution happens only
+# when:
+# * The directory changes
+# * fragments.concat != final destination, this means rebuilds will happen
+# whenever someone changes or deletes the final file. Checking is done
+# using /usr/bin/cmp.
+# * The Exec gets notified by something else - like the concat::fragment
+# define
+# * Copies the file over to the final destination using a file resource
+#
+# === Aliases:
+#
+# * The exec can notified using Exec["concat_/path/to/file"] or
+# Exec["concat_/path/to/directory"]
+# * The final file can be referened as File["/path/to/file"] or
+# File["concat_/path/to/file"]
+#
+define concat(
+ $path = $name,
+ $owner = $::id,
+ $group = $concat::setup::root_group,
+ $mode = '0644',
+ $warn = false,
+ $force = false,
+ $backup = 'puppet',
+ $replace = true,
+ $gnu = undef,
+ $order='alpha',
+ $ensure_newline = false
+) {
+ include concat::setup
+
+ $safe_name = regsubst($name, '/', '_', 'G')
+ $concatdir = $concat::setup::concatdir
+ $version = $concat::setup::majorversion
+ $fragdir = "${concatdir}/${safe_name}"
+ $concat_name = 'fragments.concat.out'
+ $default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.'
+
+ case $warn {
+ 'true', true, yes, on: {
+ $warnmsg = $default_warn_message
+ }
+ 'false', false, no, off: {
+ $warnmsg = ''
+ }
+ default: {
+ $warnmsg = $warn
+ }
+ }
+
+ $warnmsg_escaped = regsubst($warnmsg, "'", "'\\\\''", 'G')
+ $warnflag = $warnmsg_escaped ? {
+ '' => '',
+ default => "-w '${warnmsg_escaped}'"
+ }
+
+ case $force {
+ 'true', true, yes, on: {
+ $forceflag = '-f'
+ }
+ 'false', false, no, off: {
+ $forceflag = ''
+ }
+ default: {
+ fail("Improper 'force' value given to concat: ${force}")
+ }
+ }
+
+ case $order {
+ numeric: {
+ $orderflag = '-n'
+ }
+ alpha: {
+ $orderflag = ''
+ }
+ default: {
+ fail("Improper 'order' value given to concat: ${order}")
+ }
+ }
+
+ case $ensure_newline {
+ 'true', true, yes, on: {
+ $newlineflag = '-l'
+ }
+ 'false', false, no, off: {
+ $newlineflag = ''
+ }
+ default: {
+ fail("Improper 'ensure_newline' value given to concat: ${ensure_newline}")
+ }
+ }
+
+ File {
+ owner => $::id,
+ group => $group,
+ mode => $mode,
+ backup => $backup,
+ replace => $replace
+ }
+
+ file { $fragdir:
+ ensure => directory,
+ }
+
+ $source_real = $version ? {
+ 24 => 'puppet:///concat/null',
+ default => undef,
+ }
+
+ file { "${fragdir}/fragments":
+ ensure => directory,
+ force => true,
+ ignore => ['.svn', '.git', '.gitignore'],
+ notify => Exec["concat_${name}"],
+ purge => true,
+ recurse => true,
+ source => $source_real,
+ }
+
+ file { "${fragdir}/fragments.concat":
+ ensure => present,
+ }
+
+ file { "${fragdir}/${concat_name}":
+ ensure => present,
+ }
+
+ file { $name:
+ ensure => present,
+ path => $path,
+ alias => "concat_${name}",
+ group => $group,
+ mode => $mode,
+ owner => $owner,
+ source => "${fragdir}/${concat_name}",
+ }
+
+ exec { "concat_${name}":
+ alias => "concat_${fragdir}",
+ command => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} ${warnflag} ${forceflag} ${orderflag} ${newlineflag}",
+ notify => File[$name],
+ require => [
+ File[$fragdir],
+ File["${fragdir}/fragments"],
+ File["${fragdir}/fragments.concat"],
+ ],
+ subscribe => File[$fragdir],
+ unless => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} -t ${warnflag} ${forceflag} ${orderflag} ${newlineflag}",
+ }
+
+ if $::id == 'root' {
+ Exec["concat_${name}"] {
+ user => root,
+ group => $group,
+ }
+ }
+}
+
+# vim:sw=2:ts=2:expandtab:textwidth=79
diff --git a/puppet/modules/concat/manifests/setup.pp b/puppet/modules/concat/manifests/setup.pp
new file mode 100644
index 0000000..2d29bf8
--- /dev/null
+++ b/puppet/modules/concat/manifests/setup.pp
@@ -0,0 +1,55 @@
+# === Class: concat::setup
+#
+# Sets up the concat system.
+#
+# [$concatdir]
+# is where the fragments live and is set on the fact concat_basedir.
+# Since puppet should always manage files in $concatdir and they should
+# not be deleted ever, /tmp is not an option.
+#
+# [$puppetversion]
+# should be either 24 or 25 to enable a 24 compatible
+# mode, in 24 mode you might see phantom notifies this is a side effect
+# of the method we use to clear the fragments directory.
+#
+# The regular expression below will try to figure out your puppet version
+# but this code will only work in 0.24.8 and newer.
+#
+# It also copies out the concatfragments.sh file to ${concatdir}/bin
+#
+class concat::setup {
+ $id = $::id
+ $root_group = $id ? {
+ root => 0,
+ default => $id
+ }
+
+ if $::concat_basedir {
+ $concatdir = $::concat_basedir
+ } else {
+ fail ("\$concat_basedir not defined. Try running again with pluginsync=true on the [master] section of your node's '/etc/puppet/puppet.conf'.")
+ }
+
+ $majorversion = regsubst($::puppetversion, '^[0-9]+[.]([0-9]+)[.][0-9]+$', '\1')
+ $fragments_source = $majorversion ? {
+ 24 => 'puppet:///concat/concatfragments.sh',
+ default => 'puppet:///modules/concat/concatfragments.sh'
+ }
+
+ file{"${concatdir}/bin/concatfragments.sh":
+ owner => $id,
+ group => $root_group,
+ mode => '0755',
+ source => $fragments_source;
+
+ [ $concatdir, "${concatdir}/bin" ]:
+ ensure => directory,
+ owner => $id,
+ group => $root_group,
+ mode => '0750';
+
+ ## Old versions of this module used a different path.
+ '/usr/local/bin/concatfragments.sh':
+ ensure => absent;
+ }
+}
diff --git a/puppet/modules/concat/metadata.json b/puppet/modules/concat/metadata.json
new file mode 100644
index 0000000..28f080e
--- /dev/null
+++ b/puppet/modules/concat/metadata.json
@@ -0,0 +1,39 @@
+{
+ "name": "puppetlabs-concat",
+ "version": "1.0.0",
+ "source": "git://github.com/puppetlabs/puppetlabs-concat.git",
+ "author": "Puppetlabs",
+ "license": "Apache 2.0",
+ "summary": "Concat module",
+ "description": "Concat module",
+ "project_page": "http://github.com/puppetlabs/puppetlabs-concat",
+ "dependencies": [
+
+ ],
+ "types": [
+
+ ],
+ "checksums": {
+ "CHANGELOG": "89220fae3ab04a350132fe94d7a6ca00",
+ "Gemfile": "a913d6f7a0420e07539d8ff1ef047ffb",
+ "LICENSE": "f5a76685d453424cd63dde1535811cf0",
+ "Modulefile": "f99ee2f6778b9e23635ac1027888bbd3",
+ "README": "d15ec3400f628942dd7b7fa8c1a18da3",
+ "README.markdown": "d82e203d729ea4785bdcaca1be166e62",
+ "Rakefile": "0428ea3759a4692c91604396c406a9c1",
+ "files/concatfragments.sh": "2fbba597a1513eb61229551d35d42b9f",
+ "lib/facter/concat_basedir.rb": "e152593fafe27ef305fc473929c62ca6",
+ "manifests/fragment.pp": "196ee8e405b3a31b84ae618ed54377ed",
+ "manifests/init.pp": "8d0cc8e9cf145ca7a23db05a30252476",
+ "manifests/setup.pp": "2246572410d94c68aff310f8132c55b4",
+ "spec/defines/init_spec.rb": "35e41d4abceba0dca090d3addd92bb4f",
+ "spec/fixtures/manifests/site.pp": "d41d8cd98f00b204e9800998ecf8427e",
+ "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc",
+ "spec/spec_helper_system.rb": "9c3742bf87d62027f080c6b9fa98b979",
+ "spec/system/basic_spec.rb": "9135d9af6a21f16980ab59b58e91ed9a",
+ "spec/system/concat_spec.rb": "5fe675ec42ca441d0c7e431c31bbc238",
+ "spec/system/empty_spec.rb": "51ab1fc7c86268f1ab1cda72dc5ff583",
+ "spec/system/replace_spec.rb": "275295e6b4f04fc840dc3f87faf56249",
+ "spec/system/warn_spec.rb": "0ea35b44e8f0ac5352256f95115995ce"
+ }
+}
\ No newline at end of file
diff --git a/puppet/modules/concat/spec/defines/init_spec.rb b/puppet/modules/concat/spec/defines/init_spec.rb
new file mode 100644
index 0000000..ace50f0
--- /dev/null
+++ b/puppet/modules/concat/spec/defines/init_spec.rb
@@ -0,0 +1,115 @@
+require 'spec_helper'
+
+describe 'concat' do
+ basedir = '/var/lib/puppet/concat'
+ let(:title) { '/etc/foo.bar' }
+ let(:facts) { {
+ :concat_basedir => '/var/lib/puppet/concat',
+ :id => 'root',
+ } }
+ let :pre_condition do
+ 'include concat::setup'
+ end
+
+ directories = [
+ "#{basedir}/_etc_foo.bar",
+ "#{basedir}/_etc_foo.bar/fragments",
+ ]
+
+ directories.each do |dirs|
+ it do
+ should contain_file(dirs).with({
+ 'ensure' => 'directory',
+ 'backup' => 'puppet',
+ 'group' => 0,
+ 'mode' => '0644',
+ 'owner' => 'root',
+ })
+ end
+ end
+
+ files = [
+ "/etc/foo.bar",
+ "#{basedir}/_etc_foo.bar/fragments.concat",
+ ]
+
+ files.each do |file|
+ it do
+ should contain_file(file).with({
+ 'ensure' => 'present',
+ 'backup' => 'puppet',
+ 'group' => 0,
+ 'mode' => '0644',
+ 'owner' => 'root',
+ })
+ end
+ end
+
+ it do
+ should contain_exec("concat_/etc/foo.bar").with_command(
+ "#{basedir}/bin/concatfragments.sh " +
+ "-o #{basedir}/_etc_foo.bar/fragments.concat.out " +
+ "-d #{basedir}/_etc_foo.bar "
+ )
+ end
+end
+
+describe 'concat' do
+
+ basedir = '/var/lib/puppet/concat'
+ let(:title) { 'foobar' }
+ let(:target) { '/etc/foo.bar' }
+ let(:facts) { {
+ :concat_basedir => '/var/lib/puppet/concat',
+ :id => 'root',
+ } }
+ let :pre_condition do
+ 'include concat::setup'
+ end
+
+ directories = [
+ "#{basedir}/foobar",
+ "#{basedir}/foobar/fragments",
+ ]
+
+ directories.each do |dirs|
+ it do
+ should contain_file(dirs).with({
+ 'ensure' => 'directory',
+ 'backup' => 'puppet',
+ 'group' => 0,
+ 'mode' => '0644',
+ 'owner' => 'root',
+ })
+ end
+ end
+
+ files = [
+ "foobar",
+ "#{basedir}/foobar/fragments.concat",
+ ]
+
+ files.each do |file|
+ it do
+ should contain_file(file).with({
+ 'ensure' => 'present',
+ 'backup' => 'puppet',
+ 'group' => 0,
+ 'mode' => '0644',
+ 'owner' => 'root',
+ })
+ end
+ end
+
+ it do
+ should contain_exec("concat_foobar").with_command(
+ "#{basedir}/bin/concatfragments.sh " +
+ "-o #{basedir}/foobar/fragments.concat.out " +
+ "-d #{basedir}/foobar "
+ )
+ end
+
+
+end
+
+# vim:sw=2:ts=2:expandtab:textwidth=79
diff --git a/puppet/modules/concat/spec/fixtures/manifests/site.pp b/puppet/modules/concat/spec/fixtures/manifests/site.pp
new file mode 100644
index 0000000..e69de29
diff --git a/puppet/modules/concat/spec/spec_helper.rb b/puppet/modules/concat/spec/spec_helper.rb
new file mode 100644
index 0000000..2c6f566
--- /dev/null
+++ b/puppet/modules/concat/spec/spec_helper.rb
@@ -0,0 +1 @@
+require 'puppetlabs_spec_helper/module_spec_helper'
diff --git a/puppet/modules/concat/spec/spec_helper_system.rb b/puppet/modules/concat/spec/spec_helper_system.rb
new file mode 100644
index 0000000..bf66a53
--- /dev/null
+++ b/puppet/modules/concat/spec/spec_helper_system.rb
@@ -0,0 +1,25 @@
+require 'rspec-system/spec_helper'
+require 'rspec-system-puppet/helpers'
+require 'rspec-system-serverspec/helpers'
+include Serverspec::Helper::RSpecSystem
+include Serverspec::Helper::DetectOS
+include RSpecSystemPuppet::Helpers
+
+RSpec.configure do |c|
+ # Project root
+ proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+
+ # Enable colour
+ c.tty = true
+
+ c.include RSpecSystemPuppet::Helpers
+
+ # This is where we 'setup' the nodes before running our tests
+ c.before :suite do
+ # Install puppet
+ puppet_install
+
+ # Install modules and dependencies
+ puppet_module_install(:source => proj_root, :module_name => 'concat')
+ end
+end
diff --git a/puppet/modules/concat/spec/system/basic_spec.rb b/puppet/modules/concat/spec/system/basic_spec.rb
new file mode 100644
index 0000000..39ac746
--- /dev/null
+++ b/puppet/modules/concat/spec/system/basic_spec.rb
@@ -0,0 +1,13 @@
+require 'spec_helper_system'
+
+# Here we put the more basic fundamental tests, ultra obvious stuff.
+describe "basic tests:" do
+ context 'make sure we have copied the module across' do
+ # No point diagnosing any more if the module wasn't copied properly
+ context shell 'ls /etc/puppet/modules/concat' do
+ its(:stdout) { should =~ /Modulefile/ }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+ end
+end
diff --git a/puppet/modules/concat/spec/system/concat_spec.rb b/puppet/modules/concat/spec/system/concat_spec.rb
new file mode 100644
index 0000000..af360d6
--- /dev/null
+++ b/puppet/modules/concat/spec/system/concat_spec.rb
@@ -0,0 +1,55 @@
+require 'spec_helper_system'
+
+describe 'basic concat test' do
+ context 'should run successfully' do
+ pp="
+ concat { '/tmp/file':
+ owner => root,
+ group => root,
+ mode => '0644',
+ }
+
+ concat::fragment { '1':
+ target => '/tmp/file',
+ content => '1',
+ order => '01',
+ }
+
+ concat::fragment { '2':
+ target => '/tmp/file',
+ content => '2',
+ order => '02',
+ }
+ "
+
+ context puppet_apply(pp) do
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should_not == 1 }
+ its(:refresh) { should be_nil }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+
+ describe file('/tmp/file') do
+ it { should be_file }
+ it { should contain '1' }
+ it { should contain '2' }
+ end
+
+ # Test that all the relevant bits exist on disk after it
+ # concats.
+ describe file('/var/lib/puppet/concat') do
+ it { should be_directory }
+ end
+ describe file('/var/lib/puppet/concat/_tmp_file') do
+ it { should be_directory }
+ end
+ describe file('/var/lib/puppet/concat/_tmp_file/fragments') do
+ it { should be_directory }
+ end
+ describe file('/var/lib/puppet/concat/_tmp_file/fragments.concat') do
+ it { should be_file }
+ end
+
+ end
+end
diff --git a/puppet/modules/concat/spec/system/empty_spec.rb b/puppet/modules/concat/spec/system/empty_spec.rb
new file mode 100644
index 0000000..83dae01
--- /dev/null
+++ b/puppet/modules/concat/spec/system/empty_spec.rb
@@ -0,0 +1,27 @@
+require 'spec_helper_system'
+
+describe 'basic concat test' do
+ context 'should run successfully' do
+ pp="
+ concat { '/tmp/file':
+ owner => root,
+ group => root,
+ mode => '0644',
+ force => true,
+ }
+ "
+
+ context puppet_apply(pp) do
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should_not == 1 }
+ its(:refresh) { should be_nil }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+
+ describe file('/tmp/file') do
+ it { should be_file }
+ it { should_not contain '1\n2' }
+ end
+ end
+end
diff --git a/puppet/modules/concat/spec/system/replace_spec.rb b/puppet/modules/concat/spec/system/replace_spec.rb
new file mode 100644
index 0000000..7f11e5f
--- /dev/null
+++ b/puppet/modules/concat/spec/system/replace_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper_system'
+
+
+describe 'file should not replace' do
+ shell('echo "file exists" >> /tmp/file')
+ context 'should fail' do
+ pp="
+ concat { '/tmp/file':
+ owner => root,
+ group => root,
+ mode => '0644',
+ replace => false,
+ }
+
+ concat::fragment { '1':
+ target => '/tmp/file',
+ content => '1',
+ order => '01',
+ }
+
+ concat::fragment { '2':
+ target => '/tmp/file',
+ content => '2',
+ order => '02',
+ }
+ "
+
+ context puppet_apply(pp) do
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should_not == 1 }
+ its(:refresh) { should be_nil }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+
+ end
+end
diff --git a/puppet/modules/concat/spec/system/warn_spec.rb b/puppet/modules/concat/spec/system/warn_spec.rb
new file mode 100644
index 0000000..872058b
--- /dev/null
+++ b/puppet/modules/concat/spec/system/warn_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper_system'
+
+describe 'basic concat test' do
+ context 'should run successfully' do
+ pp="
+ concat { '/tmp/file':
+ owner => root,
+ group => root,
+ mode => '0644',
+ warn => true,
+ }
+
+ concat::fragment { '1':
+ target => '/tmp/file',
+ content => '1',
+ order => '01',
+ }
+
+ concat::fragment { '2':
+ target => '/tmp/file',
+ content => '2',
+ order => '02',
+ }
+ "
+
+ context puppet_apply(pp) do
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should_not == 1 }
+ its(:refresh) { should be_nil }
+ its(:stderr) { should be_empty }
+ its(:exit_code) { should be_zero }
+ end
+
+ describe file('/tmp/file') do
+ it { should be_file }
+ it { should contain '# This file is managed by Puppet. DO NOT EDIT.' }
+ it { should contain '1' }
+ it { should contain '2' }
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/CHANGELOG b/puppet/modules/stdlib/CHANGELOG
new file mode 100644
index 0000000..e1a095f
--- /dev/null
+++ b/puppet/modules/stdlib/CHANGELOG
@@ -0,0 +1,278 @@
+2013-05-06 - Jeff McCune <jeff@puppetlabs.com> - 4.1.0
+ * (#20582) Restore facter_dot_d to stdlib for PE users (3b887c8)
+ * (maint) Update Gemfile with GEM_FACTER_VERSION (f44d535)
+
+2013-05-06 - Alex Cline <acline@us.ibm.com> - 4.1.0
+ * Terser method of string to array conversion courtesy of ethooz. (d38bce0)
+
+2013-05-06 - Alex Cline <acline@us.ibm.com> 4.1.0
+ * Refactor ensure_resource expectations (b33cc24)
+
+2013-05-06 - Alex Cline <acline@us.ibm.com> 4.1.0
+ * Changed str-to-array conversion and removed abbreviation. (de253db)
+
+2013-05-03 - Alex Cline <acline@us.ibm.com> 4.1.0
+ * (#20548) Allow an array of resource titles to be passed into the ensure_resource function (e08734a)
+
+2013-05-02 - Raphaël Pinson <raphael.pinson@camptocamp.com> - 4.1.0
+ * Add a dirname function (2ba9e47)
+
+2013-04-29 - Mark Smith-Guerrero <msmithgu@gmail.com> - 4.1.0
+ * (maint) Fix a small typo in hash() description (928036a)
+
+2013-04-12 - Jeff McCune <jeff@puppetlabs.com> - 4.0.2
+ * Update user information in gemspec to make the intent of the Gem clear.
+
+2013-04-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.1
+ * Fix README function documentation (ab3e30c)
+
+2013-04-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
+ * stdlib 4.0 drops support with Puppet 2.7
+ * stdlib 4.0 preserves support with Puppet 3
+
+2013-04-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
+ * Add ability to use puppet from git via bundler (9c5805f)
+
+2013-04-10 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
+ * (maint) Make stdlib usable as a Ruby GEM (e81a45e)
+
+2013-04-10 - Erik Dalén <dalen@spotify.com> - 4.0.0
+ * Add a count function (f28550e)
+
+2013-03-31 - Amos Shapira <ashapira@atlassian.com> - 4.0.0
+ * (#19998) Implement any2array (7a2fb80)
+
+2013-03-29 - Steve Huff <shuff@vecna.org> - 4.0.0
+ * (19864) num2bool match fix (8d217f0)
+
+2013-03-20 - Erik Dalén <dalen@spotify.com> - 4.0.0
+ * Allow comparisons of Numeric and number as String (ff5dd5d)
+
+2013-03-26 - Richard Soderberg <rsoderberg@mozilla.com> - 4.0.0
+ * add suffix function to accompany the prefix function (88a93ac)
+
+2013-03-19 - Kristof Willaert <kristof.willaert@gmail.com> - 4.0.0
+ * Add floor function implementation and unit tests (0527341)
+
+2012-04-03 - Eric Shamow <eric@puppetlabs.com> - 4.0.0
+ * (#13610) Add is_function_available to stdlib (961dcab)
+
+2012-12-17 - Justin Lambert <jlambert@eml.cc> - 4.0.0
+ * str2bool should return a boolean if called with a boolean (5d5a4d4)
+
+2012-10-23 - Uwe Stuehler <ustuehler@team.mobile.de> - 4.0.0
+ * Fix number of arguments check in flatten() (e80207b)
+
+2013-03-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
+ * Add contributing document (96e19d0)
+
+2013-03-04 - Raphaël Pinson <raphael.pinson@camptocamp.com> - 4.0.0
+ * Add missing documentation for validate_augeas and validate_cmd to README.markdown (a1510a1)
+
+2013-02-14 - Joshua Hoblitt <jhoblitt@cpan.org> - 4.0.0
+ * (#19272) Add has_element() function (95cf3fe)
+
+2013-02-07 - Raphaël Pinson <raphael.pinson@camptocamp.com> - 4.0.0
+ * validate_cmd(): Use Puppet::Util::Execution.execute when available (69248df)
+
+2012-12-06 - Raphaël Pinson <raphink@gmail.com> - 4.0.0
+ * Add validate_augeas function (3a97c23)
+
+2012-12-06 - Raphaël Pinson <raphink@gmail.com> - 4.0.0
+ * Add validate_cmd function (6902cc5)
+
+2013-01-14 - David Schmitt <david@dasz.at> - 4.0.0
+ * Add geppetto project definition (b3fc0a3)
+
+2013-01-02 - Jaka Hudoklin <jakahudoklin@gmail.com> - 4.0.0
+ * Add getparam function to get defined resource parameters (20e0e07)
+
+2013-01-05 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
+ * (maint) Add Travis CI Support (d082046)
+
+2012-12-04 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
+ * Clarify that stdlib 3 supports Puppet 3 (3a6085f)
+
+2012-11-30 - Erik Dalén <dalen@spotify.com> - 4.0.0
+ * maint: style guideline fixes (7742e5f)
+
+2012-11-09 - James Fryman <james@frymanet.com> - 4.0.0
+ * puppet-lint cleanup (88acc52)
+
+2012-11-06 - Joe Julian <me@joejulian.name> - 4.0.0
+ * Add function, uriescape, to URI.escape strings. Redmine #17459 (fd52b8d)
+
+2012-09-18 - Chad Metcalf <chad@wibidata.com> - 3.2.0
+ * Add an ensure_packages function. (8a8c09e)
+
+2012-11-23 - Erik Dalén <dalen@spotify.com> - 3.2.0
+ * (#17797) min() and max() functions (9954133)
+
+2012-05-23 - Peter Meier <peter.meier@immerda.ch> - 3.2.0
+ * (#14670) autorequire a file_line resource's path (dfcee63)
+
+2012-11-19 - Joshua Harlan Lifton <lifton@puppetlabs.com> - 3.2.0
+ * Add join_keys_to_values function (ee0f2b3)
+
+2012-11-17 - Joshua Harlan Lifton <lifton@puppetlabs.com> - 3.2.0
+ * Extend delete function for strings and hashes (7322e4d)
+
+2012-08-03 - Gary Larizza <gary@puppetlabs.com> - 3.2.0
+ * Add the pick() function (ba6dd13)
+
+2012-03-20 - Wil Cooley <wcooley@pdx.edu> - 3.2.0
+ * (#13974) Add predicate functions for interface facts (f819417)
+
+2012-11-06 - Joe Julian <me@joejulian.name> - 3.2.0
+ * Add function, uriescape, to URI.escape strings. Redmine #17459 (70f4a0e)
+
+2012-10-25 - Jeff McCune <jeff@puppetlabs.com> - 3.1.1
+ * (maint) Fix spec failures resulting from Facter API changes (97f836f)
+
+2012-10-23 - Matthaus Owens <matthaus@puppetlabs.com> - 3.1.0
+ * Add PE facts to stdlib (cdf3b05)
+
+2012-08-16 - Jeff McCune <jeff@puppetlabs.com> - 3.0.1
+ * Fix accidental removal of facts_dot_d.rb in 3.0.0 release
+
+2012-08-16 - Jeff McCune <jeff@puppetlabs.com> - 3.0.0
+ * stdlib 3.0 drops support with Puppet 2.6
+ * stdlib 3.0 preserves support with Puppet 2.7
+
+2012-08-07 - Dan Bode <dan@puppetlabs.com> - 3.0.0
+ * Add function ensure_resource and defined_with_params (ba789de)
+
+2012-07-10 - Hailee Kenney <hailee@puppetlabs.com> - 3.0.0
+ * (#2157) Remove facter_dot_d for compatibility with external facts (f92574f)
+
+2012-04-10 - Chris Price <chris@puppetlabs.com> - 3.0.0
+ * (#13693) moving logic from local spec_helper to puppetlabs_spec_helper (85f96df)
+
+2012-10-25 - Jeff McCune <jeff@puppetlabs.com> - 2.5.1
+ * (maint) Fix spec failures resulting from Facter API changes (97f836f)
+
+2012-10-23 - Matthaus Owens <matthaus@puppetlabs.com> - 2.5.0
+ * Add PE facts to stdlib (cdf3b05)
+
+2012-08-15 - Dan Bode <dan@puppetlabs.com> - 2.5.0
+ * Explicitly load functions used by ensure_resource (9fc3063)
+
+2012-08-13 - Dan Bode <dan@puppetlabs.com> - 2.5.0
+ * Add better docs about duplicate resource failures (97d327a)
+
+2012-08-13 - Dan Bode <dan@puppetlabs.com> - 2.5.0
+ * Handle undef for parameter argument (4f8b133)
+
+2012-08-07 - Dan Bode <dan@puppetlabs.com> - 2.5.0
+ * Add function ensure_resource and defined_with_params (a0cb8cd)
+
+2012-08-20 - Jeff McCune <jeff@puppetlabs.com> - 2.5.0
+ * Disable tests that fail on 2.6.x due to #15912 (c81496e)
+
+2012-08-20 - Jeff McCune <jeff@puppetlabs.com> - 2.5.0
+ * (Maint) Fix mis-use of rvalue functions as statements (4492913)
+
+2012-08-20 - Jeff McCune <jeff@puppetlabs.com> - 2.5.0
+ * Add .rspec file to repo root (88789e8)
+
+2012-06-07 - Chris Price <chris@puppetlabs.com> - 2.4.0
+ * Add support for a 'match' parameter to file_line (a06c0d8)
+
+2012-08-07 - Erik Dalén <dalen@spotify.com> - 2.4.0
+ * (#15872) Add to_bytes function (247b69c)
+
+2012-07-19 - Jeff McCune <jeff@puppetlabs.com> - 2.4.0
+ * (Maint) use PuppetlabsSpec::PuppetInternals.scope (master) (deafe88)
+
+2012-07-10 - Hailee Kenney <hailee@puppetlabs.com> - 2.4.0
+ * (#2157) Make facts_dot_d compatible with external facts (5fb0ddc)
+
+2012-03-16 - Steve Traylen <steve.traylen@cern.ch> - 2.4.0
+ * (#13205) Rotate array/string randomley based on fqdn, fqdn_rotate() (fef247b)
+
+2012-05-22 - Peter Meier <peter.meier@immerda.ch> - 2.3.3
+ * fix regression in #11017 properly (f0a62c7)
+
+2012-05-10 - Jeff McCune <jeff@puppetlabs.com> - 2.3.3
+ * Fix spec tests using the new spec_helper (7d34333)
+
+2012-05-10 - Puppet Labs <support@puppetlabs.com> - 2.3.2
+ * Make file_line default to ensure => present (1373e70)
+ * Memoize file_line spec instance variables (20aacc5)
+ * Fix spec tests using the new spec_helper (1ebfa5d)
+ * (#13595) initialize_everything_for_tests couples modules Puppet ver (3222f35)
+ * (#13439) Fix MRI 1.9 issue with spec_helper (15c5fd1)
+ * (#13439) Fix test failures with Puppet 2.6.x (665610b)
+ * (#13439) refactor spec helper for compatibility with both puppet 2.7 and master (82194ca)
+ * (#13494) Specify the behavior of zero padded strings (61891bb)
+
+2012-03-29 Puppet Labs <support@puppetlabs.com> - 2.1.3
+* (#11607) Add Rakefile to enable spec testing
+* (#12377) Avoid infinite loop when retrying require json
+
+2012-03-13 Puppet Labs <support@puppetlabs.com> - 2.3.1
+* (#13091) Fix LoadError bug with puppet apply and puppet_vardir fact
+
+2012-03-12 Puppet Labs <support@puppetlabs.com> - 2.3.0
+* Add a large number of new Puppet functions
+* Backwards compatibility preserved with 2.2.x
+
+2011-12-30 Puppet Labs <support@puppetlabs.com> - 2.2.1
+* Documentation only release for the Forge
+
+2011-12-30 Puppet Labs <support@puppetlabs.com> - 2.1.2
+* Documentation only release for PE 2.0.x
+
+2011-11-08 Puppet Labs <support@puppetlabs.com> - 2.2.0
+* #10285 - Refactor json to use pson instead.
+* Maint - Add watchr autotest script
+* Maint - Make rspec tests work with Puppet 2.6.4
+* #9859 - Add root_home fact and tests
+
+2011-08-18 Puppet Labs <support@puppetlabs.com> - 2.1.1
+* Change facts.d paths to match Facter 2.0 paths.
+* /etc/facter/facts.d
+* /etc/puppetlabs/facter/facts.d
+
+2011-08-17 Puppet Labs <support@puppetlabs.com> - 2.1.0
+* Add R.I. Pienaar's facts.d custom facter fact
+* facts defined in /etc/facts.d and /etc/puppetlabs/facts.d are
+ automatically loaded now.
+
+2011-08-04 Puppet Labs <support@puppetlabs.com> - 2.0.0
+* Rename whole_line to file_line
+* This is an API change and as such motivating a 2.0.0 release according to semver.org.
+
+2011-08-04 Puppet Labs <support@puppetlabs.com> - 1.1.0
+* Rename append_line to whole_line
+* This is an API change and as such motivating a 1.1.0 release.
+
+2011-08-04 Puppet Labs <support@puppetlabs.com> - 1.0.0
+* Initial stable release
+* Add validate_array and validate_string functions
+* Make merge() function work with Ruby 1.8.5
+* Add hash merging function
+* Add has_key function
+* Add loadyaml() function
+* Add append_line native
+
+2011-06-21 Jeff McCune <jeff@puppetlabs.com> - 0.1.7
+* Add validate_hash() and getvar() functions
+
+2011-06-15 Jeff McCune <jeff@puppetlabs.com> - 0.1.6
+* Add anchor resource type to provide containment for composite classes
+
+2011-06-03 Jeff McCune <jeff@puppetlabs.com> - 0.1.5
+* Add validate_bool() function to stdlib
+
+0.1.4 2011-05-26 Jeff McCune <jeff@puppetlabs.com>
+* Move most stages after main
+
+0.1.3 2011-05-25 Jeff McCune <jeff@puppetlabs.com>
+* Add validate_re() function
+
+0.1.2 2011-05-24 Jeff McCune <jeff@puppetlabs.com>
+* Update to add annotated tag
+
+0.1.1 2011-05-24 Jeff McCune <jeff@puppetlabs.com>
+* Add stdlib::stages class with a standard set of stages
diff --git a/puppet/modules/stdlib/CONTRIBUTING.md b/puppet/modules/stdlib/CONTRIBUTING.md
new file mode 100644
index 0000000..bd11f63
--- /dev/null
+++ b/puppet/modules/stdlib/CONTRIBUTING.md
@@ -0,0 +1,65 @@
+# 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 [Redmine account](http://projects.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 Redmine 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 (Redmine)](http://projects.puppetlabs.com)
+* [Contributor License Agreement](http://links.puppetlabs.com/cla)
+* [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/puppet/modules/stdlib/Gemfile b/puppet/modules/stdlib/Gemfile
new file mode 100644
index 0000000..197cc6b
--- /dev/null
+++ b/puppet/modules/stdlib/Gemfile
@@ -0,0 +1,42 @@
+source "https://rubygems.org"
+
+def location_for(place, fake_version = nil)
+ mdata = /^(git:[^#]*)#(.*)/.match(place)
+ if mdata
+ [fake_version, { :git => mdata[1], :branch => mdata[2], :require => false }].compact
+ elsif place =~ /^file:\/\/(.*)/
+ ['>= 0', { :path => File.expand_path(mdata[1]), :require => false }]
+ else
+ [place, { :require => false }]
+ end
+end
+
+group :development do
+ gem 'watchr'
+end
+
+group :development, :test do
+ gem 'rake'
+ gem 'puppetmodule-stdlib', ">= 1.0.0", :path => File.expand_path("..", __FILE__)
+ gem 'rspec', "~> 2.11.0", :require => false
+ gem 'mocha', "~> 0.10.5", :require => false
+ gem 'puppetlabs_spec_helper', :require => false
+ gem 'rspec-puppet', :require => false
+end
+
+facterversion = ENV['GEM_FACTER_VERSION']
+if facterversion
+ gem 'facter', *location_for(facterversion)
+else
+ gem 'facter', :require => false
+end
+
+ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION']
+puppetversion = ENV['GEM_PUPPET_VERSION']
+if puppetversion
+ gem 'puppet', *location_for(puppetversion)
+else
+ gem 'puppet', :require => false
+end
+
+# vim:ft=ruby
diff --git a/puppet/modules/stdlib/LICENSE b/puppet/modules/stdlib/LICENSE
new file mode 100644
index 0000000..ec0587c
--- /dev/null
+++ b/puppet/modules/stdlib/LICENSE
@@ -0,0 +1,19 @@
+Copyright (C) 2011 Puppet Labs Inc
+
+and some parts:
+
+Copyright (C) 2011 Krzysztof Wilczynski
+
+Puppet Labs can be contacted at: info@puppetlabs.com
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/puppet/modules/stdlib/Modulefile b/puppet/modules/stdlib/Modulefile
new file mode 100644
index 0000000..9d2e8c2
--- /dev/null
+++ b/puppet/modules/stdlib/Modulefile
@@ -0,0 +1,11 @@
+name 'puppetlabs-stdlib'
+version '4.1.0'
+source 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
+author 'puppetlabs'
+license 'Apache 2.0'
+summary 'Puppet Module Standard Library'
+description 'Standard Library for Puppet Modules'
+project_page 'https://github.com/puppetlabs/puppetlabs-stdlib'
+
+## Add dependencies, if any:
+# dependency 'username/name', '>= 1.2.0'
diff --git a/puppet/modules/stdlib/README.markdown b/puppet/modules/stdlib/README.markdown
new file mode 100644
index 0000000..7b45b17
--- /dev/null
+++ b/puppet/modules/stdlib/README.markdown
@@ -0,0 +1,1194 @@
+# Puppet Labs Standard Library #
+
+[![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
+
+ * Stages
+ * Facts
+ * Functions
+ * Defined resource types
+ * Types
+ * Providers
+
+This module is officially curated and provided by Puppet Labs. The modules
+Puppet Labs writes and distributes will make heavy use of this standard
+library.
+
+To report or research a bug with any part of this module, please go to
+[http://projects.puppetlabs.com/projects/stdlib](http://projects.puppetlabs.com/projects/stdlib)
+
+# 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 (Never released as part of PE, only to the Forge)
+ * v4.0.x (Drops support for Puppet 2.7)
+ * 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 | no | **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 drops support for Puppet 2.7. Stdlib 4.x
+supports Puppet 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
+
+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
+
+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.
+
+
+- *Type*: rvalue
+
+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
+
+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
+
+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.
+
+
+- *Type*: rvalue
+
+concat
+------
+Appends the contents of array 2 onto array 1.
+
+*Example:*
+
+ concat(['1','2','3'],['4','5','6'])
+
+Would result in:
+
+ ['1','2','3','4','5','6']
+
+
+- *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
+
+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, 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
+
+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.
+
+
+- *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
+
+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
+
+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.
+
+
+- *Type*: rvalue
+
+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
+
+has_key
+-------
+Determine if a hash has a certain key value.
+
+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
+
+hash
+----
+This function converts an array into a hash.
+
+*Examples:*
+
+ hash(['a',1,'b',2,'c',3])
+
+Would return: {'a'=>1,'b'=>2,'c'=>3}
+
+
+- *Type*: rvalue
+
+is_array
+--------
+Returns true if the variable passed to this function is an array.
+
+- *Type*: rvalue
+
+is_domain_name
+--------------
+Returns true if the string passed to this function is a syntactically correct domain name.
+
+- *Type*: rvalue
+
+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, determines whether the
+Puppet runtime has access to a function by that name. It returns a
+true if the function exists, false if not.
+
+- *Type*: rvalue
+
+is_hash
+-------
+Returns true if the variable passed to this function is a hash.
+
+- *Type*: rvalue
+
+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
+
+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 seperator.
+
+*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
+
+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"]
+
+- *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 attempt 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 - 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
+
+unique
+------
+This function will remove duplicates from strings and arrays.
+
+*Examples:*
+
+ unique("aabbcc")
+
+Will return:
+
+ abc
+
+You can also use this with arrays:
+
+ unique(["a","a","b","b","c","c"])
+
+This returns:
+
+ ["a","b","c"]
+
+
+- *Type*: rvalue
+
+upcase
+------
+Converts a string or an array of strings to uppercase.
+
+*Examples:*
+
+ upcase("abcd")
+
+Will return:
+
+ ASDF
+
+
+- *Type*: rvalue
+
+uriescape
+---------
+Urlencodes a string or array of strings.
+Requires either a single string or an array as an input.
+
+
+- *Type*: rvalue
+
+validate_absolute_path
+----------------------
+Validate the string represents an absolute path in the filesystem. This function works
+for windows and unix style paths.
+
+The following values will pass:
+
+ $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:
+
+ 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
+---------------
+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.
+
+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.
+
+For example, if you want to make sure your passwd content never contains
+a user `foo`, you could write:
+
+ validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo'])
+
+Or if you wanted to ensure that no users used the '/bin/barsh' shell,
+you could use:
+
+ validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]']
+
+If a fourth argument is specified, this will be the error message raised and
+seen by the user.
+
+A helpful error message can be returned like this:
+
+ validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas')
+
+
+
+- *Type*: statement
+
+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:
+
+ $iamtrue = true
+ validate_bool(true)
+ validate_bool(true, true, false, $iamtrue)
+
+The following values will fail, causing compilation to abort:
+
+ $some_array = [ true ]
+ validate_bool("false")
+ validate_bool("true")
+ validate_bool($some_array)
+
+
+
+- *Type*: statement
+
+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.
+
+A helpful error message can be returned like this:
+
+Example:
+
+ validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
+
+
+
+- *Type*: statement
+
+validate_hash
+-------------
+Validate that all passed values are hash data structures. Abort catalog
+compilation if any value fails this check.
+
+The following values will pass:
+
+ $my_hash = { 'one' => 'two' }
+ validate_hash($my_hash)
+
+The following values will fail, causing compilation to abort:
+
+ 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
+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.
+
+The following strings will validate against the regular expressions:
+
+ validate_re('one', '^one$')
+ validate_re('one', [ '^one', '^two' ])
+
+The following strings will fail to validate, causing compilation to abort:
+
+ validate_re('one', [ '^two', '^three' ])
+
+A helpful error message can be returned like this:
+
+ validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
+
+
+
+- *Type*: statement
+
+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. It fails if the first
+argument is not a string or array of strings, and if arg 2 is not convertable
+to a number.
+
+The following values will pass:
+
+ validate_slength("discombobulate",17)
+ validate_slength(["discombobulate","moo"],17)
+
+The following valueis will not:
+
+ validate_slength("discombobulate",1)
+ validate_slength(["discombobulate","thermometer"],5)
+
+
+
+- *Type*: statement
+
+validate_string
+---------------
+Validate that all passed values are string data structures. Abort catalog
+compilation if any value fails this check.
+
+The following values will pass:
+
+ $my_string = "one two"
+ validate_string($my_string, 'three')
+
+The following values will fail, causing compilation to abort:
+
+ validate_string(true)
+ validate_string([ 'some', 'array' ])
+ $undefined = undef
+ validate_string($undefined)
+
+
+- *Type*: statement
+
+values
+------
+When given a hash this function will return the values of that hash.
+
+*Examples:*
+
+ $hash = {
+ 'a' => 1,
+ 'b' => 2,
+ 'c' => 3,
+ }
+ values($hash)
+
+This example would return:
+
+ [1,2,3]
+
+
+- *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'].
+
+ values_at(['a','b','c','d','e'], [0, "2-3"])
+
+Would return ['a','c','d'].
+
+
+- *Type*: rvalue
+
+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.
+
+*Example:*
+
+ zip(['1','2','3'],['4','5','6'])
+
+Would result in:
+
+ ["1", "4"], ["2", "5"], ["3", "6"]
+
+
+- *Type*: rvalue
+
+*This page autogenerated on 2013-04-11 13:54:25 -0700*
diff --git a/puppet/modules/stdlib/README_DEVELOPER.markdown b/puppet/modules/stdlib/README_DEVELOPER.markdown
new file mode 100644
index 0000000..04349ed
--- /dev/null
+++ b/puppet/modules/stdlib/README_DEVELOPER.markdown
@@ -0,0 +1,35 @@
+Puppet Specific Facts
+=====================
+
+Facter is meant to stand alone and apart from Puppet. However, Facter often
+runs inside Puppet and all custom facts included in the stdlib module will
+almost always be evaluated in the context of Puppet and Facter working
+together.
+
+Still, we don't want to write custom facts that blow up in the users face if
+Puppet is not loaded in memory. This is often the case if the user runs
+`facter` without also supplying the `--puppet` flag.
+
+Ah! But Jeff, the custom fact won't be in the `$LOAD_PATH` unless the user
+supplies `--facter`! You might say...
+
+Not (always) true I say! If the user happens to have a CWD of
+`<modulepath>/stdlib/lib` then the facts will automatically be evaluated and
+blow up.
+
+In any event, it's pretty easy to write a fact that has no value if Puppet is
+not loaded. Simply do it like this:
+
+ Facter.add(:node_vardir) do
+ setcode do
+ # This will be nil if Puppet is not available.
+ Facter::Util::PuppetSettings.with_puppet do
+ Puppet[:vardir]
+ end
+ end
+ end
+
+The `Facter::Util::PuppetSettings.with_puppet` method accepts a block and
+yields to it only if the Puppet library is loaded. If the Puppet library is
+not loaded, then the method silently returns `nil` which Facter interprets as
+an undefined fact value. The net effect is that the fact won't be set.
diff --git a/puppet/modules/stdlib/README_SPECS.markdown b/puppet/modules/stdlib/README_SPECS.markdown
new file mode 100644
index 0000000..917b631
--- /dev/null
+++ b/puppet/modules/stdlib/README_SPECS.markdown
@@ -0,0 +1,7 @@
+NOTE
+====
+
+This project's specs depend on puppet core, and thus they require the
+`puppetlabs_spec_helper` project. For more information please see the README
+in that project, which can be found here: [puppetlabs spec
+helper](https://github.com/puppetlabs/puppetlabs_spec_helper)
diff --git a/puppet/modules/stdlib/RELEASE_PROCESS.markdown b/puppet/modules/stdlib/RELEASE_PROCESS.markdown
new file mode 100644
index 0000000..0f9328e
--- /dev/null
+++ b/puppet/modules/stdlib/RELEASE_PROCESS.markdown
@@ -0,0 +1,24 @@
+# Contributing to this module #
+
+ * Work in a topic branch
+ * Submit a github pull request
+ * Address any comments / feeback
+ * Merge into master using --no-ff
+
+# Releasing this module #
+
+ * This module adheres to http://semver.org/
+ * Look for API breaking changes using git diff vX.Y.Z..master
+ * If no API breaking changes, the minor version may be bumped.
+ * If there are API breaking changes, the major version must be bumped.
+ * If there are only small minor changes, the patch version may be bumped.
+ * Update the CHANGELOG
+ * Update the Modulefile
+ * Commit these changes with a message along the lines of "Update CHANGELOG and
+ Modulefile for release"
+ * Create an annotated tag with git tag -a vX.Y.Z -m 'version X.Y.Z' (NOTE the
+ leading v as per semver.org)
+ * Push the tag with git push origin --tags
+ * Build a new package with puppet-module or the rake build task if it exists
+ * Publish the new package to the forge
+ * Bonus points for an announcement to puppet-users.
diff --git a/puppet/modules/stdlib/Rakefile b/puppet/modules/stdlib/Rakefile
new file mode 100644
index 0000000..14f1c24
--- /dev/null
+++ b/puppet/modules/stdlib/Rakefile
@@ -0,0 +1,2 @@
+require 'rubygems'
+require 'puppetlabs_spec_helper/rake_tasks'
diff --git a/puppet/modules/stdlib/lib/facter/facter_dot_d.rb b/puppet/modules/stdlib/lib/facter/facter_dot_d.rb
new file mode 100644
index 0000000..e414b20
--- /dev/null
+++ b/puppet/modules/stdlib/lib/facter/facter_dot_d.rb
@@ -0,0 +1,202 @@
+# A Facter plugin that loads facts from /etc/facter/facts.d
+# and /etc/puppetlabs/facter/facts.d.
+#
+# Facts can be in the form of JSON, YAML or Text files
+# and any executable that returns key=value pairs.
+#
+# In the case of scripts you can also create a file that
+# contains a cache TTL. For foo.sh store the ttl as just
+# a number in foo.sh.ttl
+#
+# The cache is stored in /tmp/facts_cache.yaml as a mode
+# 600 file and will have the end result of not calling your
+# fact scripts more often than is needed
+
+class Facter::Util::DotD
+ require 'yaml'
+
+ def initialize(dir="/etc/facts.d", cache_file="/tmp/facts_cache.yml")
+ @dir = dir
+ @cache_file = cache_file
+ @cache = nil
+ @types = {".txt" => :txt, ".json" => :json, ".yaml" => :yaml}
+ end
+
+ def entries
+ Dir.entries(@dir).reject{|f| f =~ /^\.|\.ttl$/}.sort.map {|f| File.join(@dir, f) }
+ rescue
+ []
+ end
+
+ def fact_type(file)
+ extension = File.extname(file)
+
+ type = @types[extension] || :unknown
+
+ type = :script if type == :unknown && File.executable?(file)
+
+ return type
+ end
+
+ def txt_parser(file)
+ File.readlines(file).each do |line|
+ if line =~ /^(.+)=(.+)$/
+ var = $1; val = $2
+
+ Facter.add(var) do
+ setcode { val }
+ end
+ end
+ end
+ rescue Exception => e
+ Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
+ end
+
+ def json_parser(file)
+ begin
+ require 'json'
+ rescue LoadError
+ retry if require 'rubygems'
+ raise
+ end
+
+ JSON.load(File.read(file)).each_pair do |f, v|
+ Facter.add(f) do
+ setcode { v }
+ end
+ end
+ rescue Exception => e
+ Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}")
+ end
+
+ def yaml_parser(file)
+ require 'yaml'
+
+ YAML.load_file(file).each_pair do |f, v|
+ Facter.add(f) do
+ setcode { v }
+ end
+ end
+ rescue Exception => e
+ Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}")
+ end
+
+ def script_parser(file)
+ result = cache_lookup(file)
+ ttl = cache_time(file)
+
+ unless result
+ result = Facter::Util::Resolution.exec(file)
+
+ if ttl > 0
+ Facter.debug("Updating cache for #{file}")
+ cache_store(file, result)
+ cache_save!
+ end
+ else
+ Facter.debug("Using cached data for #{file}")
+ end
+
+ result.split("\n").each do |line|
+ if line =~ /^(.+)=(.+)$/
+ var = $1; val = $2
+
+ Facter.add(var) do
+ setcode { val }
+ end
+ end
+ end
+ rescue Exception => e
+ Facter.warn("Failed to handle #{file} as script facts: #{e.class}: #{e}")
+ Facter.debug(e.backtrace.join("\n\t"))
+ end
+
+ def cache_save!
+ cache = load_cache
+ File.open(@cache_file, "w", 0600) {|f| f.write(YAML.dump(cache)) }
+ rescue
+ end
+
+ def cache_store(file, data)
+ load_cache
+
+ @cache[file] = {:data => data, :stored => Time.now.to_i}
+ rescue
+ end
+
+ def cache_lookup(file)
+ cache = load_cache
+
+ return nil if cache.empty?
+
+ ttl = cache_time(file)
+
+ if cache[file]
+ now = Time.now.to_i
+
+ return cache[file][:data] if ttl == -1
+ return cache[file][:data] if (now - cache[file][:stored]) <= ttl
+ return nil
+ else
+ return nil
+ end
+ rescue
+ return nil
+ end
+
+ def cache_time(file)
+ meta = file + ".ttl"
+
+ return File.read(meta).chomp.to_i
+ rescue
+ return 0
+ end
+
+ def load_cache
+ unless @cache
+ if File.exist?(@cache_file)
+ @cache = YAML.load_file(@cache_file)
+ else
+ @cache = {}
+ end
+ end
+
+ return @cache
+ rescue
+ @cache = {}
+ return @cache
+ end
+
+ def create
+ entries.each do |fact|
+ type = fact_type(fact)
+ parser = "#{type}_parser"
+
+ if respond_to?("#{type}_parser")
+ Facter.debug("Parsing #{fact} using #{parser}")
+
+ send(parser, fact)
+ end
+ end
+ end
+end
+
+
+mdata = Facter.version.match(/(\d+)\.(\d+)\.(\d+)/)
+if mdata
+ (major, minor, patch) = mdata.captures.map { |v| v.to_i }
+ if major < 2
+ # Facter 1.7 introduced external facts support directly
+ unless major == 1 and minor > 6
+ Facter::Util::DotD.new("/etc/facter/facts.d").create
+ Facter::Util::DotD.new("/etc/puppetlabs/facter/facts.d").create
+
+ # Windows has a different configuration directory that defaults to a vendor
+ # specific sub directory of the %COMMON_APPDATA% directory.
+ if Dir.const_defined? 'COMMON_APPDATA' then
+ windows_facts_dot_d = File.join(Dir::COMMON_APPDATA, 'PuppetLabs', 'facter', 'facts.d')
+ Facter::Util::DotD.new(windows_facts_dot_d).create
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/facter/pe_version.rb b/puppet/modules/stdlib/lib/facter/pe_version.rb
new file mode 100644
index 0000000..0cc0f64
--- /dev/null
+++ b/puppet/modules/stdlib/lib/facter/pe_version.rb
@@ -0,0 +1,53 @@
+# Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version
+#
+# Purpose: Return various facts about the PE state of the system
+#
+# Resolution: Uses a regex match against puppetversion to determine whether the
+# machine has Puppet Enterprise installed, and what version (overall, major,
+# minor, patch) is installed.
+#
+# Caveats:
+#
+Facter.add("pe_version") do
+ setcode do
+ pe_ver = Facter.value("puppetversion").match(/Puppet Enterprise (\d+\.\d+\.\d+)/)
+ pe_ver[1] if pe_ver
+ end
+end
+
+Facter.add("is_pe") do
+ setcode do
+ if Facter.value(:pe_version).to_s.empty? then
+ false
+ else
+ true
+ end
+ end
+end
+
+Facter.add("pe_major_version") do
+ confine :is_pe => true
+ setcode do
+ if pe_version = Facter.value(:pe_version)
+ pe_version.to_s.split('.')[0]
+ end
+ end
+end
+
+Facter.add("pe_minor_version") do
+ confine :is_pe => true
+ setcode do
+ if pe_version = Facter.value(:pe_version)
+ pe_version.to_s.split('.')[1]
+ end
+ end
+end
+
+Facter.add("pe_patch_version") do
+ confine :is_pe => true
+ setcode do
+ if pe_version = Facter.value(:pe_version)
+ pe_version.to_s.split('.')[2]
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/facter/puppet_vardir.rb b/puppet/modules/stdlib/lib/facter/puppet_vardir.rb
new file mode 100644
index 0000000..0e6af40
--- /dev/null
+++ b/puppet/modules/stdlib/lib/facter/puppet_vardir.rb
@@ -0,0 +1,26 @@
+# This facter fact returns the value of the Puppet vardir setting for the node
+# running puppet or puppet agent. The intent is to enable Puppet modules to
+# automatically have insight into a place where they can place variable data,
+# regardless of the node's platform.
+#
+# The value should be directly usable in a File resource path attribute.
+
+
+begin
+ require 'facter/util/puppet_settings'
+rescue LoadError => e
+ # puppet apply does not add module lib directories to the $LOAD_PATH (See
+ # #4248). It should (in the future) but for the time being we need to be
+ # defensive which is what this rescue block is doing.
+ rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
+ load rb_file if File.exists?(rb_file) or raise e
+end
+
+Facter.add(:puppet_vardir) do
+ setcode do
+ # This will be nil if Puppet is not available.
+ Facter::Util::PuppetSettings.with_puppet do
+ Puppet[:vardir]
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/facter/root_home.rb b/puppet/modules/stdlib/lib/facter/root_home.rb
new file mode 100644
index 0000000..8249f7d
--- /dev/null
+++ b/puppet/modules/stdlib/lib/facter/root_home.rb
@@ -0,0 +1,19 @@
+# A facter fact to determine the root home directory.
+# This varies on PE supported platforms and may be
+# reconfigured by the end user.
+
+module Facter::Util::RootHome
+ class << self
+ def get_root_home
+ root_ent = Facter::Util::Resolution.exec("getent passwd root")
+ # The home directory is the sixth element in the passwd entry
+ # If the platform doesn't have getent, root_ent will be nil and we should
+ # return it straight away.
+ root_ent && root_ent.split(":")[5]
+ end
+ end
+end
+
+Facter.add(:root_home) do
+ setcode { Facter::Util::RootHome.get_root_home }
+end
diff --git a/puppet/modules/stdlib/lib/facter/util/puppet_settings.rb b/puppet/modules/stdlib/lib/facter/util/puppet_settings.rb
new file mode 100644
index 0000000..1ad9452
--- /dev/null
+++ b/puppet/modules/stdlib/lib/facter/util/puppet_settings.rb
@@ -0,0 +1,21 @@
+module Facter
+ module Util
+ module PuppetSettings
+ # This method is intended to provide a convenient way to evaluate a
+ # Facter code block only if Puppet is loaded. This is to account for the
+ # situation where the fact happens to be in the load path, but Puppet is
+ # not loaded for whatever reason. Perhaps the user is simply running
+ # facter without the --puppet flag and they happen to be working in a lib
+ # directory of a module.
+ def self.with_puppet
+ begin
+ Module.const_get("Puppet")
+ rescue NameError
+ nil
+ else
+ yield
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/abs.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/abs.rb
new file mode 100644
index 0000000..11d2d7f
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/abs.rb
@@ -0,0 +1,36 @@
+#
+# abs.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:abs, :type => :rvalue, :doc => <<-EOS
+ Returns the absolute value of a number, for example -34.56 becomes
+ 34.56. Takes a single integer and float value as an argument.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "abs(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ if value.is_a?(String)
+ if value.match(/^-?(?:\d+)(?:\.\d+){1}$/)
+ value = value.to_f
+ elsif value.match(/^-?\d+$/)
+ value = value.to_i
+ else
+ raise(Puppet::ParseError, 'abs(): Requires float or ' +
+ 'integer to work with')
+ end
+ end
+
+ # We have numeric value to handle ...
+ result = value.abs
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/any2array.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/any2array.rb
new file mode 100644
index 0000000..e71407e
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/any2array.rb
@@ -0,0 +1,33 @@
+#
+# any2array.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:any2array, :type => :rvalue, :doc => <<-EOS
+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.
+ EOS
+ ) do |arguments|
+
+ if arguments.empty?
+ return []
+ end
+
+ if arguments.length == 1
+ if arguments[0].kind_of?(Array)
+ return arguments[0]
+ elsif arguments[0].kind_of?(Hash)
+ result = []
+ arguments[0].each do |key, value|
+ result << key << value
+ end
+ return result
+ end
+ end
+
+ return arguments
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/bool2num.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/bool2num.rb
new file mode 100644
index 0000000..9a07a8a
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/bool2num.rb
@@ -0,0 +1,49 @@
+#
+# bool2num.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS
+ 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.
+ EOS
+ ) do |arguments|
+
+ 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
+
+ # We have real boolean values as well ...
+ result = value ? 1 : 0
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/capitalize.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/capitalize.rb
new file mode 100644
index 0000000..640d00b
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/capitalize.rb
@@ -0,0 +1,34 @@
+#
+# capitalize.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS
+ Capitalizes the first letter of a string or array of strings.
+ Requires either a single string or an array as an input.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'capitalize(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.capitalize : i }
+ else
+ result = value.capitalize
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/chomp.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/chomp.rb
new file mode 100644
index 0000000..4564a00
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/chomp.rb
@@ -0,0 +1,35 @@
+#
+# chomp.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS'
+ 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.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "chomp(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'chomp(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.chomp : i }
+ else
+ result = value.chomp
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/chop.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/chop.rb
new file mode 100644
index 0000000..f242af3
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/chop.rb
@@ -0,0 +1,37 @@
+#
+# chop.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:chop, :type => :rvalue, :doc => <<-'EOS'
+ 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.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "chop(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'chop(): Requires either an ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.chop : i }
+ else
+ result = value.chop
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/concat.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/concat.rb
new file mode 100644
index 0000000..c86aa00
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/concat.rb
@@ -0,0 +1,37 @@
+#
+# concat.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:concat, :type => :rvalue, :doc => <<-EOS
+Appends the contents of array 2 onto array 1.
+
+*Example:*
+
+ concat(['1','2','3'],['4','5','6'])
+
+Would result in:
+
+ ['1','2','3','4','5','6']
+ EOS
+ ) do |arguments|
+
+ # Check that 2 arguments have been given ...
+ raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") if arguments.size != 2
+
+ a = arguments[0]
+ b = arguments[1]
+
+ # Check that both args are arrays.
+ unless a.is_a?(Array) and b.is_a?(Array)
+ raise(Puppet::ParseError, 'concat(): Requires array to work with')
+ end
+
+ result = a.concat(b)
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/count.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/count.rb
new file mode 100644
index 0000000..52de1b8
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/count.rb
@@ -0,0 +1,22 @@
+module Puppet::Parser::Functions
+ newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-EOS
+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.
+ EOS
+ ) do |args|
+
+ if (args.size > 2) then
+ raise(ArgumentError, "count(): Wrong number of arguments "+
+ "given #{args.size} for 1 or 2.")
+ end
+
+ collection, item = args
+
+ if item then
+ collection.count item
+ else
+ collection.count { |obj| obj != nil && obj != :undef && obj != '' }
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb
new file mode 100644
index 0000000..d7df306
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb
@@ -0,0 +1,35 @@
+# Test whether a given class or definition is defined
+require 'puppet/parser/functions'
+
+Puppet::Parser::Functions.newfunction(:defined_with_params,
+ :type => :rvalue,
+ :doc => <<-'ENDOFDOC'
+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, and false otherwise.
+
+ user { 'dan':
+ ensure => present,
+ }
+
+ if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
+ user { 'dan': ensure => present, }
+ }
+ENDOFDOC
+) do |vals|
+ reference, params = vals
+ raise(ArgumentError, 'Must specify a reference') unless reference
+ if (! params) || params == ''
+ params = {}
+ end
+ ret = false
+ if resource = findresource(reference.to_s)
+ matches = params.collect do |key, value|
+ resource[key] == value
+ end
+ ret = params.empty? || !matches.include?(false)
+ end
+ Puppet.debug("Resource #{reference} was not determined to be defined")
+ ret
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/delete.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/delete.rb
new file mode 100644
index 0000000..f814344
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/delete.rb
@@ -0,0 +1,46 @@
+#
+# delete.rb
+#
+
+# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
+
+module Puppet::Parser::Functions
+ newfunction(:delete, :type => :rvalue, :doc => <<-EOS
+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'
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 2) then
+ raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
+ "given #{arguments.size} for 2.")
+ end
+
+ collection = arguments[0]
+ item = arguments[1]
+
+ case collection
+ when Array, Hash
+ collection.delete item
+ when String
+ collection.gsub! item, ''
+ else
+ raise(TypeError, "delete(): First argument must be an Array, " +
+ "String, or Hash. Given an argument of class #{collection.class}.")
+ end
+ collection
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/delete_at.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/delete_at.rb
new file mode 100644
index 0000000..3eb4b53
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/delete_at.rb
@@ -0,0 +1,49 @@
+#
+# delete_at.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
+Deletes a determined indexed value from an array.
+
+*Examples:*
+
+ delete_at(['a','b','c'], 1)
+
+Would return: ['a','c']
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") if arguments.size < 2
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'delete_at(): Requires array to work with')
+ end
+
+ index = arguments[1]
+
+ if index.is_a?(String) and not index.match(/^\d+$/)
+ raise(Puppet::ParseError, 'delete_at(): You must provide ' +
+ 'non-negative numeric index')
+ end
+
+ result = array.clone
+
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ index = index.to_i
+
+ if index > result.size - 1 # First element is at index 0 is it not?
+ raise(Puppet::ParseError, 'delete_at(): Given index ' +
+ 'exceeds size of array given')
+ end
+
+ result.delete_at(index) # We ignore the element that got deleted ...
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/dirname.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/dirname.rb
new file mode 100644
index 0000000..ea8cc1e
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/dirname.rb
@@ -0,0 +1,15 @@
+module Puppet::Parser::Functions
+ newfunction(:dirname, :type => :rvalue, :doc => <<-EOS
+ Returns the dirname of a path.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "dirname(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ path = arguments[0]
+ return File.dirname(path)
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/downcase.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/downcase.rb
new file mode 100644
index 0000000..4066d21
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/downcase.rb
@@ -0,0 +1,33 @@
+#
+# downcase.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:downcase, :type => :rvalue, :doc => <<-EOS
+Converts the case of a string or all strings in an array to lower case.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "downcase(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'downcase(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.downcase : i }
+ else
+ result = value.downcase
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/empty.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/empty.rb
new file mode 100644
index 0000000..80ebb86
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/empty.rb
@@ -0,0 +1,28 @@
+#
+# empty.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:empty, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable is empty.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "empty(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, Hash, String].include?(klass)
+ raise(Puppet::ParseError, 'empty(): Requires either ' +
+ 'array, hash or string to work with')
+ end
+
+ result = value.empty?
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb
new file mode 100644
index 0000000..450ea02
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb
@@ -0,0 +1,24 @@
+#
+# ensure_packages.rb
+#
+require 'puppet/parser/functions'
+
+module Puppet::Parser::Functions
+ newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS
+Takes a list of packages and only installs them if they don't already exist.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+ raise(Puppet::ParseError, "ensure_packages(): Requires array " +
+ "given (#{arguments[0].class})") if !arguments[0].kind_of?(Array)
+
+ Puppet::Parser::Functions.function(:ensure_resource)
+ arguments[0].each { |package_name|
+ function_ensure_resource(['package', package_name, {'ensure' => 'present' } ])
+ }
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb
new file mode 100644
index 0000000..a9a1733
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb
@@ -0,0 +1,45 @@
+# Test whether a given class or definition is defined
+require 'puppet/parser/functions'
+
+Puppet::Parser::Functions.newfunction(:ensure_resource,
+ :type => :statement,
+ :doc => <<-'ENDOFDOC'
+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'})
+
+ENDOFDOC
+) do |vals|
+ type, title, params = vals
+ raise(ArgumentError, 'Must specify a type') unless type
+ raise(ArgumentError, 'Must specify a title') unless title
+ params ||= {}
+
+ items = [title].flatten
+
+ items.each do |item|
+ Puppet::Parser::Functions.function(:defined_with_params)
+ if function_defined_with_params(["#{type}[#{item}]", params])
+ Puppet.debug("Resource #{type}[#{item}] not created because it already exists")
+ else
+ Puppet::Parser::Functions.function(:create_resources)
+ function_create_resources([type.capitalize, { item => params }])
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/flatten.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/flatten.rb
new file mode 100644
index 0000000..a1ed183
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/flatten.rb
@@ -0,0 +1,33 @@
+#
+# flatten.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:flatten, :type => :rvalue, :doc => <<-EOS
+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']
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "flatten(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'flatten(): Requires array to work with')
+ end
+
+ result = array.flatten
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/floor.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/floor.rb
new file mode 100644
index 0000000..a401923
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/floor.rb
@@ -0,0 +1,20 @@
+module Puppet::Parser::Functions
+ newfunction(:floor, :type => :rvalue, :doc => <<-EOS
+ Returns the largest integer less or equal to the argument.
+ Takes a single numeric value as an argument.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "floor(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ arg = arguments[0]
+
+ raise(Puppet::ParseError, "floor(): Wrong argument type " +
+ "given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
+
+ arg.floor
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb
new file mode 100644
index 0000000..6558206
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb
@@ -0,0 +1,46 @@
+#
+# fqdn_rotate.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:fqdn_rotate, :type => :rvalue, :doc => <<-EOS
+Rotates an array a random number of times based on a nodes fqdn.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+ require 'digest/md5'
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ result = value.clone
+
+ string = value.is_a?(String) ? true : false
+
+ # Check whether it makes sense to rotate ...
+ return result if result.size <= 1
+
+ # We turn any string value into an array to be able to rotate ...
+ result = string ? result.split('') : result
+
+ elements = result.size
+
+ srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),arguments].join(':')).hex)
+ rand(elements).times {
+ result.push result.shift
+ }
+
+ result = string ? result.join : result
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb
new file mode 100644
index 0000000..1421b91
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb
@@ -0,0 +1,17 @@
+module Puppet::Parser::Functions
+ newfunction(:get_module_path, :type =>:rvalue, :doc => <<-EOT
+ Returns the absolute path of the specified module for the current
+ environment.
+
+ Example:
+ $module_path = get_module_path('stdlib')
+ EOT
+ ) do |args|
+ raise(Puppet::ParseError, "get_module_path(): Wrong number of arguments, expects one") unless args.size == 1
+ if module_path = Puppet::Module.find(args[0], compiler.environment.to_s)
+ module_path.path
+ else
+ raise(Puppet::ParseError, "Could not find module #{args[0]} in environment #{compiler.environment}")
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/getparam.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/getparam.rb
new file mode 100644
index 0000000..6d51006
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/getparam.rb
@@ -0,0 +1,35 @@
+# Test whether a given class or definition is defined
+require 'puppet/parser/functions'
+
+Puppet::Parser::Functions.newfunction(:getparam,
+ :type => :rvalue,
+ :doc => <<-'ENDOFDOC'
+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
+ENDOFDOC
+) do |vals|
+ reference, param = vals
+ raise(ArgumentError, 'Must specify a reference') unless reference
+ raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String
+
+ return '' if param.empty?
+
+ if resource = findresource(reference.to_s)
+ return resource[param] if resource[param]
+ end
+
+ return ''
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/getvar.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/getvar.rb
new file mode 100644
index 0000000..1621149
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/getvar.rb
@@ -0,0 +1,26 @@
+module Puppet::Parser::Functions
+
+ newfunction(:getvar, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ 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
+ ENDHEREDOC
+
+ unless args.length == 1
+ raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)")
+ end
+
+ self.lookupvar("#{args[0]}")
+
+ end
+
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/grep.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/grep.rb
new file mode 100644
index 0000000..ceba9ec
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/grep.rb
@@ -0,0 +1,33 @@
+#
+# grep.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:grep, :type => :rvalue, :doc => <<-EOS
+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']
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 2) then
+ raise(Puppet::ParseError, "grep(): Wrong number of arguments "+
+ "given #{arguments.size} for 2")
+ end
+
+ a = arguments[0]
+ pattern = Regexp.new(arguments[1])
+
+ a.grep(pattern)
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb
new file mode 100644
index 0000000..7f150a7
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb
@@ -0,0 +1,52 @@
+#
+# has_interface_with
+#
+
+module Puppet::Parser::Functions
+ newfunction(:has_interface_with, :type => :rvalue, :doc => <<-EOS
+Returns boolean based on kind and value:
+ * macaddress
+ * netmask
+ * ipaddress
+ * network
+
+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
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments " +
+ "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2
+
+ interfaces = lookupvar('interfaces')
+
+ # If we do not have any interfaces, then there are no requested attributes
+ return false if (interfaces == :undefined)
+
+ interfaces = interfaces.split(',')
+
+ if args.size == 1
+ return interfaces.member?(args[0])
+ end
+
+ kind, value = args
+
+ if lookupvar(kind) == value
+ return true
+ end
+
+ result = false
+ interfaces.each do |iface|
+ if value == lookupvar("#{kind}_#{iface}")
+ result = true
+ break
+ end
+ end
+
+ result
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb
new file mode 100644
index 0000000..842c8ec
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb
@@ -0,0 +1,25 @@
+#
+# has_ip_address
+#
+
+module Puppet::Parser::Functions
+ newfunction(:has_ip_address, :type => :rvalue, :doc => <<-EOS
+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.
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments " +
+ "given (#{args.size} for 1)") if args.size != 1
+
+ Puppet::Parser::Functions.autoloader.load(:has_interface_with) \
+ unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with)
+
+ function_has_interface_with(['ipaddress', args[0]])
+
+ end
+end
+
+# vim:sts=2 sw=2
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb
new file mode 100644
index 0000000..9ccf902
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb
@@ -0,0 +1,25 @@
+#
+# has_ip_network
+#
+
+module Puppet::Parser::Functions
+ newfunction(:has_ip_network, :type => :rvalue, :doc => <<-EOS
+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.
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments " +
+ "given (#{args.size} for 1)") if args.size != 1
+
+ Puppet::Parser::Functions.autoloader.load(:has_interface_with) \
+ unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with)
+
+ function_has_interface_with(['network', args[0]])
+
+ end
+end
+
+# vim:sts=2 sw=2
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/has_key.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/has_key.rb
new file mode 100644
index 0000000..4657cc2
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/has_key.rb
@@ -0,0 +1,28 @@
+module Puppet::Parser::Functions
+
+ newfunction(:has_key, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ Determine if a hash has a certain key value.
+
+ 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')
+ }
+
+ ENDHEREDOC
+
+ unless args.length == 2
+ raise Puppet::ParseError, ("has_key(): wrong number of arguments (#{args.length}; must be 2)")
+ end
+ unless args[0].is_a?(Hash)
+ raise Puppet::ParseError, "has_key(): expects the first argument to be a hash, got #{args[0].inspect} which is of type #{args[0].class}"
+ end
+ args[0].has_key?(args[1])
+
+ end
+
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/hash.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/hash.rb
new file mode 100644
index 0000000..8cc4823
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/hash.rb
@@ -0,0 +1,41 @@
+#
+# hash.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:hash, :type => :rvalue, :doc => <<-EOS
+This function converts an array into a hash.
+
+*Examples:*
+
+ hash(['a',1,'b',2,'c',3])
+
+Would return: {'a'=>1,'b'=>2,'c'=>3}
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "hash(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'hash(): Requires array to work with')
+ end
+
+ result = {}
+
+ begin
+ # This is to make it compatible with older version of Ruby ...
+ array = array.flatten
+ result = Hash[*array]
+ rescue Exception
+ raise(Puppet::ParseError, 'hash(): Unable to compute ' +
+ 'hash from array given')
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_array.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_array.rb
new file mode 100644
index 0000000..b39e184
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_array.rb
@@ -0,0 +1,22 @@
+#
+# is_array.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_array, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable passed to this function is an array.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "is_array(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ type = arguments[0]
+
+ result = type.is_a?(Array)
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb
new file mode 100644
index 0000000..5826dc0
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb
@@ -0,0 +1,47 @@
+#
+# is_domain_name.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_domain_name, :type => :rvalue, :doc => <<-EOS
+Returns true if the string passed to this function is a syntactically correct domain name.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ domain = arguments[0]
+
+ # Limits (rfc1035, 3.1)
+ domain_max_length=255
+ label_min_length=1
+ label_max_length=63
+
+ # Allow ".", it is the top level domain
+ return true if domain == '.'
+
+ # Remove the final dot, if present.
+ domain.chomp!('.')
+
+ # Check the whole domain
+ return false if domain.empty?
+ return false if domain.length > domain_max_length
+
+ # Check each label in the domain
+ labels = domain.split('.')
+ vlabels = labels.each do |label|
+ break if label.length < label_min_length
+ break if label.length > label_max_length
+ break if label[-1..-1] == '-'
+ break if label[0..0] == '-'
+ break unless /^[a-z\d-]+$/i.match(label)
+ end
+ return vlabels == labels
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_float.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_float.rb
new file mode 100644
index 0000000..911f3c2
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_float.rb
@@ -0,0 +1,27 @@
+#
+# is_float.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_float, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable passed to this function is a float.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ value = arguments[0]
+
+ if value != value.to_f.to_s and !value.is_a? Float then
+ return false
+ else
+ return true
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_function_available.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_function_available.rb
new file mode 100644
index 0000000..6cbd35c
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_function_available.rb
@@ -0,0 +1,23 @@
+#
+# is_function_available.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_function_available, :type => :rvalue, :doc => <<-EOS
+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.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ function = Puppet::Parser::Functions.function(arguments[0].to_sym)
+ function.is_a?(String) and not function.empty?
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_hash.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_hash.rb
new file mode 100644
index 0000000..ad907f0
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_hash.rb
@@ -0,0 +1,22 @@
+#
+# is_hash.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_hash, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable passed to this function is a hash.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "is_hash(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ type = arguments[0]
+
+ result = type.is_a?(Hash)
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_integer.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_integer.rb
new file mode 100644
index 0000000..6b29e98
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_integer.rb
@@ -0,0 +1,27 @@
+#
+# is_integer.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable returned to this string is an integer.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ value = arguments[0]
+
+ if value != value.to_i.to_s and !value.is_a? Fixnum then
+ return false
+ else
+ return true
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb
new file mode 100644
index 0000000..a90adab
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb
@@ -0,0 +1,32 @@
+#
+# is_ip_address.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_ip_address, :type => :rvalue, :doc => <<-EOS
+Returns true if the string passed to this function is a valid IP address.
+ EOS
+ ) do |arguments|
+
+ require 'ipaddr'
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ begin
+ ip = IPAddr.new(arguments[0])
+ rescue ArgumentError
+ return false
+ end
+
+ if ip.ipv4? or ip.ipv6? then
+ return true
+ else
+ return false
+ end
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb
new file mode 100644
index 0000000..1b3088a
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb
@@ -0,0 +1,27 @@
+#
+# is_mac_address.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_mac_address, :type => :rvalue, :doc => <<-EOS
+Returns true if the string passed to this function is a valid mac address.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ mac = arguments[0]
+
+ if /^[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}$/.match(mac) then
+ return true
+ else
+ return false
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb
new file mode 100644
index 0000000..abf0321
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb
@@ -0,0 +1,27 @@
+#
+# is_numeric.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable passed to this function is a number.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ value = arguments[0]
+
+ if value == value.to_f.to_s or value == value.to_i.to_s or value.is_a? Numeric then
+ return true
+ else
+ return false
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/is_string.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/is_string.rb
new file mode 100644
index 0000000..f5bef04
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/is_string.rb
@@ -0,0 +1,26 @@
+#
+# is_string.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:is_string, :type => :rvalue, :doc => <<-EOS
+Returns true if the variable passed to this function is a string.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "is_string(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ type = arguments[0]
+
+ result = type.is_a?(String)
+
+ if result and (type == type.to_f.to_s or type == type.to_i.to_s) then
+ return false
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/join.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/join.rb
new file mode 100644
index 0000000..005a46e
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/join.rb
@@ -0,0 +1,41 @@
+#
+# join.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:join, :type => :rvalue, :doc => <<-EOS
+This function joins an array into a string using a seperator.
+
+*Examples:*
+
+ join(['a','b','c'], ",")
+
+Would result in: "a,b,c"
+ EOS
+ ) do |arguments|
+
+ # Technically we support two arguments but only first is mandatory ...
+ raise(Puppet::ParseError, "join(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'join(): Requires array to work with')
+ end
+
+ suffix = arguments[1] if arguments[1]
+
+ if suffix
+ unless suffix.is_a?(String)
+ raise(Puppet::ParseError, 'join(): Requires string to work with')
+ end
+ end
+
+ result = suffix ? array.join(suffix) : array.join
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb
new file mode 100644
index 0000000..e9924fe
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb
@@ -0,0 +1,47 @@
+#
+# join.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:join_keys_to_values, :type => :rvalue, :doc => <<-EOS
+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"]
+ EOS
+ ) do |arguments|
+
+ # Validate the number of arguments.
+ if arguments.size != 2
+ raise(Puppet::ParseError, "join_keys_to_values(): Takes exactly two " +
+ "arguments, but #{arguments.size} given.")
+ end
+
+ # Validate the first argument.
+ hash = arguments[0]
+ if not hash.is_a?(Hash)
+ raise(TypeError, "join_keys_to_values(): The first argument must be a " +
+ "hash, but a #{hash.class} was given.")
+ end
+
+ # Validate the second argument.
+ separator = arguments[1]
+ if not separator.is_a?(String)
+ raise(TypeError, "join_keys_to_values(): The second argument must be a " +
+ "string, but a #{separator.class} was given.")
+ end
+
+ # Join the keys to their values.
+ hash.map do |k,v|
+ String(k) + separator + String(v)
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/keys.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/keys.rb
new file mode 100644
index 0000000..f0d13b6
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/keys.rb
@@ -0,0 +1,26 @@
+#
+# keys.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:keys, :type => :rvalue, :doc => <<-EOS
+Returns the keys of a hash as an array.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "keys(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ hash = arguments[0]
+
+ unless hash.is_a?(Hash)
+ raise(Puppet::ParseError, 'keys(): Requires hash to work with')
+ end
+
+ result = hash.keys
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb
new file mode 100644
index 0000000..10c4005
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb
@@ -0,0 +1,20 @@
+module Puppet::Parser::Functions
+
+ newfunction(:loadyaml, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ 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')
+ ENDHEREDOC
+
+ unless args.length == 1
+ raise Puppet::ParseError, ("loadyaml(): wrong number of arguments (#{args.length}; must be 1)")
+ end
+
+ YAML.load_file(args[0])
+
+ end
+
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/lstrip.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/lstrip.rb
new file mode 100644
index 0000000..3a64de3
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/lstrip.rb
@@ -0,0 +1,33 @@
+#
+# lstrip.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS
+Strips leading spaces to the left of a string.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "lstrip(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'lstrip(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.lstrip : i }
+ else
+ result = value.lstrip
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/max.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/max.rb
new file mode 100644
index 0000000..60fb94a
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/max.rb
@@ -0,0 +1,21 @@
+module Puppet::Parser::Functions
+ newfunction(:max, :type => :rvalue, :doc => <<-EOS
+ Returns the highest value of all arguments.
+ Requires at least one argument.
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "max(): Wrong number of arguments " +
+ "need at least one") if args.size == 0
+
+ # Sometimes we get numbers as numerics and sometimes as strings.
+ # We try to compare them as numbers when possible
+ return args.max do |a,b|
+ if a.to_s =~ /\A-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then
+ a.to_f <=> b.to_f
+ else
+ a.to_s <=> b.to_s
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/member.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/member.rb
new file mode 100644
index 0000000..43d76af
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/member.rb
@@ -0,0 +1,44 @@
+#
+# member.rb
+#
+
+# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
+# TODO(Krzysztof Wilczynski): Support for strings and hashes too ...
+
+module Puppet::Parser::Functions
+ newfunction(:member, :type => :rvalue, :doc => <<-EOS
+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
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "member(): Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") if arguments.size < 2
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'member(): Requires array to work with')
+ end
+
+ item = arguments[1]
+
+ raise(Puppet::ParseError, 'member(): You must provide item ' +
+ 'to search for within array given') if item.empty?
+
+ result = array.include?(item)
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/merge.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/merge.rb
new file mode 100644
index 0000000..6ec085e
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/merge.rb
@@ -0,0 +1,33 @@
+module Puppet::Parser::Functions
+ newfunction(:merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
+ 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."
+
+ ENDHEREDOC
+
+ if args.length < 2
+ raise Puppet::ParseError, ("merge(): wrong number of arguments (#{args.length}; must be at least 2)")
+ end
+
+ # The hash we accumulate into
+ accumulator = Hash.new
+ # Merge into the accumulator hash
+ args.each do |arg|
+ unless arg.is_a?(Hash)
+ raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments"
+ end
+ accumulator.merge!(arg)
+ end
+ # Return the fully merged hash
+ accumulator
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/min.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/min.rb
new file mode 100644
index 0000000..6bd6ebf
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/min.rb
@@ -0,0 +1,21 @@
+module Puppet::Parser::Functions
+ newfunction(:min, :type => :rvalue, :doc => <<-EOS
+ Returns the lowest value of all arguments.
+ Requires at least one argument.
+ EOS
+ ) do |args|
+
+ raise(Puppet::ParseError, "min(): Wrong number of arguments " +
+ "need at least one") if args.size == 0
+
+ # Sometimes we get numbers as numerics and sometimes as strings.
+ # We try to compare them as numbers when possible
+ return args.min do |a,b|
+ if a.to_s =~ /\A^-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then
+ a.to_f <=> b.to_f
+ else
+ a.to_s <=> b.to_s
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/num2bool.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/num2bool.rb
new file mode 100644
index 0000000..af0e6ed
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/num2bool.rb
@@ -0,0 +1,43 @@
+#
+# num2bool.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:num2bool, :type => :rvalue, :doc => <<-EOS
+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.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "num2bool(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ number = arguments[0]
+
+ case number
+ when Numeric
+ # Yay, it's a number
+ when String
+ begin
+ number = Float(number)
+ rescue ArgumentError => ex
+ raise(Puppet::ParseError, "num2bool(): '#{number}' does not look like a number: #{ex.message}")
+ end
+ else
+ begin
+ number = number.to_s
+ rescue NoMethodError => ex
+ raise(Puppet::ParseError, "num2bool(): Unable to parse argument: #{ex.message}")
+ end
+ end
+
+ # Truncate Floats
+ number = number.to_i
+
+ # Return true for any positive number and false otherwise
+ return number > 0
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/parsejson.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/parsejson.rb
new file mode 100644
index 0000000..a9a16a4
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/parsejson.rb
@@ -0,0 +1,24 @@
+#
+# parsejson.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:parsejson, :type => :rvalue, :doc => <<-EOS
+This function accepts JSON as a string and converts into the correct Puppet
+structure.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "parsejson(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ json = arguments[0]
+
+ # PSON is natively available in puppet
+ PSON.load(json)
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb
new file mode 100644
index 0000000..53d54fa
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb
@@ -0,0 +1,24 @@
+#
+# parseyaml.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:parseyaml, :type => :rvalue, :doc => <<-EOS
+This function accepts YAML as a string and converts it into the correct
+Puppet structure.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "parseyaml(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ require 'yaml'
+
+ YAML::load(arguments[0])
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/pick.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/pick.rb
new file mode 100644
index 0000000..cbc0300
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/pick.rb
@@ -0,0 +1,29 @@
+module Puppet::Parser::Functions
+ newfunction(:pick, :type => :rvalue, :doc => <<-EOS
+
+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.
+
+EOS
+) do |args|
+ args = args.compact
+ args.delete(:undef)
+ args.delete(:undefined)
+ args.delete("")
+ if args[0].to_s.empty? then
+ fail "Must provide non empty value."
+ else
+ return args[0]
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/prefix.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/prefix.rb
new file mode 100644
index 0000000..62211ae
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/prefix.rb
@@ -0,0 +1,45 @@
+#
+# prefix.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:prefix, :type => :rvalue, :doc => <<-EOS
+This function applies a prefix to all elements in an array.
+
+*Examples:*
+
+ prefix(['a','b','c'], 'p')
+
+Will return: ['pa','pb','pc']
+ EOS
+ ) do |arguments|
+
+ # Technically we support two arguments but only first is mandatory ...
+ raise(Puppet::ParseError, "prefix(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise Puppet::ParseError, "prefix(): expected first argument to be an Array, got #{array.inspect}"
+ end
+
+ prefix = arguments[1] if arguments[1]
+
+ if prefix
+ unless prefix.is_a?(String)
+ raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{suffix.inspect}"
+ end
+ end
+
+ # Turn everything into string same as join would do ...
+ result = array.collect do |i|
+ i = i.to_s
+ prefix ? prefix + i : i
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/range.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/range.rb
new file mode 100644
index 0000000..825617b
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/range.rb
@@ -0,0 +1,80 @@
+#
+# range.rb
+#
+
+# TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ...
+
+module Puppet::Parser::Functions
+ newfunction(:range, :type => :rvalue, :doc => <<-EOS
+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"]
+ EOS
+ ) do |arguments|
+
+ # We support more than one argument but at least one is mandatory ...
+ raise(Puppet::ParseError, "range(): Wrong number of " +
+ "arguments given (#{arguments.size} for 1)") if arguments.size < 1
+
+ if arguments.size > 1
+ start = arguments[0]
+ stop = arguments[1]
+
+ type = '..' # We select simplest type for Range available in Ruby ...
+
+ elsif arguments.size > 0
+ value = arguments[0]
+
+ if m = value.match(/^(\w+)(\.\.\.?|\-)(\w+)$/)
+ start = m[1]
+ stop = m[3]
+
+ type = m[2]
+
+ elsif value.match(/^.+$/)
+ raise(Puppet::ParseError, 'range(): Unable to compute range ' +
+ 'from the value given')
+ else
+ raise(Puppet::ParseError, 'range(): Unknown format of range given')
+ end
+ end
+
+ # Check whether we have integer value if so then make it so ...
+ if start.match(/^\d+$/)
+ start = start.to_i
+ stop = stop.to_i
+ else
+ start = start.to_s
+ stop = stop.to_s
+ end
+
+ range = case type
+ when /^(\.\.|\-)$/ then (start .. stop)
+ when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ...
+ end
+
+ result = range.collect { |i| i } # Get them all ... Pokemon ...
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/reject.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/reject.rb
new file mode 100644
index 0000000..1953ffc
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/reject.rb
@@ -0,0 +1,31 @@
+#
+# reject.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:reject, :type => :rvalue, :doc => <<-EOS) do |args|
+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']
+EOS
+
+ if (args.size != 2)
+ raise Puppet::ParseError,
+ "reject(): Wrong number of arguments given #{args.size} for 2"
+ end
+
+ ary = args[0]
+ pattern = Regexp.new(args[1])
+
+ ary.reject { |e| e =~ pattern }
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/reverse.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/reverse.rb
new file mode 100644
index 0000000..fe04869
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/reverse.rb
@@ -0,0 +1,28 @@
+#
+# reverse.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:reverse, :type => :rvalue, :doc => <<-EOS
+Reverses the order of a string or array.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "reverse(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'reverse(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ result = value.reverse
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/rstrip.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/rstrip.rb
new file mode 100644
index 0000000..29b0998
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/rstrip.rb
@@ -0,0 +1,32 @@
+#
+# rstrip.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS
+Strips leading spaces to the right of the string.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "rstrip(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'rstrip(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ result = value.collect { |i| i.is_a?(String) ? i.rstrip : i }
+ else
+ result = value.rstrip
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/shuffle.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/shuffle.rb
new file mode 100644
index 0000000..18134ab
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/shuffle.rb
@@ -0,0 +1,46 @@
+#
+# shuffle.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:shuffle, :type => :rvalue, :doc => <<-EOS
+Randomizes the order of a string or array elements.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "shuffle(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'shuffle(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ result = value.clone
+
+ string = value.is_a?(String) ? true : false
+
+ # Check whether it makes sense to shuffle ...
+ return result if result.size <= 1
+
+ # We turn any string value into an array to be able to shuffle ...
+ result = string ? result.split('') : result
+
+ elements = result.size
+
+ # Simple implementation of Fisher–Yates in-place shuffle ...
+ elements.times do |i|
+ j = rand(elements - i) + i
+ result[j], result[i] = result[i], result[j]
+ end
+
+ result = string ? result.join : result
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/size.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/size.rb
new file mode 100644
index 0000000..cc207e3
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/size.rb
@@ -0,0 +1,48 @@
+#
+# size.rb
+#
+
+# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ...
+
+module Puppet::Parser::Functions
+ newfunction(:size, :type => :rvalue, :doc => <<-EOS
+Returns the number of elements in a string or array.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "size(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ item = arguments[0]
+
+ if item.is_a?(String)
+
+ begin
+ #
+ # Check whether your item is a numeric value or not ...
+ # This will take care about positive and/or negative numbers
+ # for both integer and floating-point values ...
+ #
+ # Please note that Puppet has no notion of hexadecimal
+ # nor octal numbers for its DSL at this point in time ...
+ #
+ Float(item)
+
+ raise(Puppet::ParseError, 'size(): Requires either ' +
+ 'string or array to work with')
+
+ rescue ArgumentError
+ result = item.size
+ end
+
+ elsif item.is_a?(Array)
+ result = item.size
+ else
+ raise(Puppet::ParseError, 'size(): Unknown type given')
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/sort.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/sort.rb
new file mode 100644
index 0000000..cefbe54
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/sort.rb
@@ -0,0 +1,27 @@
+#
+# sort.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:sort, :type => :rvalue, :doc => <<-EOS
+Sorts strings and arrays lexically.
+ EOS
+ ) do |arguments|
+
+ if (arguments.size != 1) then
+ raise(Puppet::ParseError, "sort(): Wrong number of arguments "+
+ "given #{arguments.size} for 1")
+ end
+
+ value = arguments[0]
+
+ if value.is_a?(Array) then
+ value.sort
+ elsif value.is_a?(String) then
+ value.split("").sort.join("")
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/squeeze.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/squeeze.rb
new file mode 100644
index 0000000..81fadfd
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/squeeze.rb
@@ -0,0 +1,36 @@
+#
+# squeeze.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS
+Returns a new string where runs of the same character that occur in this set are replaced by a single character.
+ EOS
+ ) do |arguments|
+
+ if ((arguments.size != 2) and (arguments.size != 1)) then
+ raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+
+ "given #{arguments.size} for 2 or 1")
+ end
+
+ item = arguments[0]
+ squeezeval = arguments[1]
+
+ if item.is_a?(Array) then
+ if squeezeval then
+ item.collect { |i| i.squeeze(squeezeval) }
+ else
+ item.collect { |i| i.squeeze }
+ end
+ else
+ if squeezeval then
+ item.squeeze(squeezeval)
+ else
+ item.squeeze
+ end
+ end
+
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/str2bool.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/str2bool.rb
new file mode 100644
index 0000000..fece7a6
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/str2bool.rb
@@ -0,0 +1,46 @@
+#
+# str2bool.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS
+This converts a string to a boolean. This attempt 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'.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "str2bool(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ string = arguments[0]
+
+ # If string is already Boolean, return it
+ if !!string == string
+ return string
+ end
+
+ unless string.is_a?(String)
+ raise(Puppet::ParseError, 'str2bool(): Requires either ' +
+ 'string to work with')
+ end
+
+ # We consider all the yes, no, y, n and so on too ...
+ result = case string
+ #
+ # 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, 'str2bool(): Unknown type of boolean given')
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb
new file mode 100644
index 0000000..7fe7b01
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb
@@ -0,0 +1,32 @@
+#
+# str2saltedsha512.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:str2saltedsha512, :type => :rvalue, :doc => <<-EOS
+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.
+ EOS
+ ) do |arguments|
+ require 'digest/sha2'
+
+ raise(Puppet::ParseError, "str2saltedsha512(): Wrong number of arguments " +
+ "passed (#{arguments.size} but we require 1)") if arguments.size != 1
+
+ password = arguments[0]
+
+ unless password.is_a?(String)
+ raise(Puppet::ParseError, 'str2saltedsha512(): Requires a ' +
+ "String argument, you passed: #{password.class}")
+ end
+
+ seedint = rand(2**31 - 1)
+ seedstring = Array(seedint).pack("L")
+ saltedpass = Digest::SHA512.digest(seedstring + password)
+ (seedstring + saltedpass).unpack('H*')[0]
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/strftime.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/strftime.rb
new file mode 100644
index 0000000..0b52ade
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/strftime.rb
@@ -0,0 +1,107 @@
+#
+# strftime.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:strftime, :type => :rvalue, :doc => <<-EOS
+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)
+ %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
+ EOS
+ ) do |arguments|
+
+ # Technically we support two arguments but only first is mandatory ...
+ raise(Puppet::ParseError, "strftime(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ format = arguments[0]
+
+ raise(Puppet::ParseError, 'strftime(): You must provide ' +
+ 'format for evaluation') if format.empty?
+
+ # The Time Zone argument is optional ...
+ time_zone = arguments[1] if arguments[1]
+
+ time = Time.new
+
+ # There is probably a better way to handle Time Zone ...
+ if time_zone and not time_zone.empty?
+ original_zone = ENV['TZ']
+
+ local_time = time.clone
+ local_time = local_time.utc
+
+ ENV['TZ'] = time_zone
+
+ time = local_time.localtime
+
+ ENV['TZ'] = original_zone
+ end
+
+ result = time.strftime(format)
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/strip.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/strip.rb
new file mode 100644
index 0000000..5f4630d
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/strip.rb
@@ -0,0 +1,39 @@
+#
+# strip.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:strip, :type => :rvalue, :doc => <<-EOS
+This function removes leading and trailing whitespace from a string or from
+every string inside an array.
+
+*Examples:*
+
+ strip(" aaa ")
+
+Would result in: "aaa"
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "strip(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'strip(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ result = value.collect { |i| i.is_a?(String) ? i.strip : i }
+ else
+ result = value.strip
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/suffix.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/suffix.rb
new file mode 100644
index 0000000..f7792d6
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/suffix.rb
@@ -0,0 +1,45 @@
+#
+# suffix.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:suffix, :type => :rvalue, :doc => <<-EOS
+This function applies a suffix to all elements in an array.
+
+*Examples:*
+
+ suffix(['a','b','c'], 'p')
+
+Will return: ['ap','bp','cp']
+ EOS
+ ) do |arguments|
+
+ # Technically we support two arguments but only first is mandatory ...
+ raise(Puppet::ParseError, "suffix(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ array = arguments[0]
+
+ unless array.is_a?(Array)
+ raise Puppet::ParseError, "suffix(): expected first argument to be an Array, got #{array.inspect}"
+ end
+
+ suffix = arguments[1] if arguments[1]
+
+ if suffix
+ unless suffix.is_a? String
+ raise Puppet::ParseError, "suffix(): expected second argument to be a String, got #{suffix.inspect}"
+ end
+ end
+
+ # Turn everything into string same as join would do ...
+ result = array.collect do |i|
+ i = i.to_s
+ suffix ? i + suffix : i
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/swapcase.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/swapcase.rb
new file mode 100644
index 0000000..b9e6632
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/swapcase.rb
@@ -0,0 +1,39 @@
+#
+# swapcase.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS
+This function will swap the existing case of a string.
+
+*Examples:*
+
+ swapcase("aBcD")
+
+Would result in: "AbCd"
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "swapcase(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'swapcase(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.swapcase : i }
+ else
+ result = value.swapcase
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/time.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/time.rb
new file mode 100644
index 0000000..0cddaf8
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/time.rb
@@ -0,0 +1,49 @@
+#
+# time.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:time, :type => :rvalue, :doc => <<-EOS
+This function will return the current time since epoch as an integer.
+
+*Examples:*
+
+ time()
+
+Will return something like: 1311972653
+ EOS
+ ) do |arguments|
+
+ # The Time Zone argument is optional ...
+ time_zone = arguments[0] if arguments[0]
+
+ if (arguments.size != 0) and (arguments.size != 1) then
+ raise(Puppet::ParseError, "time(): Wrong number of arguments "+
+ "given #{arguments.size} for 0 or 1")
+ end
+
+ time = Time.new
+
+ # There is probably a better way to handle Time Zone ...
+ if time_zone and not time_zone.empty?
+ original_zone = ENV['TZ']
+
+ local_time = time.clone
+ local_time = local_time.utc
+
+ ENV['TZ'] = time_zone
+
+ time = local_time.localtime
+
+ ENV['TZ'] = original_zone
+ end
+
+ # Calling Time#to_i on a receiver changes it. Trust me I am the Doctor.
+ result = time.strftime('%s')
+ result = result.to_i
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb
new file mode 100644
index 0000000..8ff73d1
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb
@@ -0,0 +1,28 @@
+module Puppet::Parser::Functions
+ newfunction(:to_bytes, :type => :rvalue, :doc => <<-EOS
+ Converts the argument into bytes, for example 4 kB becomes 4096.
+ Takes a single string value as an argument.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "to_bytes(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size != 1
+
+ arg = arguments[0]
+
+ return arg if arg.is_a? Numeric
+
+ value,prefix = */([0-9.e+-]*)\s*([^bB]?)/.match(arg)[1,2]
+
+ value = value.to_f
+ case prefix
+ when '' then return value.to_i
+ when 'k' then return (value*(1<<10)).to_i
+ when 'M' then return (value*(1<<20)).to_i
+ when 'G' then return (value*(1<<30)).to_i
+ when 'T' then return (value*(1<<40)).to_i
+ when 'E' then return (value*(1<<50)).to_i
+ else raise Puppet::ParseError, "to_bytes(): Unknown prefix #{prefix}"
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/type.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/type.rb
new file mode 100644
index 0000000..8d85f11
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/type.rb
@@ -0,0 +1,50 @@
+#
+# type.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:type, :type => :rvalue, :doc => <<-EOS
+Returns the type when passed a variable. Type can be one of:
+
+* string
+* array
+* hash
+* float
+* integer
+* boolean
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "type(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+
+ klass = value.class
+
+ if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass)
+ raise(Puppet::ParseError, 'type(): Unknown type')
+ end
+
+ klass = klass.to_s # Ugly ...
+
+ # We note that Integer is the parent to Bignum and Fixnum ...
+ result = case klass
+ when /^(?:Big|Fix)num$/ then 'integer'
+ when /^(?:True|False)Class$/ then 'boolean'
+ else klass
+ end
+
+ if result == "String" then
+ if value == value.to_i.to_s then
+ result = "Integer"
+ elsif value == value.to_f.to_s then
+ result = "Float"
+ end
+ end
+
+ return result.downcase
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/unique.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/unique.rb
new file mode 100644
index 0000000..8844a74
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/unique.rb
@@ -0,0 +1,51 @@
+#
+# unique.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:unique, :type => :rvalue, :doc => <<-EOS
+This function will remove duplicates from strings and arrays.
+
+*Examples:*
+
+ unique("aabbcc")
+
+Will return:
+
+ abc
+
+You can also use this with arrays:
+
+ unique(["a","a","b","b","c","c"])
+
+This returns:
+
+ ["a","b","c"]
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "unique(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'unique(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ result = value.clone
+
+ string = value.is_a?(String) ? true : false
+
+ # We turn any string value into an array to be able to shuffle ...
+ result = string ? result.split('') : result
+ result = result.uniq # Remove duplicates ...
+ result = string ? result.join : result
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/upcase.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/upcase.rb
new file mode 100644
index 0000000..fe6cadc
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/upcase.rb
@@ -0,0 +1,41 @@
+#
+# upcase.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:upcase, :type => :rvalue, :doc => <<-EOS
+Converts a string or an array of strings to uppercase.
+
+*Examples:*
+
+ upcase("abcd")
+
+Will return:
+
+ ASDF
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "upcase(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'upcase(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? i.upcase : i }
+ else
+ result = value.upcase
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/uriescape.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/uriescape.rb
new file mode 100644
index 0000000..67b93a6
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/uriescape.rb
@@ -0,0 +1,36 @@
+#
+# uriescape.rb
+#
+require 'uri'
+
+module Puppet::Parser::Functions
+ newfunction(:uriescape, :type => :rvalue, :doc => <<-EOS
+ Urlencodes a string or array of strings.
+ Requires either a single string or an array as an input.
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "uriescape(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ value = arguments[0]
+ klass = value.class
+ unsafe = ":/?#[]@!$&'()*+,;= "
+
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'uriescape(): Requires either ' +
+ 'array or string to work with')
+ end
+
+ if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded which is troublesome ...
+ result = value.collect { |i| i.is_a?(String) ? URI.escape(i,unsafe) : i }
+ else
+ result = URI.escape(value,unsafe)
+ end
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb
new file mode 100644
index 0000000..fe27974
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb
@@ -0,0 +1,56 @@
+module Puppet::Parser::Functions
+ newfunction(:validate_absolute_path, :doc => <<-'ENDHEREDOC') do |args|
+ Validate the string represents an absolute path in the filesystem. This function works
+ for windows and unix style paths.
+
+ The following values will pass:
+
+ $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:
+
+ 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)
+
+ ENDHEREDOC
+
+ require 'puppet/util'
+
+ unless args.length > 0 then
+ raise Puppet::ParseError, ("validate_absolute_path(): wrong number of arguments (#{args.length}; must be > 0)")
+ end
+
+ args.each do |arg|
+ # This logic was borrowed from
+ # [lib/puppet/file_serving/base.rb](https://github.com/puppetlabs/puppet/blob/master/lib/puppet/file_serving/base.rb)
+
+ # Puppet 2.7 and beyond will have Puppet::Util.absolute_path? Fall back to a back-ported implementation otherwise.
+ if Puppet::Util.respond_to?(:absolute_path?) then
+ unless Puppet::Util.absolute_path?(arg, :posix) or Puppet::Util.absolute_path?(arg, :windows)
+ raise Puppet::ParseError, ("#{arg.inspect} is not an absolute path.")
+ end
+ else
+ # This code back-ported from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path?
+ # Determine in a platform-specific way whether a path is absolute. This
+ # defaults to the local platform if none is specified.
+ # Escape once for the string literal, and once for the regex.
+ slash = '[\\\\/]'
+ name = '[^\\\\/]+'
+ regexes = {
+ :windows => %r!^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))!i,
+ :posix => %r!^/!,
+ }
+
+ rval = (!!(arg =~ regexes[:posix])) || (!!(arg =~ regexes[:windows]))
+ rval or raise Puppet::ParseError, ("#{arg.inspect} is not an absolute path.")
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_array.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_array.rb
new file mode 100644
index 0000000..34b5118
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_array.rb
@@ -0,0 +1,33 @@
+module Puppet::Parser::Functions
+
+ newfunction(:validate_array, :doc => <<-'ENDHEREDOC') do |args|
+ 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)
+
+ ENDHEREDOC
+
+ unless args.length > 0 then
+ raise Puppet::ParseError, ("validate_array(): wrong number of arguments (#{args.length}; must be > 0)")
+ end
+
+ args.each do |arg|
+ unless arg.is_a?(Array)
+ raise Puppet::ParseError, ("#{arg.inspect} is not an Array. It looks to be a #{arg.class}")
+ end
+ end
+
+ end
+
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb
new file mode 100644
index 0000000..154d660
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb
@@ -0,0 +1,81 @@
+module Puppet::Parser::Functions
+ newfunction(:validate_augeas, :doc => <<-'ENDHEREDOC') do |args|
+ 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.
+
+ 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.
+
+ For example, if you want to make sure your passwd content never contains
+ a user `foo`, you could write:
+
+ validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo'])
+
+ Or if you wanted to ensure that no users used the '/bin/barsh' shell,
+ you could use:
+
+ validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]']
+
+ If a fourth argument is specified, this will be the error message raised and
+ seen by the user.
+
+ A helpful error message can be returned like this:
+
+ validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas')
+
+ ENDHEREDOC
+ unless Puppet.features.augeas?
+ raise Puppet::ParseError, ("validate_augeas(): this function requires the augeas feature. See http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Augeas#Pre-requisites for how to activate it.")
+ end
+
+ if (args.length < 2) or (args.length > 4) then
+ raise Puppet::ParseError, ("validate_augeas(): wrong number of arguments (#{args.length}; must be 2, 3, or 4)")
+ end
+
+ msg = args[3] || "validate_augeas(): Failed to validate content against #{args[1].inspect}"
+
+ require 'augeas'
+ aug = Augeas::open(nil, nil, Augeas::NO_MODL_AUTOLOAD)
+ begin
+ content = args[0]
+
+ # Test content in a temporary file
+ tmpfile = Tempfile.new("validate_augeas")
+ begin
+ tmpfile.write(content)
+ ensure
+ tmpfile.close
+ end
+
+ # Check for syntax
+ lens = args[1]
+ aug.transform(
+ :lens => lens,
+ :name => 'Validate_augeas',
+ :incl => tmpfile.path
+ )
+ aug.load!
+
+ unless aug.match("/augeas/files#{tmpfile.path}//error").empty?
+ error = aug.get("/augeas/files#{tmpfile.path}//error/message")
+ msg += " with error: #{error}"
+ raise Puppet::ParseError, (msg)
+ end
+
+ # Launch unit tests
+ tests = args[2] || []
+ aug.defvar('file', "/files#{tmpfile.path}")
+ tests.each do |t|
+ msg += " testing path #{t}"
+ raise Puppet::ParseError, (msg) unless aug.match(t).empty?
+ end
+ ensure
+ aug.close
+ tmpfile.unlink
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb
new file mode 100644
index 0000000..62c1d88
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb
@@ -0,0 +1,34 @@
+module Puppet::Parser::Functions
+
+ newfunction(:validate_bool, :doc => <<-'ENDHEREDOC') do |args|
+ Validate that all passed values are either true or false. Abort catalog
+ compilation if any value fails this check.
+
+ 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:
+
+ $some_array = [ true ]
+ validate_bool("false")
+ validate_bool("true")
+ validate_bool($some_array)
+
+ ENDHEREDOC
+
+ unless args.length > 0 then
+ raise Puppet::ParseError, ("validate_bool(): wrong number of arguments (#{args.length}; must be > 0)")
+ end
+
+ args.each do |arg|
+ unless (arg.is_a?(TrueClass) || arg.is_a?(FalseClass))
+ raise Puppet::ParseError, ("#{arg.inspect} is not a boolean. It looks to be a #{arg.class}")
+ end
+ end
+
+ end
+
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_cmd.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_cmd.rb
new file mode 100644
index 0000000..344a80c
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_cmd.rb
@@ -0,0 +1,47 @@
+require 'puppet/util/execution'
+
+module Puppet::Parser::Functions
+ newfunction(:validate_cmd, :doc => <<-'ENDHEREDOC') do |args|
+ 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.
+
+ A helpful error message can be returned like this:
+
+ Example:
+
+ validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
+
+ ENDHEREDOC
+ if (args.length < 2) or (args.length > 3) then
+ raise Puppet::ParseError, ("validate_cmd(): wrong number of arguments (#{args.length}; must be 2 or 3)")
+ end
+
+ msg = args[2] || "validate_cmd(): failed to validate content with command #{args[1].inspect}"
+
+ content = args[0]
+ checkscript = args[1]
+
+ # Test content in a temporary file
+ tmpfile = Tempfile.new("validate_cmd")
+ begin
+ tmpfile.write(content)
+ if Puppet::Util::Execution.respond_to?('execute')
+ Puppet::Util::Execution.execute("#{checkscript} #{tmpfile.path}")
+ else
+ Puppet::Util.execute("#{checkscript} #{tmpfile.path}")
+ end
+ rescue Puppet::ExecutionFailure => detail
+ msg += "\n#{detail}"
+ raise Puppet::ParseError, msg
+ ensure
+ tmpfile.unlink
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb
new file mode 100644
index 0000000..9bdd543
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb
@@ -0,0 +1,33 @@
+module Puppet::Parser::Functions
+
+ newfunction(:validate_hash, :doc => <<-'ENDHEREDOC') do |args|
+ Validate that all passed values are hash data structures. Abort catalog
+ compilation if any value fails this check.
+
+ The following values will pass:
+
+ $my_hash = { 'one' => 'two' }
+ validate_hash($my_hash)
+
+ The following values will fail, causing compilation to abort:
+
+ validate_hash(true)
+ validate_hash('some_string')
+ $undefined = undef
+ validate_hash($undefined)
+
+ ENDHEREDOC
+
+ unless args.length > 0 then
+ raise Puppet::ParseError, ("validate_hash(): wrong number of arguments (#{args.length}; must be > 0)")
+ end
+
+ args.each do |arg|
+ unless arg.is_a?(Hash)
+ raise Puppet::ParseError, ("#{arg.inspect} is not a Hash. It looks to be a #{arg.class}")
+ end
+ end
+
+ end
+
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_re.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_re.rb
new file mode 100644
index 0000000..ca25a70
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_re.rb
@@ -0,0 +1,40 @@
+module Puppet::Parser::Functions
+ newfunction(:validate_re, :doc => <<-'ENDHEREDOC') do |args|
+ Perform simple validation of a string against one or more regular
+ expressions. The first argument of this function should be a 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.
+
+ The following strings will validate against the regular expressions:
+
+ validate_re('one', '^one$')
+ validate_re('one', [ '^one', '^two' ])
+
+ The following strings will fail to validate, causing compilation to abort:
+
+ validate_re('one', [ '^two', '^three' ])
+
+ A helpful error message can be returned like this:
+
+ validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
+
+ ENDHEREDOC
+ if (args.length < 2) or (args.length > 3) then
+ raise Puppet::ParseError, ("validate_re(): wrong number of arguments (#{args.length}; must be 2 or 3)")
+ end
+
+ msg = args[2] || "validate_re(): #{args[0].inspect} does not match #{args[1].inspect}"
+
+ # We're using a flattened array here because we can't call String#any? in
+ # Ruby 1.9 like we can in Ruby 1.8
+ raise Puppet::ParseError, (msg) unless [args[1]].flatten.any? do |re_str|
+ args[0] =~ Regexp.compile(re_str)
+ end
+
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb
new file mode 100644
index 0000000..fdcc0a2
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb
@@ -0,0 +1,52 @@
+module Puppet::Parser::Functions
+
+ newfunction(:validate_slength, :doc => <<-'ENDHEREDOC') do |args|
+ Validate that the first argument is a string (or an array of strings), and
+ less/equal to than the length of the second argument. It fails if the first
+ argument is not a string or array of strings, and if arg 2 is not convertable
+ to a number.
+
+ The following values will pass:
+
+ validate_slength("discombobulate",17)
+ validate_slength(["discombobulate","moo"],17)
+
+ The following valueis will not:
+
+ validate_slength("discombobulate",1)
+ validate_slength(["discombobulate","thermometer"],5)
+
+ ENDHEREDOC
+
+ raise Puppet::ParseError, ("validate_slength(): Wrong number of arguments (#{args.length}; must be = 2)") unless args.length == 2
+
+ unless (args[0].is_a?(String) or args[0].is_a?(Array))
+ raise Puppet::ParseError, ("validate_slength(): please pass a string, or an array of strings - what you passed didn't work for me at all - #{args[0].class}")
+ end
+
+ begin
+ max_length = args[1].to_i
+ rescue NoMethodError => e
+ raise Puppet::ParseError, ("validate_slength(): Couldn't convert whatever you passed as the length parameter to an integer - sorry: " + e.message )
+ end
+
+ raise Puppet::ParseError, ("validate_slength(): please pass a positive number as max_length") unless max_length > 0
+
+ case args[0]
+ when String
+ raise Puppet::ParseError, ("validate_slength(): #{args[0].inspect} is #{args[0].length} characters. It should have been less than or equal to #{max_length} characters") unless args[0].length <= max_length
+ when Array
+ args[0].each do |arg|
+ if arg.is_a?(String)
+ unless ( arg.is_a?(String) and arg.length <= max_length )
+ raise Puppet::ParseError, ("validate_slength(): #{arg.inspect} is #{arg.length} characters. It should have been less than or equal to #{max_length} characters")
+ end
+ else
+ raise Puppet::ParseError, ("validate_slength(): #{arg.inspect} is not a string, it's a #{arg.class}")
+ end
+ end
+ else
+ raise Puppet::ParseError, ("validate_slength(): please pass a string, or an array of strings - what you passed didn't work for me at all - #{args[0].class}")
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/validate_string.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_string.rb
new file mode 100644
index 0000000..e667794
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/validate_string.rb
@@ -0,0 +1,33 @@
+module Puppet::Parser::Functions
+
+ newfunction(:validate_string, :doc => <<-'ENDHEREDOC') do |args|
+ Validate that all passed values are string data structures. Abort catalog
+ compilation if any value fails this check.
+
+ The following values will pass:
+
+ $my_string = "one two"
+ validate_string($my_string, 'three')
+
+ The following values will fail, causing compilation to abort:
+
+ validate_string(true)
+ validate_string([ 'some', 'array' ])
+ $undefined = undef
+ validate_string($undefined)
+
+ ENDHEREDOC
+
+ unless args.length > 0 then
+ raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
+ end
+
+ args.each do |arg|
+ unless arg.is_a?(String)
+ raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}")
+ end
+ end
+
+ end
+
+end
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/values.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/values.rb
new file mode 100644
index 0000000..1606756
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/values.rb
@@ -0,0 +1,39 @@
+#
+# values.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:values, :type => :rvalue, :doc => <<-EOS
+When given a hash this function will return the values of that hash.
+
+*Examples:*
+
+ $hash = {
+ 'a' => 1,
+ 'b' => 2,
+ 'c' => 3,
+ }
+ values($hash)
+
+This example would return:
+
+ [1,2,3]
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "values(): Wrong number of arguments " +
+ "given (#{arguments.size} for 1)") if arguments.size < 1
+
+ hash = arguments[0]
+
+ unless hash.is_a?(Hash)
+ raise(Puppet::ParseError, 'values(): Requires hash to work with')
+ end
+
+ result = hash.values
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/values_at.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/values_at.rb
new file mode 100644
index 0000000..d3e69d9
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/values_at.rb
@@ -0,0 +1,98 @@
+#
+# values_at.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:values_at, :type => :rvalue, :doc => <<-EOS
+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'].
+
+ values_at(['a','b','c','d','e'], [0, "2-3"])
+
+Would return ['a','c','d'].
+ EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "values_at(): Wrong number of " +
+ "arguments given (#{arguments.size} for 2)") if arguments.size < 2
+
+ array = arguments.shift
+
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'values_at(): Requires array to work with')
+ end
+
+ indices = [arguments.shift].flatten() # Get them all ... Pokemon ...
+
+ if not indices or indices.empty?
+ raise(Puppet::ParseError, 'values_at(): You must provide ' +
+ 'at least one positive index to collect')
+ end
+
+ result = []
+ indices_list = []
+
+ indices.each do |i|
+ if m = i.match(/^(\d+)(\.\.\.?|\-)(\d+)$/)
+ start = m[1].to_i
+ stop = m[3].to_i
+
+ type = m[2]
+
+ if start > stop
+ raise(Puppet::ParseError, 'values_at(): Stop index in ' +
+ 'given indices range is smaller than the start index')
+ elsif stop > array.size - 1 # First element is at index 0 is it not?
+ raise(Puppet::ParseError, 'values_at(): Stop index in ' +
+ 'given indices range exceeds array size')
+ end
+
+ range = case type
+ when /^(\.\.|\-)$/ then (start .. stop)
+ when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ...
+ end
+
+ range.each { |i| indices_list << i.to_i }
+ else
+ # Only positive numbers allowed in this case ...
+ if not i.match(/^\d+$/)
+ raise(Puppet::ParseError, 'values_at(): Unknown format ' +
+ 'of given index')
+ end
+
+ # In Puppet numbers are often string-encoded ...
+ i = i.to_i
+
+ if i > array.size - 1 # Same story. First element is at index 0 ...
+ raise(Puppet::ParseError, 'values_at(): Given index ' +
+ 'exceeds array size')
+ end
+
+ indices_list << i
+ end
+ end
+
+ # We remove nil values as they make no sense in Puppet DSL ...
+ result = indices_list.collect { |i| array[i] }.compact
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/parser/functions/zip.rb b/puppet/modules/stdlib/lib/puppet/parser/functions/zip.rb
new file mode 100644
index 0000000..2b56e9c
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/parser/functions/zip.rb
@@ -0,0 +1,65 @@
+#
+# zip.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:zip, :type => :rvalue, :doc => <<-EOS
+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.
+
+*Example:*
+
+ zip(['1','2','3'],['4','5','6'])
+
+Would result in:
+
+ ["1", "4"], ["2", "5"], ["3", "6"]
+ EOS
+ ) do |arguments|
+
+ # Technically we support three arguments but only first is mandatory ...
+ raise(Puppet::ParseError, "zip(): Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") if arguments.size < 2
+
+ a = arguments[0]
+ b = arguments[1]
+
+ unless a.is_a?(Array) and b.is_a?(Array)
+ 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
+
+ result = a.zip(b)
+ result = flatten ? result.flatten : result
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :
diff --git a/puppet/modules/stdlib/lib/puppet/provider/file_line/ruby.rb b/puppet/modules/stdlib/lib/puppet/provider/file_line/ruby.rb
new file mode 100644
index 0000000..a3219d3
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/provider/file_line/ruby.rb
@@ -0,0 +1,59 @@
+
+Puppet::Type.type(:file_line).provide(:ruby) do
+
+ def exists?
+ lines.find do |line|
+ line.chomp == resource[:line].chomp
+ end
+ end
+
+ def create
+ if resource[:match]
+ handle_create_with_match()
+ else
+ handle_create_without_match()
+ end
+ end
+
+ def destroy
+ local_lines = lines
+ File.open(resource[:path],'w') do |fh|
+ fh.write(local_lines.reject{|l| l.chomp == resource[:line] }.join(''))
+ end
+ end
+
+ private
+ def lines
+ # If this type is ever used with very large files, we should
+ # write this in a different way, using a temp
+ # file; for now assuming that this type is only used on
+ # small-ish config files that can fit into memory without
+ # too much trouble.
+ @lines ||= File.readlines(resource[:path])
+ end
+
+ def handle_create_with_match()
+ regex = resource[:match] ? Regexp.new(resource[:match]) : nil
+ match_count = lines.select { |l| regex.match(l) }.size
+ if match_count > 1
+ raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'"
+ end
+ File.open(resource[:path], 'w') do |fh|
+ lines.each do |l|
+ fh.puts(regex.match(l) ? resource[:line] : l)
+ end
+
+ if (match_count == 0)
+ fh.puts(resource[:line])
+ end
+ end
+ end
+
+ def handle_create_without_match
+ File.open(resource[:path], 'a') do |fh|
+ fh.puts resource[:line]
+ end
+ end
+
+
+end
diff --git a/puppet/modules/stdlib/lib/puppet/type/anchor.rb b/puppet/modules/stdlib/lib/puppet/type/anchor.rb
new file mode 100644
index 0000000..fe1e5aa
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/type/anchor.rb
@@ -0,0 +1,46 @@
+Puppet::Type.newtype(:anchor) do
+ desc <<-'ENDOFDESC'
+ 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': }
+
+ ENDOFDESC
+
+ newparam :name do
+ desc "The name of the anchor resource."
+ end
+
+ def refresh
+ # We don't do anything with them, but we need this to
+ # show that we are "refresh aware" and not break the
+ # chain of propagation.
+ end
+end
diff --git a/puppet/modules/stdlib/lib/puppet/type/file_line.rb b/puppet/modules/stdlib/lib/puppet/type/file_line.rb
new file mode 100644
index 0000000..f71a4bc
--- /dev/null
+++ b/puppet/modules/stdlib/lib/puppet/type/file_line.rb
@@ -0,0 +1,70 @@
+Puppet::Type.newtype(:file_line) do
+
+ desc <<-EOT
+ 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.
+
+ Example:
+
+ 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.
+
+ EOT
+
+ ensurable do
+ defaultvalues
+ defaultto :present
+ end
+
+ newparam(:name, :namevar => true) do
+ desc 'An arbitrary name used as the identity of the resource.'
+ end
+
+ newparam(:match) do
+ desc 'An optional regular expression to run against existing lines in the file;\n' +
+ 'if a match is found, we replace that line rather than adding a new line.'
+ end
+
+ newparam(:line) do
+ desc 'The line to be appended to the file located by the path parameter.'
+ end
+
+ newparam(:path) do
+ desc 'The file Puppet will ensure contains the line specified by the line parameter.'
+ validate do |value|
+ unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/))
+ raise(Puppet::Error, "File paths must be fully qualified, not '#{value}'")
+ end
+ end
+ end
+
+ # Autorequire the file resource if it's being managed
+ autorequire(:file) do
+ self[:path]
+ end
+
+ validate do
+ unless self[:line] and self[:path]
+ raise(Puppet::Error, "Both line and path are required attributes")
+ end
+
+ if (self[:match])
+ unless Regexp.new(self[:match]).match(self[:line])
+ raise(Puppet::Error, "When providing a 'match' parameter, the value must be a regex that matches against the value of your 'line' parameter")
+ end
+ end
+
+ end
+end
diff --git a/puppet/modules/stdlib/manifests/init.pp b/puppet/modules/stdlib/manifests/init.pp
new file mode 100644
index 0000000..500ad77
--- /dev/null
+++ b/puppet/modules/stdlib/manifests/init.pp
@@ -0,0 +1,20 @@
+# Class: stdlib
+#
+# This module manages stdlib. Most of stdlib's features are automatically
+# loaded by Puppet, but this class should be declared in order to use the
+# standardized run stages.
+#
+# Parameters: none
+#
+# Actions:
+#
+# Declares all other classes in the stdlib module. Currently, this consists
+# of stdlib::stages.
+#
+# Requires: nothing
+#
+class stdlib {
+
+ class { 'stdlib::stages': }
+
+}
diff --git a/puppet/modules/stdlib/manifests/stages.pp b/puppet/modules/stdlib/manifests/stages.pp
new file mode 100644
index 0000000..eb15fd6
--- /dev/null
+++ b/puppet/modules/stdlib/manifests/stages.pp
@@ -0,0 +1,43 @@
+# Class: 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.
+#
+# The high level stages are (in order):
+#
+# * setup
+# * main
+# * runtime
+# * setup_infra
+# * deploy_infra
+# * setup_app
+# * deploy_app
+# * deploy
+#
+# Parameters: none
+#
+# Actions:
+#
+# Declares various run-stages for deploying infrastructure,
+# language runtimes, and application layers.
+#
+# Requires: nothing
+#
+# Sample Usage:
+#
+# node default {
+# include stdlib
+# class { java: stage => 'runtime' }
+# }
+#
+class stdlib::stages {
+
+ stage { 'setup': before => Stage['main'] }
+ stage { 'runtime': require => Stage['main'] }
+ -> stage { 'setup_infra': }
+ -> stage { 'deploy_infra': }
+ -> stage { 'setup_app': }
+ -> stage { 'deploy_app': }
+ -> stage { 'deploy': }
+
+}
diff --git a/puppet/modules/stdlib/metadata.json b/puppet/modules/stdlib/metadata.json
new file mode 100644
index 0000000..5d3308e
--- /dev/null
+++ b/puppet/modules/stdlib/metadata.json
@@ -0,0 +1,270 @@
+{
+ "types": [
+ {
+ "doc": " A simple resource type intended to be used as an anchor in a composite class.\n\n In Puppet 2.6, when a class declares another class, the resources in the\n interior class are not contained by the exterior class. This interacts badly\n with the pattern of composing complex modules from smaller classes, as it\n makes it impossible for end users to specify order relationships between the\n exterior class and other modules.\n\n The anchor type lets you work around this. By sandwiching any interior\n classes between two no-op resources that _are_ contained by the exterior\n class, you can ensure that all resources in the module are contained.\n\n class ntp {\n # These classes will have the correct order relationship with each\n # other. However, without anchors, they won't have any order\n # relationship to Class['ntp'].\n class { 'ntp::package': }\n -> class { 'ntp::config': }\n -> class { 'ntp::service': }\n\n # These two resources \
"anchor\" the composed classes within the ntp\n # class.\n anchor { 'ntp::begin': } -> Class['ntp::package']\n Class['ntp::service'] -> anchor { 'ntp::end': }\n }\n\n This allows the end user of the ntp module to establish require and before\n relationships with Class['ntp']:\n\n class { 'ntp': } -> class { 'mcollective': }\n class { 'mcollective': } -> class { 'ntp': }\n\n",
+ "parameters": [
+ {
+ "doc": "The name of the anchor resource.",
+ "name": "name"
+ }
+ ],
+ "name": "anchor",
+ "properties": [
+
+ ]
+ },
+ {
+ "doc": " Ensures that a given line is contained within a file. The implementation\n matches the full line, including whitespace at the beginning and end. If\n the line is not contained in the given file, Puppet will add the line to\n ensure the desired state. Multiple resources may be declared to manage\n multiple lines in the same file.\n\n Example:\n\n file_line { 'sudo_rule':\n path => '/etc/sudoers',\n line => '%sudo ALL=(ALL) ALL',\n }\n file_line { 'sudo_rule_nopw':\n path => '/etc/sudoers',\n line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',\n }\n\n In this example, Puppet will ensure both of the specified lines are\n contained in the file /etc/sudoers.\n\n",
+ "providers": [
+ {
+ "doc": "",
+ "name": "ruby"
+ }
+ ],
+ "parameters": [
+ {
+ "doc": "An arbitrary name used as the identity of the resource.",
+ "name": "name"
+ },
+ {
+ "doc": "An optional regular expression to run against existing lines in the file;\\nif a match is found, we replace that line rather than adding a new line.",
+ "name": "match"
+ },
+ {
+ "doc": "The line to be appended to the file located by the path parameter.",
+ "name": "line"
+ },
+ {
+ "doc": "The file Puppet will ensure contains the line specified by the line parameter.",
+ "name": "path"
+ }
+ ],
+ "name": "file_line",
+ "properties": [
+ {
+ "doc": "The basic property that the resource should be in. Valid values are `present`, `absent`.",
+ "name": "ensure"
+ }
+ ]
+ }
+ ],
+ "license": "Apache 2.0",
+ "checksums": {
+ "spec/unit/puppet/parser/functions/uriescape_spec.rb": "8d9e15156d93fe29bfe91a2e83352ff4",
+ "Gemfile": "a7144ac8fdb2255ed7badb6b54f6c342",
+ "spec/unit/facter/root_home_spec.rb": "4f4c4236ac2368d2e27fd2f3eb606a19",
+ "spec/unit/puppet/parser/functions/size_spec.rb": "d126b696b21a8cd754d58f78ddba6f06",
+ "spec/unit/puppet/parser/functions/shuffle_spec.rb": "2141a54d2fb3cf725b88184d639677f4",
+ "spec/unit/puppet/parser/functions/validate_re_spec.rb": "b21292ad2f30c0d43ab2f0c2df0ba7d5",
+ "lib/puppet/parser/functions/flatten.rb": "25777b76f9719162a8bab640e5595b7a",
+ "lib/puppet/parser/functions/ensure_packages.rb": "ca852b2441ca44b91a984094de4e3afc",
+ "lib/puppet/parser/functions/validate_augeas.rb": "d4acca7b8a9fdada9ae39e5101902cc1",
+ "spec/unit/puppet/parser/functions/unique_spec.rb": "2df8b3b2edb9503943cb4dcb4a371867",
+ "tests/has_ip_network.pp": "abc05686797a776ea8c054657e6f7456",
+ "spec/fixtures/manifests/site.pp": "d41d8cd98f00b204e9800998ecf8427e",
+ "lib/puppet/parser/functions/defined_with_params.rb": "ffab4433d03f32b551f2ea024a2948fc",
+ "lib/puppet/parser/functions/size.rb": "8972d48c0f9e487d659bd7326b40b642",
+ "lib/puppet/parser/functions/has_ip_address.rb": "ee207f47906455a5aa49c4fb219dd325",
+ "lib/facter/util/puppet_settings.rb": "9f1d2593d0ae56bfca89d4b9266aeee1",
+ "spec/unit/puppet/parser/functions/any2array_spec.rb": "167e114cfa222de971bf8be141766b6a",
+ "spec/unit/facter/pe_required_facts_spec.rb": "0ec83db2a004a0d7f6395b34939c53b9",
+ "spec/unit/puppet/parser/functions/bool2num_spec.rb": "67c3055d5d4e4c9fbcaca82038a09081",
+ "lib/facter/root_home.rb": "f559294cceafcf70799339627d94871d",
+ "lib/puppet/parser/functions/loadyaml.rb": "2b912f257aa078e376d3b3f6a86c2a00",
+ "spec/unit/puppet/parser/functions/is_float_spec.rb": "171fc0e382d9856c2d8db2b70c9ec9cd",
+ "lib/puppet/type/anchor.rb": "bbd36bb49c3b554f8602d8d3df366c0c",
+ "lib/puppet/parser/functions/getparam.rb": "4dd7a0e35f4a3780dcfc9b19b4e0006e",
+ "lib/facter/facter_dot_d.rb": "b35b8b59ec579901444f984127f0b833",
+ "lib/puppet/parser/functions/strftime.rb": "e02e01a598ca5d7d6eee0ba22440304a",
+ "lib/puppet/parser/functions/max.rb": "f652fd0b46ef7d2fbdb42b141f8fdd1d",
+ "spec/spec_helper.rb": "4449b0cafd8f7b2fb440c0cdb0a1f2b3",
+ "lib/puppet/parser/functions/merge.rb": "52281fe881b762e2adfef20f58dc4180",
+ "lib/puppet/parser/functions/validate_slength.rb": "0ca530d1d3b45c3fe2d604c69acfc22f",
+ "spec/unit/puppet/parser/functions/suffix_spec.rb": "c3eed8e40066f2ad56264405c4192f2e",
+ "spec/unit/puppet/parser/functions/validate_bool_spec.rb": "32a580f280ba62bf17ccd30460d357bd",
+ "spec/unit/puppet/parser/functions/str2bool_spec.rb": "60e3eaea48b0f6efccc97010df7d912c",
+ "lib/puppet/parser/functions/reject.rb": "689f6a7c961a55fe9dcd240921f4c7f9",
+ "lib/puppet/parser/functions/delete.rb": "9b17b9f7f820adf02360147c1a2f4279",
+ "lib/puppet/parser/functions/strip.rb": "273d547c7b05c0598556464dfd12f5fd",
+ "lib/puppet/parser/functions/values.rb": "066a6e4170e5034edb9a80463dff2bb5",
+ "LICENSE": "38a048b9d82e713d4e1b2573e370a756",
+ "lib/puppet/parser/functions/is_array.rb": "875ca4356cb0d7a10606fb146b4a3d11",
+ "spec/unit/puppet/parser/functions/strip_spec.rb": "a01796bebbdabd3fad12b0662ea5966e",
+ "lib/puppet/parser/functions/swapcase.rb": "4902f38f0b9292afec66d40fee4b02ec",
+ "lib/puppet/parser/functions/has_ip_network.rb": "b4d726c8b2a0afac81ced8a3a28aa731",
+ "spec/unit/puppet/parser/functions/validate_array_spec.rb": "bcd231229554785c4270ca92ef99cb60",
+ "lib/puppet/parser/functions/validate_re.rb": "c6664b3943bc820415a43f16372dc2a9",
+ "lib/puppet/parser/functions/time.rb": "08d88d52abd1e230e3a2f82107545d48",
+ "lib/puppet/parser/functions/is_numeric.rb": "0a9bcc49e8f57af81bdfbb7e7c3a575c",
+ "spec/unit/puppet/parser/functions/merge_spec.rb": "a63c0bc2f812e27fbef570d834ef61ce",
+ "lib/puppet/parser/functions/count.rb": "9eb74eccd93e2b3c87fd5ea14e329eba",
+ "spec/unit/puppet/parser/functions/values_at_spec.rb": "de45fd8abbc4c037c3c4fac2dcf186f9",
+ "spec/monkey_patches/publicize_methods.rb": "ce2c98f38b683138c5ac649344a39276",
+ "spec/unit/puppet/parser/functions/is_hash_spec.rb": "408e121a5e30c4c5c4a0a383beb6e209",
+ "lib/puppet/parser/functions/chop.rb": "4691a56e6064b792ed4575e4ad3f3d20",
+ "spec/unit/puppet/parser/functions/validate_cmd_spec.rb": "538db08292a0ecc4cd902a14aaa55d74",
+ "spec/unit/puppet/parser/functions/is_integer_spec.rb": "a302cf1de5ccb494ca9614d2fc2b53c5",
+ "spec/functions/ensure_resource_spec.rb": "3423a445e13efc7663a71c6641d49d07",
+ "spec/unit/puppet/parser/functions/keys_spec.rb": "35cc2ed490dc68da6464f245dfebd617",
+ "manifests/init.pp": "f2ba5f36e7227ed87bbb69034fc0de8b",
+ "lib/puppet/parser/functions/dirname.rb": "bef7214eb89db3eb8f7ee5fc9dca0233",
+ "lib/puppet/parser/functions/validate_hash.rb": "e9cfaca68751524efe16ecf2f958a9a0",
+ "lib/puppet/parser/functions/join_keys_to_values.rb": "f29da49531228f6ca5b3aa0df00a14c2",
+ "spec/unit/puppet/parser/functions/delete_spec.rb": "0d84186ea618523b4b2a4ca0b5a09c9e",
+ "lib/puppet/parser/functions/validate_string.rb": "6afcbc51f83f0714348b8d61e06ea7eb",
+ "spec/unit/puppet/parser/functions/rstrip_spec.rb": "a408e933753c9c323a05d7079d32cbb3",
+ "spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb": "c67b71737bee9936f5261d41a37bad46",
+ "spec/unit/puppet/parser/functions/concat_spec.rb": "c21aaa84609f92290d5ffb2ce8ea4bf5",
+ "lib/puppet/parser/functions/unique.rb": "217ccce6d23235af92923f50f8556963",
+ "CHANGELOG": "344383410cb78409f0c59ecf38e8c21a",
+ "lib/puppet/parser/functions/member.rb": "541e67d06bc4155e79b00843a125e9bc",
+ "spec/unit/puppet/parser/functions/validate_string_spec.rb": "64a4f681084cba55775a070f7fab5e0c",
+ "lib/facter/puppet_vardir.rb": "c7ddc97e8a84ded3dd93baa5b9b3283d",
+ "lib/puppet/parser/functions/pick.rb": "2bede116a0651405c47e650bbf942abe",
+ "spec/unit/puppet/parser/functions/parseyaml_spec.rb": "65dfed872930ffe0d21954c15daaf498",
+ "lib/puppet/parser/functions/delete_at.rb": "6bc24b79390d463d8be95396c963381a",
+ "lib/puppet/parser/functions/zip.rb": "a80782461ed9465f0cd0c010936f1855",
+ "tests/file_line.pp": "67727539aa7b7dd76f06626fe734f7f7",
+ "lib/puppet/parser/functions/ensure_resource.rb": "3f68b8e17a16bfd01455cd73f8e324ba",
+ "lib/puppet/parser/functions/num2bool.rb": "605c12fa518c87ed2c66ae153e0686ce",
+ "spec/unit/puppet/parser/functions/grep_spec.rb": "78179537496a7150469e591a95e255d8",
+ "lib/puppet/parser/functions/keys.rb": "eb6ac815ea14fbf423580ed903ef7bad",
+ "spec/unit/puppet/parser/functions/num2bool_spec.rb": "8cd5b46b7c8e612dfae3362e3a68a5f9",
+ "lib/puppet/parser/functions/parsejson.rb": "e7f968c34928107b84cd0860daf50ab1",
+ "lib/puppet/parser/functions/is_mac_address.rb": "288bd4b38d4df42a83681f13e7eaaee0",
+ "lib/puppet/parser/functions/join.rb": "b28087823456ca5cf943de4a233ac77f",
+ "spec/unit/puppet/parser/functions/type_spec.rb": "422f2c33458fe9b0cc9614d16f7573ba",
+ "lib/puppet/parser/functions/downcase.rb": "9204a04c2a168375a38d502db8811bbe",
+ "spec/unit/puppet/parser/functions/validate_augeas_spec.rb": "1d5bcfbf97dc56b45734248a14358d4f",
+ "spec/unit/puppet/parser/functions/has_ip_address_spec.rb": "f53c7baeaf024ff577447f6c28c0f3a7",
+ "lib/puppet/parser/functions/is_function_available.rb": "88c63869cb5df3402bc9756a8d40c16d",
+ "lib/puppet/parser/functions/prefix.rb": "21fd6a2c1ee8370964346b3bfe829d2b",
+ "spec/watchr.rb": "b588ddf9ef1c19ab97aa892cc776da73",
+ "spec/unit/puppet/parser/functions/has_key_spec.rb": "3e4e730d98bbdfb88438b6e08e45868e",
+ "lib/puppet/parser/functions/values_at.rb": "094ac110ce9f7a5b16d0c80a0cf2243c",
+ "lib/puppet/parser/functions/fqdn_rotate.rb": "20743a138c56fc806a35cb7b60137dbc",
+ "lib/puppet/parser/functions/rstrip.rb": "8a0d69876bdbc88a2054ba41c9c38961",
+ "spec/unit/puppet/parser/functions/validate_slength_spec.rb": "a1b4d805149dc0143e9a57e43e1f84bf",
+ "spec/functions/ensure_packages_spec.rb": "935b4aec5ab36bdd0458c1a9b2a93ad5",
+ "lib/puppet/parser/functions/suffix.rb": "109279db4180441e75545dbd5f273298",
+ "lib/puppet/parser/functions/str2saltedsha512.rb": "49afad7b386be38ce53deaefef326e85",
+ "spec/unit/puppet/parser/functions/count_spec.rb": "db98ef89752a7112425f0aade10108e0",
+ "lib/puppet/parser/functions/hash.rb": "9d072527dfc7354b69292e9302906530",
+ "manifests/stages.pp": "cc6ed1751d334b0ea278c0335c7f0b5a",
+ "spec/unit/puppet/parser/functions/is_ip_address_spec.rb": "6040a9bae4e5c853966148b634501157",
+ "spec/unit/facter/pe_version_spec.rb": "ef031cca838f36f99b1dab3259df96a5",
+ "spec/unit/puppet/parser/functions/get_module_path_spec.rb": "b7ea196f548b1a9a745ab6671295ab27",
+ "lib/puppet/parser/functions/is_integer.rb": "a50ebc15c30bffd759e4a6f8ec6a0cf3",
+ "lib/puppet/parser/functions/reverse.rb": "1386371c0f5301055fdf99079e862b3e",
+ "spec/unit/puppet/parser/functions/has_interface_with_spec.rb": "7c16d731c518b434c81b8cb2227cc916",
+ "README_SPECS.markdown": "82bb4c6abbb711f40778b162ec0070c1",
+ "spec/unit/puppet/parser/functions/is_domain_name_spec.rb": "8eed3a9eb9334bf6a473ad4e2cabc2ec",
+ "spec/unit/puppet/parser/functions/join_spec.rb": "c3b50c39390a86b493511be2c6722235",
+ "lib/puppet/parser/functions/chomp.rb": "719d46923d75251f7b6b68b6e015cccc",
+ "lib/puppet/parser/functions/is_string.rb": "2bd9a652bbb2668323eee6c57729ff64",
+ "spec/unit/puppet/parser/functions/is_array_spec.rb": "8c020af9c360abdbbf1ba887bb26babe",
+ "Modulefile": "351bba73290cd526ca7bacd4c7d250dc",
+ "spec/unit/puppet/parser/functions/reject_spec.rb": "8e16c9f064870e958b6278261e480954",
+ "spec/unit/puppet/type/file_line_spec.rb": "d9f4e08e8b98e565a07f1b995593fa89",
+ "spec/unit/puppet/parser/functions/lstrip_spec.rb": "1fc2c2d80b5f724a358c3cfeeaae6249",
+ "lib/puppet/parser/functions/type.rb": "62f914d6c90662aaae40c5539701be60",
+ "lib/puppet/parser/functions/shuffle.rb": "6445e6b4dc62c37b184a60eeaf34414b",
+ "lib/puppet/parser/functions/has_key.rb": "7cd9728c38f0b0065f832dabd62b0e7e",
+ "lib/puppet/parser/functions/concat.rb": "f28a09811ff4d19bb5e7a540e767d65c",
+ "spec/unit/puppet/parser/functions/capitalize_spec.rb": "82a4209a033fc88c624f708c12e64e2a",
+ "tests/init.pp": "1d98070412c76824e66db4b7eb74d433",
+ "lib/puppet/provider/file_line/ruby.rb": "a445a57f9b884037320ea37307dbc92b",
+ "tests/has_ip_address.pp": "93ce02915f67ddfb43a049b2b84ef391",
+ "spec/unit/puppet/parser/functions/min_spec.rb": "bf80bf58261117bb24392670b624a611",
+ "lib/puppet/parser/functions/to_bytes.rb": "83f23c33adbfa42b2a9d9fc2db3daeb4",
+ "lib/puppet/parser/functions/sort.rb": "504b033b438461ca4f9764feeb017833",
+ "lib/puppet/parser/functions/capitalize.rb": "14481fc8c7c83fe002066ebcf6722f17",
+ "lib/puppet/type/file_line.rb": "3e8222cb58f3503b3ea7de3647c602a0",
+ "lib/puppet/parser/functions/has_interface_with.rb": "8d3ebca805dc6edb88b6b7a13d404787",
+ "spec/functions/getparam_spec.rb": "122f37cf9ec7489f1dae10db39c871b5",
+ "Rakefile": "f37e6131fe7de9a49b09d31596f5fbf1",
+ "spec/unit/puppet/parser/functions/downcase_spec.rb": "b0197829512f2e92a2d2b06ce8e2226f",
+ "spec/unit/puppet/parser/functions/max_spec.rb": "5562bccc643443af7e4fa7c9d1e52b8b",
+ "lib/puppet/parser/functions/validate_absolute_path.rb": "385137ac24a2dec6cecc4e6ea75be442",
+ "spec/unit/puppet/parser/functions/getvar_spec.rb": "842bf88d47077a9ae64097b6e39c3364",
+ "spec/unit/puppet/parser/functions/sort_spec.rb": "7039cd230a94e95d9d1de2e1094acae2",
+ "spec/unit/puppet/parser/functions/strftime_spec.rb": "bf140883ecf3254277306fa5b25f0344",
+ "spec/unit/puppet/parser/functions/is_mac_address_spec.rb": "644cd498b426ff2f9ea9cbc5d8e141d7",
+ "spec/unit/puppet/parser/functions/empty_spec.rb": "028c30267d648a172d8a81a9262c3abe",
+ "lib/puppet/parser/functions/is_domain_name.rb": "fba9f855df3bbf90d72dfd5201f65d2b",
+ "lib/puppet/parser/functions/get_module_path.rb": "d4bf50da25c0b98d26b75354fa1bcc45",
+ "spec/unit/puppet/provider/file_line/ruby_spec.rb": "e8cd7432739cb212d40a9148523bd4d7",
+ "spec/unit/puppet/parser/functions/reverse_spec.rb": "48169990e59081ccbd112b6703418ce4",
+ "spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb": "1de174be8835ba6fef86b590887bb2cc",
+ "spec/unit/puppet/parser/functions/prefix_spec.rb": "16a95b321d76e773812693c80edfbe36",
+ "spec/spec.opts": "a600ded995d948e393fbe2320ba8e51c",
+ "spec/monkey_patches/alias_should_to_must.rb": "7cd4065c63f06f1ab3aaa1c5f92af947",
+ "lib/puppet/parser/functions/uriescape.rb": "9ebc34f1b2f319626512b8cd7cde604c",
+ "lib/puppet/parser/functions/floor.rb": "c5a960e9714810ebb99198ff81a11a3b",
+ "lib/puppet/parser/functions/empty.rb": "ae92905c9d94ddca30bf56b7b1dabedf",
+ "spec/unit/puppet/parser/functions/range_spec.rb": "91d69115dea43f62a2dca9a10467d836",
+ "tests/has_interface_with.pp": "59c98b4af0d39fc11d1ef4c7a6dc8f7a",
+ "spec/unit/puppet/parser/functions/is_function_available.rb": "069ef7490eba66424cab75444f36828a",
+ "README_DEVELOPER.markdown": "220a8b28521b5c5d2ea87c4ddb511165",
+ "spec/unit/puppet/parser/functions/flatten_spec.rb": "583c9a70f93e492cfb22ffa1811f6aa0",
+ "lib/puppet/parser/functions/upcase.rb": "a5744a74577cfa136fca2835e75888d3",
+ "lib/puppet/parser/functions/str2bool.rb": "c822a8944747f5624b13f2da0df8db21",
+ "lib/puppet/parser/functions/is_hash.rb": "8c7d9a05084dab0389d1b779c8a05b1a",
+ "lib/puppet/parser/functions/abs.rb": "32161bd0435fdfc2aec2fc559d2b454b",
+ "spec/unit/puppet/parser/functions/validate_hash_spec.rb": "8529c74051ceb71e6b1b97c9cecdf625",
+ "spec/unit/puppet/parser/functions/member_spec.rb": "067c60985efc57022ca1c5508d74d77f",
+ "README.markdown": "b63097a958f22abf7999d475a6a4d32a",
+ "spec/unit/puppet/parser/functions/values_spec.rb": "0ac9e141ed1f612d7cc224f747b2d1d9",
+ "lib/puppet/parser/functions/validate_cmd.rb": "0319a15d24fd077ebabc2f79969f6ab5",
+ "lib/puppet/parser/functions/is_float.rb": "f1b0d333061d31bf0c25bd4c33dc134b",
+ "lib/puppet/parser/functions/bool2num.rb": "8e627eee990e811e35e7e838c586bd77",
+ "lib/puppet/parser/functions/validate_bool.rb": "4ddffdf5954b15863d18f392950b88f4",
+ "lib/puppet/parser/functions/grep.rb": "5682995af458b05f3b53dd794c4bf896",
+ "spec/unit/puppet/parser/functions/upcase_spec.rb": "813668919bc62cdd1d349dafc19fbbb3",
+ "spec/unit/puppet/parser/functions/parsejson_spec.rb": "37ab84381e035c31d6a3dd9bf73a3d53",
+ "spec/unit/puppet/parser/functions/squeeze_spec.rb": "df5b349c208a9a2a4d4b8e6d9324756f",
+ "spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb": "07839082d24d5a7628fd5bce6c8b35c3",
+ "spec/unit/puppet/parser/functions/chop_spec.rb": "4e9534d25b952b261c9f46add677c390",
+ "lib/puppet/parser/functions/squeeze.rb": "541f85b4203b55c9931d3d6ecd5c75f8",
+ "lib/puppet/parser/functions/lstrip.rb": "210b103f78622e099f91cc2956b6f741",
+ "spec/unit/puppet/type/anchor_spec.rb": "a5478a72a7fab2d215f39982a9230c18",
+ "lib/facter/pe_version.rb": "4a9353952963b011759f3e6652a10da5",
+ "spec/unit/puppet/parser/functions/hash_spec.rb": "826337a92d8f7a189b7ac19615db0ed7",
+ "spec/unit/puppet/parser/functions/floor_spec.rb": "d01ef7dfe0245d7a0a73d7df13cb02e3",
+ "spec/unit/puppet/parser/functions/time_spec.rb": "b6d0279062779efe5153fe5cfafc5bbd",
+ "spec/unit/puppet/parser/functions/swapcase_spec.rb": "0660ce8807608cc8f98ad1edfa76a402",
+ "lib/puppet/parser/functions/validate_array.rb": "72b29289b8af1cfc3662ef9be78911b8",
+ "lib/puppet/parser/functions/is_ip_address.rb": "a714a736c1560e8739aaacd9030cca00",
+ "lib/puppet/parser/functions/getvar.rb": "10bf744212947bc6a7bfd2c9836dbd23",
+ "RELEASE_PROCESS.markdown": "94b92bc99ac4106ba1a74d5c04e520f9",
+ "spec/classes/anchor_spec.rb": "695d65275c3ac310d7fa23b91f8bbb4a",
+ "lib/puppet/parser/functions/any2array.rb": "a81e71d6b67a551d38770ba9a1948a75",
+ "spec/functions/defined_with_params_spec.rb": "3bdfac38e3d6f06140ff2e926f4ebed2",
+ "spec/unit/puppet/parser/functions/pick_spec.rb": "aba6247d3925e373272fca6768fd5403",
+ "spec/unit/puppet/parser/functions/to_bytes_spec.rb": "80aaf68cf7e938e46b5278c1907af6be",
+ "spec/unit/puppet/parser/functions/is_string_spec.rb": "5c015d8267de852da3a12b984e077092",
+ "spec/unit/puppet/parser/functions/abs_spec.rb": "0a5864a29a8e9e99acc483268bd5917c",
+ "spec/unit/facter/util/puppet_settings_spec.rb": "345bcbef720458e25be0190b7638e4d9",
+ "spec/unit/puppet/parser/functions/zip_spec.rb": "06a86e4e70d2aea63812582aae1d26c4",
+ "spec/unit/puppet/parser/functions/dirname_spec.rb": "1d7cf70468c2cfa6dacfc75935322395",
+ "spec/unit/puppet/parser/functions/delete_at_spec.rb": "5a4287356b5bd36a6e4c100421215b8e",
+ "spec/unit/puppet/parser/functions/chomp_spec.rb": "3cd8e2fe6b12efeffad94cce5b693b7c",
+ "spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb": "7c7937411b7fe4bb944c0c022d3a96b0",
+ "lib/puppet/parser/functions/range.rb": "033048bba333fe429e77e0f2e91db25f",
+ "lib/puppet/parser/functions/parseyaml.rb": "00f10ec1e2b050e23d80c256061ebdd7",
+ "spec/unit/puppet/parser/functions/is_numeric_spec.rb": "5f08148803b6088c27b211c446ad3658",
+ "spec/unit/puppet/parser/functions/has_ip_network_spec.rb": "885ea8a4c987b735d683b742bf846cb1",
+ "lib/puppet/parser/functions/min.rb": "0d2a1b7e735ab251c5469e735fa3f4c6",
+ "CONTRIBUTING.md": "fdddc4606dc3b6949e981e6bf50bc8e5"
+ },
+ "version": "4.1.0",
+ "description": "Standard Library for Puppet Modules",
+ "source": "git://github.com/puppetlabs/puppetlabs-stdlib.git",
+ "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
+ "summary": "Puppet Module Standard Library",
+ "dependencies": [
+
+ ],
+ "author": "puppetlabs",
+ "name": "puppetlabs-stdlib"
+}
\ No newline at end of file
diff --git a/puppet/modules/stdlib/spec/classes/anchor_spec.rb b/puppet/modules/stdlib/spec/classes/anchor_spec.rb
new file mode 100644
index 0000000..2dd17de
--- /dev/null
+++ b/puppet/modules/stdlib/spec/classes/anchor_spec.rb
@@ -0,0 +1,32 @@
+require 'puppet'
+require 'rspec-puppet'
+
+describe "anchorrefresh" do
+ let(:node) { 'testhost.example.com' }
+ let :pre_condition do
+ <<-ANCHORCLASS
+class anchored {
+ anchor { 'anchored::begin': }
+ ~> anchor { 'anchored::end': }
+}
+
+class anchorrefresh {
+ notify { 'first': }
+ ~> class { 'anchored': }
+ ~> anchor { 'final': }
+}
+ ANCHORCLASS
+ end
+
+ def apply_catalog_and_return_exec_rsrc
+ catalog = subject.to_ral
+ transaction = catalog.apply
+ transaction.resource_status("Anchor[final]")
+ end
+
+ it 'propagates events through the anchored class' do
+ resource = apply_catalog_and_return_exec_rsrc
+
+ expect(resource.restarted).to eq(true)
+ end
+end
diff --git a/puppet/modules/stdlib/spec/fixtures/manifests/site.pp b/puppet/modules/stdlib/spec/fixtures/manifests/site.pp
new file mode 100644
index 0000000..e69de29
diff --git a/puppet/modules/stdlib/spec/functions/defined_with_params_spec.rb b/puppet/modules/stdlib/spec/functions/defined_with_params_spec.rb
new file mode 100644
index 0000000..28dbab3
--- /dev/null
+++ b/puppet/modules/stdlib/spec/functions/defined_with_params_spec.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+require 'rspec-puppet'
+describe 'defined_with_params' do
+ describe 'when a resource is not specified' do
+ it { should run.with_params().and_raise_error(ArgumentError) }
+ end
+ describe 'when compared against a resource with no attributes' do
+ let :pre_condition do
+ 'user { "dan": }'
+ end
+ it do
+ should run.with_params('User[dan]', {}).and_return(true)
+ should run.with_params('User[bob]', {}).and_return(false)
+ should run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false)
+ end
+ end
+
+ describe 'when compared against a resource with attributes' do
+ let :pre_condition do
+ 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
+ end
+ it do
+ should run.with_params('User[dan]', {}).and_return(true)
+ should run.with_params('User[dan]', '').and_return(true)
+ should run.with_params('User[dan]', {'ensure' => 'present'}
+ ).and_return(true)
+ should run.with_params('User[dan]',
+ {'ensure' => 'present', 'managehome' => false}
+ ).and_return(true)
+ should run.with_params('User[dan]',
+ {'ensure' => 'absent', 'managehome' => false}
+ ).and_return(false)
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/functions/ensure_packages_spec.rb b/puppet/modules/stdlib/spec/functions/ensure_packages_spec.rb
new file mode 100644
index 0000000..1c2a328
--- /dev/null
+++ b/puppet/modules/stdlib/spec/functions/ensure_packages_spec.rb
@@ -0,0 +1,42 @@
+#! /usr/bin/env ruby
+
+require 'spec_helper'
+require 'rspec-puppet'
+
+describe 'ensure_packages' do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'argument handling' do
+ it 'fails with no arguments' do
+ should run.with_params().and_raise_error(Puppet::ParseError)
+ end
+ it 'requires an array' do
+ lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error
+ end
+ it 'fails when given a string' do
+ should run.with_params('foo').and_raise_error(Puppet::ParseError)
+ end
+ end
+
+ context 'given a catalog containing Package[puppet]{ensure => absent}' do
+ let :pre_condition do
+ 'package { puppet: ensure => absent }'
+ end
+
+ # NOTE: should run.with_params has the side effect of making the compiler
+ # available to the test harness.
+ it 'has no effect on Package[puppet]' do
+ should run.with_params(['puppet'])
+ rsrc = compiler.catalog.resource('Package[puppet]')
+ rsrc.to_hash.should == {:ensure => "absent"}
+ end
+ end
+
+ context 'given a clean catalog' do
+ it 'declares package resources with ensure => present' do
+ should run.with_params(['facter'])
+ rsrc = compiler.catalog.resource('Package[facter]')
+ rsrc.to_hash.should == {:name => "facter", :ensure => "present"}
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/functions/ensure_resource_spec.rb b/puppet/modules/stdlib/spec/functions/ensure_resource_spec.rb
new file mode 100644
index 0000000..2e8aefc
--- /dev/null
+++ b/puppet/modules/stdlib/spec/functions/ensure_resource_spec.rb
@@ -0,0 +1,64 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+require 'rspec-puppet'
+describe 'ensure_resource' do
+ describe 'when a type or title is not specified' do
+ it { should run.with_params().and_raise_error(ArgumentError) }
+ it { should run.with_params(['type']).and_raise_error(ArgumentError) }
+ end
+
+ describe 'when compared against a resource with no attributes' do
+ let :pre_condition do
+ 'user { "dan": }'
+ end
+ it "should contain the the ensured resources" do
+ subject.should run.with_params('user', 'dan', {})
+ compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
+ end
+ end
+
+ describe 'when compared against a resource with attributes' do
+ let :pre_condition do
+ 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}'
+ end
+ # these first three should not fail
+ it { should run.with_params('User', 'dan', {}) }
+ it { should run.with_params('User', 'dan', '') }
+ it { should run.with_params('User', 'dan', {'ensure' => 'present'}) }
+ it { should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false}) }
+ # test that this fails
+ it { should run.with_params('User', 'dan', {'ensure' => 'absent', 'managehome' => false}).and_raise_error(Puppet::Error) }
+ end
+
+ describe 'when an array of new resources are passed in' do
+ it "should contain the ensured resources" do
+ subject.should run.with_params('User', ['dan', 'alex'], {})
+ compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
+ compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]'
+ end
+ end
+
+ describe 'when an array of existing resources is compared against existing resources' do
+ let :pre_condition do
+ 'user { "dan": ensure => present; "alex": ensure => present }'
+ end
+ it "should return the existing resources" do
+ subject.should run.with_params('User', ['dan', 'alex'], {})
+ compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]'
+ compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]'
+ end
+ end
+
+ describe 'when compared against existing resources with attributes' do
+ let :pre_condition do
+ 'user { "dan": ensure => present; "alex": ensure => present }'
+ end
+ # These should not fail
+ it { should run.with_params('User', ['dan', 'alex'], {}) }
+ it { should run.with_params('User', ['dan', 'alex'], '') }
+ it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'present'}) }
+ # This should fail
+ it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'absent'}).and_raise_error(Puppet::Error) }
+ end
+end
diff --git a/puppet/modules/stdlib/spec/functions/getparam_spec.rb b/puppet/modules/stdlib/spec/functions/getparam_spec.rb
new file mode 100644
index 0000000..d9c50a6
--- /dev/null
+++ b/puppet/modules/stdlib/spec/functions/getparam_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+require 'rspec-puppet'
+describe 'getparam' do
+ describe 'when a resource is not specified' do
+ it do
+ should run.with_params().and_raise_error(ArgumentError)
+ should run.with_params('User[dan]').and_raise_error(ArgumentError)
+ should run.with_params('User[dan]', {}).and_raise_error(ArgumentError)
+ should run.with_params('User[dan]', '').and_return('')
+ end
+ end
+ describe 'when compared against a resource with no params' do
+ let :pre_condition do
+ 'user { "dan": }'
+ end
+ it do
+ should run.with_params('User[dan]', 'shell').and_return('')
+ end
+ end
+
+ describe 'when compared against a resource with params' do
+ let :pre_condition do
+ 'user { "dan": ensure => present, shell => "/bin/sh", managehome => false}'
+ end
+ it do
+ should run.with_params('User[dan]', 'shell').and_return('/bin/sh')
+ should run.with_params('User[dan]', '').and_return('')
+ should run.with_params('User[dan]', 'ensure').and_return('present')
+ should run.with_params('User[dan]', 'managehome').and_return(false)
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/monkey_patches/alias_should_to_must.rb b/puppet/modules/stdlib/spec/monkey_patches/alias_should_to_must.rb
new file mode 100755
index 0000000..1a11117
--- /dev/null
+++ b/puppet/modules/stdlib/spec/monkey_patches/alias_should_to_must.rb
@@ -0,0 +1,8 @@
+require 'rspec'
+
+class Object
+ # This is necessary because the RAL has a 'should'
+ # method.
+ alias :must :should
+ alias :must_not :should_not
+end
diff --git a/puppet/modules/stdlib/spec/monkey_patches/publicize_methods.rb b/puppet/modules/stdlib/spec/monkey_patches/publicize_methods.rb
new file mode 100755
index 0000000..f3a1abf
--- /dev/null
+++ b/puppet/modules/stdlib/spec/monkey_patches/publicize_methods.rb
@@ -0,0 +1,10 @@
+# Some monkey-patching to allow us to test private methods.
+class Class
+ def publicize_methods(*methods)
+ saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods
+
+ self.class_eval { public(*saved_private_instance_methods) }
+ yield
+ self.class_eval { private(*saved_private_instance_methods) }
+ end
+end
diff --git a/puppet/modules/stdlib/spec/spec.opts b/puppet/modules/stdlib/spec/spec.opts
new file mode 100644
index 0000000..91cd642
--- /dev/null
+++ b/puppet/modules/stdlib/spec/spec.opts
@@ -0,0 +1,6 @@
+--format
+s
+--colour
+--loadby
+mtime
+--backtrace
diff --git a/puppet/modules/stdlib/spec/spec_helper.rb b/puppet/modules/stdlib/spec/spec_helper.rb
new file mode 100644
index 0000000..931d35c
--- /dev/null
+++ b/puppet/modules/stdlib/spec/spec_helper.rb
@@ -0,0 +1,28 @@
+dir = File.expand_path(File.dirname(__FILE__))
+$LOAD_PATH.unshift File.join(dir, 'lib')
+
+# Don't want puppet getting the command line arguments for rake or autotest
+ARGV.clear
+
+require 'puppet'
+require 'facter'
+require 'mocha'
+gem 'rspec', '>=2.0.0'
+require 'rspec/expectations'
+
+require 'puppetlabs_spec_helper/module_spec_helper'
+
+RSpec.configure do |config|
+ # FIXME REVISIT - We may want to delegate to Facter like we do in
+ # Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because
+ # this behavior is a duplication of the spec_helper in Facter.
+ config.before :each do
+ # Ensure that we don't accidentally cache facts and environment between
+ # test cases. This requires each example group to explicitly load the
+ # facts being exercised with something like
+ # Facter.collection.loader.load(:ipaddress)
+ Facter::Util::Loader.any_instance.stubs(:load_all)
+ Facter.clear
+ Facter.clear_messages
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/facter/pe_required_facts_spec.rb b/puppet/modules/stdlib/spec/unit/facter/pe_required_facts_spec.rb
new file mode 100644
index 0000000..f219b37
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/facter/pe_required_facts_spec.rb
@@ -0,0 +1,69 @@
+# Puppet Enterprise requires the following facts to be set in order to operate.
+# These facts are set using the file ???? and the two facts are
+# `fact_stomp_port`, and `fact_stomp_server`.
+#
+
+require 'spec_helper'
+
+describe "External facts in /etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt" do
+ context "With Facter 1.6.17 which does not have external facts support" do
+ before :each do
+ Facter.stubs(:version).returns("1.6.17")
+ # Stub out the filesystem for stdlib
+ Dir.stubs(:entries).with("/etc/puppetlabs/facter/facts.d").
+ returns(['puppet_enterprise_installer.txt'])
+ Dir.stubs(:entries).with("/etc/facter/facts.d").returns([])
+ File.stubs(:readlines).with('/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt').
+ returns([
+ "fact_stomp_port=61613\n",
+ "fact_stomp_server=puppetmaster.acme.com\n",
+ "fact_is_puppetagent=true\n",
+ "fact_is_puppetmaster=false\n",
+ "fact_is_puppetca=false\n",
+ "fact_is_puppetconsole=false\n",
+ ])
+ if Facter.collection.respond_to? :load
+ Facter.collection.load(:facter_dot_d)
+ else
+ Facter.collection.loader.load(:facter_dot_d)
+ end
+ end
+
+ it 'defines fact_stomp_port' do
+ Facter.fact(:fact_stomp_port).value.should == '61613'
+ end
+ it 'defines fact_stomp_server' do
+ Facter.fact(:fact_stomp_server).value.should == 'puppetmaster.acme.com'
+ end
+ it 'defines fact_is_puppetagent' do
+ Facter.fact(:fact_is_puppetagent).value.should == 'true'
+ end
+ it 'defines fact_is_puppetmaster' do
+ Facter.fact(:fact_is_puppetmaster).value.should == 'false'
+ end
+ it 'defines fact_is_puppetca' do
+ Facter.fact(:fact_is_puppetca).value.should == 'false'
+ end
+ it 'defines fact_is_puppetconsole' do
+ Facter.fact(:fact_is_puppetconsole).value.should == 'false'
+ end
+ end
+
+ [ '1.7.1', '2.0.1' ].each do |v|
+ context "With Facter #{v} which has external facts support" do
+ before :each do
+ Facter.stubs(:version).returns(v)
+ end
+
+ it 'does not call Facter::Util::DotD.new' do
+ Facter::Util::DotD.expects(:new).never
+
+ if Facter.collection.respond_to? :load
+ Facter.collection.load(:facter_dot_d)
+ else
+ Facter.collection.loader.load(:facter_dot_d)
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/facter/pe_version_spec.rb b/puppet/modules/stdlib/spec/unit/facter/pe_version_spec.rb
new file mode 100644
index 0000000..931c6d4
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/facter/pe_version_spec.rb
@@ -0,0 +1,76 @@
+#!/usr/bin/env rspec
+
+require 'spec_helper'
+
+describe "PE Version specs" do
+ before :each do
+ # Explicitly load the pe_version.rb file which contains generated facts
+ # that cannot be automatically loaded. Puppet 2.x implements
+ # Facter.collection.load while Facter 1.x markes Facter.collection.load as
+ # a private method.
+ if Facter.collection.respond_to? :load
+ Facter.collection.load(:pe_version)
+ else
+ Facter.collection.loader.load(:pe_version)
+ end
+ end
+
+ context "If PE is installed" do
+ %w{ 2.6.1 2.10.300 }.each do |version|
+ puppetversion = "2.7.19 (Puppet Enterprise #{version})"
+ context "puppetversion => #{puppetversion}" do
+ before :each do
+ Facter.fact(:puppetversion).stubs(:value).returns(puppetversion)
+ end
+
+ (major,minor,patch) = version.split(".")
+
+ it "Should return true" do
+ Facter.fact(:is_pe).value.should == true
+ end
+
+ it "Should have a version of #{version}" do
+ Facter.fact(:pe_version).value.should == version
+ end
+
+ it "Should have a major version of #{major}" do
+ Facter.fact(:pe_major_version).value.should == major
+ end
+
+ it "Should have a minor version of #{minor}" do
+ Facter.fact(:pe_minor_version).value.should == minor
+ end
+
+ it "Should have a patch version of #{patch}" do
+ Facter.fact(:pe_patch_version).value.should == patch
+ end
+ end
+ end
+ end
+
+ context "When PE is not installed" do
+ before :each do
+ Facter.fact(:puppetversion).stubs(:value).returns("2.7.19")
+ end
+
+ it "is_pe is false" do
+ Facter.fact(:is_pe).value.should == false
+ end
+
+ it "pe_version is nil" do
+ Facter.fact(:pe_version).value.should be_nil
+ end
+
+ it "pe_major_version is nil" do
+ Facter.fact(:pe_major_version).value.should be_nil
+ end
+
+ it "pe_minor_version is nil" do
+ Facter.fact(:pe_minor_version).value.should be_nil
+ end
+
+ it "Should have a patch version" do
+ Facter.fact(:pe_patch_version).value.should be_nil
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/facter/root_home_spec.rb b/puppet/modules/stdlib/spec/unit/facter/root_home_spec.rb
new file mode 100644
index 0000000..ce80684
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/facter/root_home_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+require 'facter/root_home'
+
+describe Facter::Util::RootHome do
+ context "solaris" do
+ let(:root_ent) { "root:x:0:0:Super-User:/:/sbin/sh" }
+ let(:expected_root_home) { "/" }
+
+ it "should return /" do
+ Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
+ Facter::Util::RootHome.get_root_home.should == expected_root_home
+ end
+ end
+ context "linux" do
+ let(:root_ent) { "root:x:0:0:root:/root:/bin/bash" }
+ let(:expected_root_home) { "/root" }
+
+ it "should return /root" do
+ Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
+ Facter::Util::RootHome.get_root_home.should == expected_root_home
+ end
+ end
+ context "macosx" do
+ let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" }
+ let(:expected_root_home) { "/var/root" }
+
+ it "should return /var/root" do
+ Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent)
+ Facter::Util::RootHome.get_root_home.should == expected_root_home
+ end
+ end
+ context "windows" do
+ before :each do
+ Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil)
+ end
+ it "should be nil on windows" do
+ Facter::Util::RootHome.get_root_home.should be_nil
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb b/puppet/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb
new file mode 100644
index 0000000..c3ce6ea
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+require 'facter/util/puppet_settings'
+
+describe Facter::Util::PuppetSettings do
+
+ describe "#with_puppet" do
+ context "Without Puppet loaded" do
+ before(:each) do
+ Module.expects(:const_get).with("Puppet").raises(NameError)
+ end
+
+ it 'should be nil' do
+ subject.with_puppet { Puppet[:vardir] }.should be_nil
+ end
+ it 'should not yield to the block' do
+ Puppet.expects(:[]).never
+ subject.with_puppet { Puppet[:vardir] }.should be_nil
+ end
+ end
+ context "With Puppet loaded" do
+ module Puppet; end
+ let(:vardir) { "/var/lib/puppet" }
+
+ before :each do
+ Puppet.expects(:[]).with(:vardir).returns vardir
+ end
+ it 'should yield to the block' do
+ subject.with_puppet { Puppet[:vardir] }
+ end
+ it 'should return the nodes vardir' do
+ subject.with_puppet { Puppet[:vardir] }.should eq vardir
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb
new file mode 100755
index 0000000..c0b4297
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb
@@ -0,0 +1,25 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the abs function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("abs").should == "function_abs"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert a negative number into a positive" do
+ result = scope.function_abs(["-34"])
+ result.should(eq(34))
+ end
+
+ it "should do nothing with a positive number" do
+ result = scope.function_abs(["5678"])
+ result.should(eq(5678))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb
new file mode 100644
index 0000000..b266e84
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb
@@ -0,0 +1,55 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the any2array function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("any2array").should == "function_any2array"
+ end
+
+ it "should return an empty array if there is less than 1 argument" do
+ result = scope.function_any2array([])
+ result.should(eq([]))
+ end
+
+ it "should convert boolean true to [ true ] " do
+ result = scope.function_any2array([true])
+ result.should(eq([true]))
+ end
+
+ it "should convert one object to [object]" do
+ result = scope.function_any2array(['one'])
+ result.should(eq(['one']))
+ end
+
+ it "should convert multiple objects to [objects]" do
+ result = scope.function_any2array(['one', 'two'])
+ result.should(eq(['one', 'two']))
+ end
+
+ it "should return empty array it was called with" do
+ result = scope.function_any2array([[]])
+ result.should(eq([]))
+ end
+
+ it "should return one-member array it was called with" do
+ result = scope.function_any2array([['string']])
+ result.should(eq(['string']))
+ end
+
+ it "should return multi-member array it was called with" do
+ result = scope.function_any2array([['one', 'two']])
+ result.should(eq(['one', 'two']))
+ end
+
+ it "should return members of a hash it was called with" do
+ result = scope.function_any2array([{ 'key' => 'value' }])
+ result.should(eq(['key', 'value']))
+ end
+
+ it "should return an empty array if it was called with an empty hash" do
+ result = scope.function_any2array([{ }])
+ result.should(eq([]))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb
new file mode 100755
index 0000000..518ac85
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the bool2num function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("bool2num").should == "function_bool2num"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ 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])
+ result.should(eq(0))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb
new file mode 100755
index 0000000..69c9758
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the capitalize function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("capitalize").should == "function_capitalize"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should capitalize the beginning of a string" do
+ result = scope.function_capitalize(["abc"])
+ result.should(eq("Abc"))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb
new file mode 100755
index 0000000..e425365
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the chomp function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("chomp").should == "function_chomp"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_chomp([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should chomp the end of a string" do
+ result = scope.function_chomp(["abc\n"])
+ result.should(eq("abc"))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb
new file mode 100755
index 0000000..9e466de
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the chop function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("chop").should == "function_chop"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_chop([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should chop the end of a string" do
+ result = scope.function_chop(["asdf\n"])
+ result.should(eq("asdf"))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb
new file mode 100644
index 0000000..123188b
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb
@@ -0,0 +1,15 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the concat function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_concat([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should be able to concat an array" do
+ result = scope.function_concat([['1','2','3'],['4','5','6']])
+ result.should(eq(['1','2','3','4','5','6']))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/count_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/count_spec.rb
new file mode 100644
index 0000000..2453815
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/count_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the count function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("count").should == "function_count"
+ end
+
+ it "should raise a ArgumentError if there is more than 2 arguments" do
+ lambda { scope.function_count(['foo', 'bar', 'baz']) }.should( raise_error(ArgumentError))
+ end
+
+ it "should be able to count arrays" do
+ scope.function_count([["1","2","3"]]).should(eq(3))
+ end
+
+ it "should be able to count matching elements in arrays" do
+ scope.function_count([["1", "2", "2"], "2"]).should(eq(2))
+ end
+
+ it "should not count nil or empty strings" do
+ scope.function_count([["foo","bar",nil,""]]).should(eq(2))
+ end
+
+ it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do
+ expect(scope.function_count([["foo",:undef,:undef]])).to eq(1)
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb
new file mode 100755
index 0000000..d8d9618
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the delete_at function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("delete_at").should == "function_delete_at"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should delete an item at specified location from an array" do
+ result = scope.function_delete_at([['a','b','c'],1])
+ result.should(eq(['a','c']))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb
new file mode 100755
index 0000000..2f29c93
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb
@@ -0,0 +1,38 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the delete function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("delete").should == "function_delete"
+ end
+
+ it "should raise a ParseError if there are fewer than 2 arguments" do
+ lambda { scope.function_delete([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there are greater than 2 arguments" do
+ lambda { scope.function_delete([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a TypeError if a number is passed as the first argument" do
+ lambda { scope.function_delete([1, 'bar']) }.should( raise_error(TypeError))
+ end
+
+ it "should delete all instances of an element from an array" do
+ result = scope.function_delete([['a','b','c','b'],'b'])
+ result.should(eq(['a','c']))
+ end
+
+ it "should delete all instances of a substring from a string" do
+ result = scope.function_delete(['foobarbabarz','bar'])
+ result.should(eq('foobaz'))
+ end
+
+ it "should delete a key from a hash" do
+ result = scope.function_delete([{ 'a' => 1, 'b' => 2, 'c' => 3 },'b'])
+ result.should(eq({ 'a' => 1, 'c' => 3 }))
+ end
+
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb
new file mode 100755
index 0000000..fb3b4fe
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the dirname function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("dirname").should == "function_dirname"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_dirname([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return dirname for an absolute path" do
+ result = scope.function_dirname(['/path/to/a/file.ext'])
+ result.should(eq('/path/to/a'))
+ end
+
+ it "should return dirname for a relative path" do
+ result = scope.function_dirname(['path/to/a/file.ext'])
+ result.should(eq('path/to/a'))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb
new file mode 100755
index 0000000..acef1f0
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the downcase function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("downcase").should == "function_downcase"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_downcase([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should downcase a string" do
+ result = scope.function_downcase(["ASFD"])
+ result.should(eq("asfd"))
+ end
+
+ it "should do nothing to a string that is already downcase" do
+ result = scope.function_downcase(["asdf asdf"])
+ result.should(eq("asdf asdf"))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb
new file mode 100755
index 0000000..7745875
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb
@@ -0,0 +1,23 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the empty function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should exist" do
+ Puppet::Parser::Functions.function("empty").should == "function_empty"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_empty([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a true for an empty string" do
+ result = scope.function_empty([''])
+ result.should(eq(true))
+ end
+
+ it "should return a false for a non-empty string" do
+ result = scope.function_empty(['asdf'])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb
new file mode 100755
index 0000000..dba7a6b
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the flatten function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should exist" do
+ Puppet::Parser::Functions.function("flatten").should == "function_flatten"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there is more than 1 argument" do
+ lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should flatten a complex data structure" do
+ result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]])
+ result.should(eq(["a","b","c","d","e","f","g"]))
+ end
+
+ it "should do nothing to a structure that is already flat" do
+ result = scope.function_flatten([["a","b","c","d"]])
+ result.should(eq(["a","b","c","d"]))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb
new file mode 100644
index 0000000..dbc8c77
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the floor function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("floor").should == "function_floor"
+ end
+
+ it "should raise a ParseError if there is less than 1 argument" do
+ lambda { scope.function_floor([]) }.should( raise_error(Puppet::ParseError, /Wrong number of arguments/))
+ end
+
+ it "should should raise a ParseError if input isn't numeric (eg. String)" do
+ lambda { scope.function_floor(["foo"]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/))
+ end
+
+ it "should should raise a ParseError if input isn't numeric (eg. Boolean)" do
+ lambda { scope.function_floor([true]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/))
+ end
+
+ it "should return an integer when a numeric type is passed" do
+ result = scope.function_floor([12.4])
+ result.is_a?(Integer).should(eq(true))
+ end
+
+ it "should return the input when an integer is passed" do
+ result = scope.function_floor([7])
+ result.should(eq(7))
+ end
+
+ it "should return the largest integer less than or equal to the input" do
+ result = scope.function_floor([3.8])
+ result.should(eq(3))
+ end
+end
+
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb
new file mode 100644
index 0000000..2577723
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the fqdn_rotate function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("fqdn_rotate").should == "function_fqdn_rotate"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_fqdn_rotate([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should rotate a string and the result should be the same size" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
+ result = scope.function_fqdn_rotate(["asdf"])
+ result.size.should(eq(4))
+ end
+
+ it "should rotate a string to give the same results for one host" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice
+ scope.function_fqdn_rotate(["abcdefg"]).should eql(scope.function_fqdn_rotate(["abcdefg"]))
+ end
+
+ it "should rotate a string to give different values on different hosts" do
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
+ val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
+ scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2")
+ val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
+ val1.should_not eql(val2)
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb
new file mode 100644
index 0000000..486bef6
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb
@@ -0,0 +1,46 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:get_module_path) do
+ Internals = PuppetlabsSpec::PuppetInternals
+ class StubModule
+ attr_reader :path
+ def initialize(path)
+ @path = path
+ end
+ end
+
+ def scope(environment = "production")
+ Internals.scope(:compiler => Internals.compiler(:node => Internals.node(:environment => environment)))
+ end
+
+ it 'should only allow one argument' do
+ expect { scope.function_get_module_path([]) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/)
+ expect { scope.function_get_module_path(['1','2','3']) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/)
+ end
+ it 'should raise an exception when the module cannot be found' do
+ expect { scope.function_get_module_path(['foo']) }.to raise_error(Puppet::ParseError, /Could not find module/)
+ end
+ describe 'when locating a module' do
+ let(:modulepath) { "/tmp/does_not_exist" }
+ let(:path_of_module_foo) { StubModule.new("/tmp/does_not_exist/foo") }
+
+ before(:each) { Puppet[:modulepath] = modulepath }
+
+ it 'should be able to find module paths from the modulepath setting' do
+ Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
+ scope.function_get_module_path(['foo']).should == path_of_module_foo.path
+ end
+ it 'should be able to find module paths when the modulepath is a list' do
+ Puppet[:modulepath] = modulepath + ":/tmp"
+ Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo)
+ scope.function_get_module_path(['foo']).should == path_of_module_foo.path
+ end
+ it 'should respect the environment' do
+ pending("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/
+ Puppet.settings[:environment] = 'danstestenv'
+ Puppet::Module.expects(:find).with('foo', 'danstestenv').returns(path_of_module_foo)
+ scope('danstestenv').function_get_module_path(['foo']).should == path_of_module_foo.path
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb
new file mode 100644
index 0000000..5ff834e
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb
@@ -0,0 +1,37 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:getvar) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ describe 'when calling getvar from puppet' do
+
+ it "should not compile when no arguments are passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = '$foo = getvar()'
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should not compile when too many arguments are passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = '$foo = getvar("foo::bar", "baz")'
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should lookup variables in other namespaces" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ class site::data { $foo = 'baz' }
+ include site::data
+ $foo = getvar("site::data::foo")
+ if $foo != 'baz' {
+ fail('getvar did not return what we expect')
+ }
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb
new file mode 100755
index 0000000..a93b842
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the grep function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("grep").should == "function_grep"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_grep([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should grep contents from an array" do
+ result = scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"])
+ result.should(eq(["aaabbb","bbbccc"]))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb
new file mode 100755
index 0000000..c5264e4
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb
@@ -0,0 +1,64 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:has_interface_with) do
+
+ let(:scope) do
+ PuppetlabsSpec::PuppetInternals.scope
+ end
+
+ # The subject of these examples is the method itself.
+ subject do
+ function_name = Puppet::Parser::Functions.function(:has_interface_with)
+ scope.method(function_name)
+ end
+
+ # We need to mock out the Facts so we can specify how we expect this function
+ # to behave on different platforms.
+ context "On Mac OS X Systems" do
+ before :each do
+ scope.stubs(:lookupvar).with("interfaces").returns('lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0')
+ end
+ it 'should have loopback (lo0)' do
+ subject.call(['lo0']).should be_true
+ end
+ it 'should not have loopback (lo)' do
+ subject.call(['lo']).should be_false
+ end
+ end
+ context "On Linux Systems" do
+ before :each do
+ scope.stubs(:lookupvar).with("interfaces").returns('eth0,lo')
+ scope.stubs(:lookupvar).with("ipaddress").returns('10.0.0.1')
+ scope.stubs(:lookupvar).with("ipaddress_lo").returns('127.0.0.1')
+ scope.stubs(:lookupvar).with("ipaddress_eth0").returns('10.0.0.1')
+ scope.stubs(:lookupvar).with('muppet').returns('kermit')
+ scope.stubs(:lookupvar).with('muppet_lo').returns('mspiggy')
+ scope.stubs(:lookupvar).with('muppet_eth0').returns('kermit')
+ end
+ it 'should have loopback (lo)' do
+ subject.call(['lo']).should be_true
+ end
+ it 'should not have loopback (lo0)' do
+ subject.call(['lo0']).should be_false
+ end
+ it 'should have ipaddress with 127.0.0.1' do
+ subject.call(['ipaddress', '127.0.0.1']).should be_true
+ end
+ it 'should have ipaddress with 10.0.0.1' do
+ subject.call(['ipaddress', '10.0.0.1']).should be_true
+ end
+ it 'should not have ipaddress with 10.0.0.2' do
+ subject.call(['ipaddress', '10.0.0.2']).should be_false
+ end
+ it 'should have muppet named kermit' do
+ subject.call(['muppet', 'kermit']).should be_true
+ end
+ it 'should have muppet named mspiggy' do
+ subject.call(['muppet', 'mspiggy']).should be_true
+ end
+ it 'should not have muppet named bigbird' do
+ subject.call(['muppet', 'bigbird']).should be_false
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb
new file mode 100755
index 0000000..5a68460
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb
@@ -0,0 +1,39 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:has_ip_address) do
+
+ let(:scope) do
+ PuppetlabsSpec::PuppetInternals.scope
+ end
+
+ subject do
+ function_name = Puppet::Parser::Functions.function(:has_ip_address)
+ scope.method(function_name)
+ end
+
+ context "On Linux Systems" do
+ before :each do
+ scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo')
+ scope.stubs(:lookupvar).with('ipaddress').returns('10.0.2.15')
+ scope.stubs(:lookupvar).with('ipaddress_eth0').returns('10.0.2.15')
+ scope.stubs(:lookupvar).with('ipaddress_lo').returns('127.0.0.1')
+ end
+
+ it 'should have primary address (10.0.2.15)' do
+ subject.call(['10.0.2.15']).should be_true
+ end
+
+ it 'should have lookupback address (127.0.0.1)' do
+ subject.call(['127.0.0.1']).should be_true
+ end
+
+ it 'should not have other address' do
+ subject.call(['192.1681.1.1']).should be_false
+ end
+
+ it 'should not have "mspiggy" on an interface' do
+ subject.call(['mspiggy']).should be_false
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb
new file mode 100755
index 0000000..c3a289e
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:has_ip_network) do
+
+ let(:scope) do
+ PuppetlabsSpec::PuppetInternals.scope
+ end
+
+ subject do
+ function_name = Puppet::Parser::Functions.function(:has_ip_network)
+ scope.method(function_name)
+ end
+
+ context "On Linux Systems" do
+ before :each do
+ scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo')
+ scope.stubs(:lookupvar).with('network').returns(:undefined)
+ scope.stubs(:lookupvar).with('network_eth0').returns('10.0.2.0')
+ scope.stubs(:lookupvar).with('network_lo').returns('127.0.0.1')
+ end
+
+ it 'should have primary network (10.0.2.0)' do
+ subject.call(['10.0.2.0']).should be_true
+ end
+
+ it 'should have loopback network (127.0.0.0)' do
+ subject.call(['127.0.0.1']).should be_true
+ end
+
+ it 'should not have other network' do
+ subject.call(['192.168.1.0']).should be_false
+ end
+ end
+end
+
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb
new file mode 100644
index 0000000..490daea
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb
@@ -0,0 +1,42 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:has_key) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'when calling has_key from puppet' do
+ it "should not compile when no arguments are passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = '$x = has_key()'
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should not compile when 1 argument is passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = "$x = has_key('foo')"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should require the first value to be a Hash" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = "$x = has_key('foo', 'bar')"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /expects the first argument to be a hash/)
+ end
+ end
+
+ describe 'when calling the function has_key from a scope instance' do
+ it 'should detect existing keys' do
+ scope.function_has_key([{'one' => 1}, 'one']).should be_true
+ end
+
+ it 'should detect existing keys' do
+ scope.function_has_key([{'one' => 1}, 'two']).should be_false
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb
new file mode 100644
index 0000000..7c91be9
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the hash function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("hash").should == "function_hash"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_hash([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert an array to a hash" do
+ result = scope.function_hash([['a',1,'b',2,'c',3]])
+ result.should(eq({'a'=>1,'b'=>2,'c'=>3}))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb
new file mode 100644
index 0000000..e7f4bcd
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_array function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_array").should == "function_is_array"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_array([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if passed an array" do
+ result = scope.function_is_array([[1,2,3]])
+ result.should(eq(true))
+ end
+
+ it "should return false if passed a hash" do
+ result = scope.function_is_array([{'a'=>1}])
+ result.should(eq(false))
+ end
+
+ it "should return false if passed a string" do
+ result = scope.function_is_array(["asdf"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb
new file mode 100644
index 0000000..f2ea76d
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb
@@ -0,0 +1,64 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_domain_name function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_domain_name").should == "function_is_domain_name"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a valid short domain name" do
+ result = scope.function_is_domain_name(["x.com"])
+ result.should(be_true)
+ end
+
+ it "should return true if the domain is ." do
+ result = scope.function_is_domain_name(["."])
+ result.should(be_true)
+ end
+
+ it "should return true if the domain is x.com." do
+ result = scope.function_is_domain_name(["x.com."])
+ result.should(be_true)
+ end
+
+ it "should return true if a valid domain name" do
+ result = scope.function_is_domain_name(["foo.bar.com"])
+ result.should(be_true)
+ end
+
+ it "should allow domain parts to start with numbers" do
+ result = scope.function_is_domain_name(["3foo.2bar.com"])
+ result.should(be_true)
+ end
+
+ it "should allow domain to end with a dot" do
+ result = scope.function_is_domain_name(["3foo.2bar.com."])
+ result.should(be_true)
+ end
+
+ it "should allow a single part domain" do
+ result = scope.function_is_domain_name(["orange"])
+ result.should(be_true)
+ end
+
+ it "should return false if domain parts start with hyphens" do
+ result = scope.function_is_domain_name(["-3foo.2bar.com"])
+ result.should(be_false)
+ end
+
+ it "should return true if domain contains hyphens" do
+ result = scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"])
+ result.should(be_true)
+ end
+
+ it "should return false if domain name contains spaces" do
+ result = scope.function_is_domain_name(["not valid"])
+ result.should(be_false)
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb
new file mode 100644
index 0000000..b7d73b0
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_float function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_float").should == "function_is_float"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_float([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a float" do
+ result = scope.function_is_float(["0.12"])
+ result.should(eq(true))
+ end
+
+ it "should return false if a string" do
+ result = scope.function_is_float(["asdf"])
+ result.should(eq(false))
+ end
+
+ it "should return false if an integer" do
+ result = scope.function_is_float(["3"])
+ result.should(eq(false))
+ end
+ it "should return true if a float is created from an arithmetical operation" do
+ result = scope.function_is_float([3.2*2])
+ result.should(eq(true))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb
new file mode 100644
index 0000000..bd40c51
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+describe "the is_function_available function" do
+ before :all do
+ Puppet::Parser::Functions.autoloader.loadall
+ end
+
+ before :each do
+ @scope = Puppet::Parser::Scope.new
+ end
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_function_available").should == "function_is_function_available"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { @scope.function_is_function_available([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return false if a nonexistent function is passed" do
+ result = @scope.function_is_function_available(['jeff_mccunes_left_sock'])
+ result.should(eq(false))
+ end
+
+ it "should return true if an available function is passed" do
+ result = @scope.function_is_function_available(['require'])
+ result.should(eq(true))
+ end
+
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb
new file mode 100644
index 0000000..bbebf39
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_hash function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_hash").should == "function_is_hash"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if passed a hash" do
+ result = scope.function_is_hash([{"a"=>1,"b"=>2}])
+ result.should(eq(true))
+ end
+
+ it "should return false if passed an array" do
+ result = scope.function_is_hash([["a","b"]])
+ result.should(eq(false))
+ end
+
+ it "should return false if passed a string" do
+ result = scope.function_is_hash(["asdf"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb
new file mode 100644
index 0000000..4335795
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_integer function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_integer").should == "function_is_integer"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if an integer" do
+ result = scope.function_is_integer(["3"])
+ result.should(eq(true))
+ end
+
+ it "should return false if a float" do
+ result = scope.function_is_integer(["3.2"])
+ result.should(eq(false))
+ end
+
+ it "should return false if a string" do
+ result = scope.function_is_integer(["asdf"])
+ result.should(eq(false))
+ end
+
+ it "should return true if an integer is created from an arithmetical operation" do
+ result = scope.function_is_integer([3*2])
+ result.should(eq(true))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb
new file mode 100644
index 0000000..c0debb3
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_ip_address function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_ip_address").should == "function_is_ip_address"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if an IPv4 address" do
+ result = scope.function_is_ip_address(["1.2.3.4"])
+ result.should(eq(true))
+ end
+
+ it "should return true if a full IPv6 address" do
+ result = scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"])
+ result.should(eq(true))
+ end
+
+ it "should return true if a compressed IPv6 address" do
+ result = scope.function_is_ip_address(["fe00::1"])
+ result.should(eq(true))
+ end
+
+ it "should return false if not valid" do
+ result = scope.function_is_ip_address(["asdf"])
+ result.should(eq(false))
+ end
+
+ it "should return false if IP octets out of range" do
+ result = scope.function_is_ip_address(["1.1.1.300"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb
new file mode 100644
index 0000000..ca9c590
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_mac_address function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_mac_address").should == "function_is_mac_address"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a valid mac address" do
+ result = scope.function_is_mac_address(["00:a0:1f:12:7f:a0"])
+ result.should(eq(true))
+ end
+
+ it "should return false if octets are out of range" do
+ result = scope.function_is_mac_address(["00:a0:1f:12:7f:g0"])
+ result.should(eq(false))
+ end
+
+ it "should return false if not valid" do
+ result = scope.function_is_mac_address(["not valid"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb
new file mode 100644
index 0000000..d7440fb
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_numeric function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_numeric").should == "function_is_numeric"
+ end
+
+ it "should raise a ParseError if there is less than 1 argument" do
+ lambda { scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if an integer" do
+ result = scope.function_is_numeric(["3"])
+ result.should(eq(true))
+ end
+
+ it "should return true if a float" do
+ result = scope.function_is_numeric(["3.2"])
+ result.should(eq(true))
+ end
+
+ it "should return true if an integer is created from an arithmetical operation" do
+ result = scope.function_is_numeric([3*2])
+ result.should(eq(true))
+ end
+
+ it "should return true if a float is created from an arithmetical operation" do
+ result = scope.function_is_numeric([3.2*2])
+ result.should(eq(true))
+ end
+
+ it "should return false if a string" do
+ result = scope.function_is_numeric(["asdf"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb
new file mode 100644
index 0000000..3756bea
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the is_string function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("is_string").should == "function_is_string"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_is_string([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a string" do
+ result = scope.function_is_string(["asdf"])
+ result.should(eq(true))
+ end
+
+ it "should return false if an integer" do
+ result = scope.function_is_string(["3"])
+ result.should(eq(false))
+ end
+
+ it "should return false if a float" do
+ result = scope.function_is_string(["3.23"])
+ result.should(eq(false))
+ end
+
+ it "should return false if an array" do
+ result = scope.function_is_string([["a","b","c"]])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb
new file mode 100644
index 0000000..a52fb71
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb
@@ -0,0 +1,40 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the join_keys_to_values function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("join_keys_to_values").should == "function_join_keys_to_values"
+ end
+
+ it "should raise a ParseError if there are fewer than two arguments" do
+ lambda { scope.function_join_keys_to_values([{}]) }.should raise_error Puppet::ParseError
+ end
+
+ it "should raise a ParseError if there are greater than two arguments" do
+ lambda { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.should raise_error Puppet::ParseError
+ end
+
+ it "should raise a TypeError if the first argument is an array" do
+ lambda { scope.function_join_keys_to_values([[1,2], ',']) }.should raise_error TypeError
+ end
+
+ it "should raise a TypeError if the second argument is an array" do
+ lambda { scope.function_join_keys_to_values([{}, [1,2]]) }.should raise_error TypeError
+ end
+
+ it "should raise a TypeError if the second argument is a number" do
+ lambda { scope.function_join_keys_to_values([{}, 1]) }.should raise_error TypeError
+ end
+
+ it "should return an empty array given an empty hash" do
+ result = scope.function_join_keys_to_values([{}, ":"])
+ result.should == []
+ end
+
+ it "should join hash's keys to its values" do
+ result = scope.function_join_keys_to_values([{'a'=>1,2=>'foo',:b=>nil}, ":"])
+ result.should =~ ['a:1','2:foo','b:']
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb
new file mode 100644
index 0000000..aafa1a7
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the join function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("join").should == "function_join"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_join([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should join an array into a string" do
+ result = scope.function_join([["a","b","c"], ":"])
+ result.should(eq("a:b:c"))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb
new file mode 100644
index 0000000..fdd7a70
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb
@@ -0,0 +1,21 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the keys function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("keys").should == "function_keys"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_keys([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return an array of keys when given a hash" do
+ result = scope.function_keys([{'a'=>1, 'b'=>2}])
+ # =~ performs 'array with same elements' (set) matching
+ # For more info see RSpec::Matchers::MatchArray
+ result.should =~ ['a','b']
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb
new file mode 100644
index 0000000..b280ae7
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the lstrip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("lstrip").should == "function_lstrip"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should lstrip a string" do
+ result = scope.function_lstrip([" asdf"])
+ result.should(eq('asdf'))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb
new file mode 100755
index 0000000..ff6f2b3
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the max function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("max").should == "function_max"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_max([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should be able to compare strings" do
+ scope.function_max(["albatross","dog","horse"]).should(eq("horse"))
+ end
+
+ it "should be able to compare numbers" do
+ scope.function_max([6,8,4]).should(eq(8))
+ end
+
+ it "should be able to compare a number with a stringified number" do
+ scope.function_max([1,"2"]).should(eq("2"))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb
new file mode 100644
index 0000000..6e9a023
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the member function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("member").should == "function_member"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_member([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if a member is in an array" do
+ result = scope.function_member([["a","b","c"], "a"])
+ result.should(eq(true))
+ end
+
+ it "should return false if a member is not in an array" do
+ result = scope.function_member([["a","b","c"], "d"])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb
new file mode 100644
index 0000000..04169e7
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb
@@ -0,0 +1,47 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:merge) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'when calling merge from puppet' do
+ it "should not compile when no arguments are passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = '$x = merge()'
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should not compile when 1 argument is passed" do
+ pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./
+ Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)"
+ expect {
+ scope.compiler.compile
+ }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+ end
+
+ describe 'when calling merge on the scope instance' do
+ it 'should require all parameters are hashes' do
+ expect { new_hash = scope.function_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/)
+ end
+
+ it 'should be able to merge two hashes' do
+ new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}])
+ new_hash['one'].should == '1'
+ new_hash['two'].should == '2'
+ new_hash['three'].should == '2'
+ end
+
+ it 'should merge multiple hashes' do
+ hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}])
+ hash['one'].should == '3'
+ end
+
+ it 'should accept empty hashes' do
+ scope.function_merge([{},{},{}]).should == {}
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb
new file mode 100755
index 0000000..71d593e
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb
@@ -0,0 +1,27 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the min function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("min").should == "function_min"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_min([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should be able to compare strings" do
+ scope.function_min(["albatross","dog","horse"]).should(eq("albatross"))
+ end
+
+ it "should be able to compare numbers" do
+ scope.function_min([6,8,4]).should(eq(4))
+ end
+
+ it "should be able to compare a number with a stringified number" do
+ scope.function_min([1,"2"]).should(eq(1))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb
new file mode 100644
index 0000000..b56196d
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb
@@ -0,0 +1,67 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the num2bool function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("num2bool").should == "function_num2bool"
+ end
+
+ it "should raise a ParseError if there are no arguments" do
+ lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there are more than 1 arguments" do
+ lambda { scope.function_num2bool(["foo","bar"]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if passed something non-numeric" do
+ lambda { scope.function_num2bool(["xyzzy"]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return true if passed string 1" do
+ result = scope.function_num2bool(["1"])
+ result.should(be_true)
+ end
+
+ it "should return true if passed string 1.5" do
+ result = scope.function_num2bool(["1.5"])
+ result.should(be_true)
+ end
+
+ it "should return true if passed number 1" do
+ result = scope.function_num2bool([1])
+ result.should(be_true)
+ end
+
+ it "should return false if passed string 0" do
+ result = scope.function_num2bool(["0"])
+ result.should(be_false)
+ end
+
+ it "should return false if passed number 0" do
+ result = scope.function_num2bool([0])
+ result.should(be_false)
+ end
+
+ it "should return false if passed string -1" do
+ result = scope.function_num2bool(["-1"])
+ result.should(be_false)
+ end
+
+ it "should return false if passed string -1.5" do
+ result = scope.function_num2bool(["-1.5"])
+ result.should(be_false)
+ end
+
+ it "should return false if passed number -1" do
+ result = scope.function_num2bool([-1])
+ result.should(be_false)
+ end
+
+ it "should return false if passed float -1.5" do
+ result = scope.function_num2bool([-1.5])
+ result.should(be_false)
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb
new file mode 100644
index 0000000..f179ac1
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb
@@ -0,0 +1,22 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the parsejson function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("parsejson").should == "function_parsejson"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert JSON to a data structure" do
+ json = <<-EOS
+["aaa","bbb","ccc"]
+EOS
+ result = scope.function_parsejson([json])
+ result.should(eq(['aaa','bbb','ccc']))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb
new file mode 100644
index 0000000..0c7aea8
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the parseyaml function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert YAML to a data structure" do
+ yaml = <<-EOS
+- aaa
+- bbb
+- ccc
+EOS
+ result = scope.function_parseyaml([yaml])
+ result.should(eq(['aaa','bbb','ccc']))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb
new file mode 100644
index 0000000..761db6b
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the pick function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("pick").should == "function_pick"
+ end
+
+ it 'should return the correct value' do
+ scope.function_pick(['first', 'second']).should == 'first'
+ end
+
+ it 'should return the correct value if the first value is empty' do
+ scope.function_pick(['', 'second']).should == 'second'
+ end
+
+ it 'should remove empty string values' do
+ scope.function_pick(['', 'first']).should == 'first'
+ end
+
+ it 'should remove :undef values' do
+ scope.function_pick([:undef, 'first']).should == 'first'
+ end
+
+ it 'should remove :undefined values' do
+ scope.function_pick([:undefined, 'first']).should == 'first'
+ end
+
+ it 'should error if no values are passed' do
+ expect { scope.function_pick([]) }.to raise_error(Puppet::Error, /Must provide non empty value./)
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb
new file mode 100644
index 0000000..5cf592b
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the prefix function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("prefix").should == "function_prefix"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_prefix([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a prefixed array" do
+ result = scope.function_prefix([['a','b','c'], 'p'])
+ result.should(eq(['pa','pb','pc']))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb
new file mode 100644
index 0000000..42751f4
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb
@@ -0,0 +1,34 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the range function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("range").should == "function_range"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_range([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a letter range" do
+ result = scope.function_range(["a","d"])
+ result.should(eq(['a','b','c','d']))
+ end
+
+ it "should return a number range" do
+ result = scope.function_range(["1","4"])
+ result.should(eq([1,2,3,4]))
+ end
+
+ it "should work with padded hostname like strings" do
+ expected = ("host01".."host10").to_a
+ scope.function_range(["host01","host10"]).should eq expected
+ end
+
+ it "should coerce zero padded digits to integers" do
+ expected = (0..10).to_a
+ scope.function_range(["00", "10"]).should eq expected
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb
new file mode 100755
index 0000000..f2cb741
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb
@@ -0,0 +1,20 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+
+describe "the reject function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("reject").should == "function_reject"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_reject([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should reject contents from an array" do
+ result = scope.function_reject([["1111", "aaabbb","bbbccc","dddeee"], "bbb"])
+ result.should(eq(["1111", "dddeee"]))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb
new file mode 100644
index 0000000..1b59206
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the reverse function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("reverse").should == "function_reverse"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_reverse([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should reverse a string" do
+ result = scope.function_reverse(["asdfghijkl"])
+ result.should(eq('lkjihgfdsa'))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb
new file mode 100644
index 0000000..d90de1d
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the rstrip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("rstrip").should == "function_rstrip"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_rstrip([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should rstrip a string" do
+ result = scope.function_rstrip(["asdf "])
+ result.should(eq('asdf'))
+ end
+
+ it "should rstrip each element in an array" do
+ result = scope.function_rstrip([["a ","b ", "c "]])
+ result.should(eq(['a','b','c']))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb
new file mode 100644
index 0000000..93346d5
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the shuffle function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("shuffle").should == "function_shuffle"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_shuffle([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should shuffle a string and the result should be the same size" do
+ result = scope.function_shuffle(["asdf"])
+ result.size.should(eq(4))
+ end
+
+ it "should shuffle a string but the sorted contents should still be the same" do
+ result = scope.function_shuffle(["adfs"])
+ result.split("").sort.join("").should(eq("adfs"))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb
new file mode 100644
index 0000000..b1c435a
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the size function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("size").should == "function_size"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_size([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return the size of a string" do
+ result = scope.function_size(["asdf"])
+ result.should(eq(4))
+ end
+
+ it "should return the size of an array" do
+ result = scope.function_size([["a","b","c"]])
+ result.should(eq(3))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb
new file mode 100644
index 0000000..3187a5a
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the sort function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("sort").should == "function_sort"
+ end
+
+ it "should raise a ParseError if there is not 1 arguments" do
+ lambda { scope.function_sort(['','']) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should sort an array" do
+ result = scope.function_sort([["a","c","b"]])
+ result.should(eq(['a','b','c']))
+ end
+
+ it "should sort a string" do
+ result = scope.function_sort(["acb"])
+ result.should(eq('abc'))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb
new file mode 100644
index 0000000..60e5a30
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the squeeze function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("squeeze").should == "function_squeeze"
+ end
+
+ it "should raise a ParseError if there is less than 2 arguments" do
+ lambda { scope.function_squeeze([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should squeeze a string" do
+ result = scope.function_squeeze(["aaabbbbcccc"])
+ result.should(eq('abc'))
+ end
+
+ it "should squeeze all elements in an array" do
+ result = scope.function_squeeze([["aaabbbbcccc","dddfff"]])
+ result.should(eq(['abc','df']))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb
new file mode 100644
index 0000000..ef6350f
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the str2bool function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("str2bool").should == "function_str2bool"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_str2bool([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert string 'true' to true" do
+ result = scope.function_str2bool(["true"])
+ result.should(eq(true))
+ end
+
+ it "should convert string 'undef' to false" do
+ result = scope.function_str2bool(["undef"])
+ result.should(eq(false))
+ end
+
+ it "should return the boolean it was called with" do
+ result = scope.function_str2bool([true])
+ result.should(eq(true))
+ result = scope.function_str2bool([false])
+ result.should(eq(false))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb
new file mode 100644
index 0000000..df8fb8e
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb
@@ -0,0 +1,45 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the str2saltedsha512 function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("str2saltedsha512").should == "function_str2saltedsha512"
+ end
+
+ it "should raise a ParseError if there is less than 1 argument" do
+ expect { scope.function_str2saltedsha512([]) }.to( raise_error(Puppet::ParseError) )
+ end
+
+ it "should raise a ParseError if there is more than 1 argument" do
+ expect { scope.function_str2saltedsha512(['foo', 'bar', 'baz']) }.to( raise_error(Puppet::ParseError) )
+ end
+
+ it "should return a salted-sha512 password hash 136 characters in length" do
+ result = scope.function_str2saltedsha512(["password"])
+ result.length.should(eq(136))
+ end
+
+ it "should raise an error if you pass a non-string password" do
+ expect { scope.function_str2saltedsha512([1234]) }.to( raise_error(Puppet::ParseError) )
+ end
+
+ it "should generate a valid password" do
+ # Allow the function to generate a password based on the string 'password'
+ password_hash = scope.function_str2saltedsha512(["password"])
+
+ # Separate the Salt and Password from the Password Hash
+ salt = password_hash[0..7]
+ password = password_hash[8..-1]
+
+ # Convert the Salt and Password from Hex to Binary Data
+ str_salt = Array(salt.lines).pack('H*')
+ str_password = Array(password.lines).pack('H*')
+
+ # Combine the Binary Salt with 'password' and compare the end result
+ saltedpass = Digest::SHA512.digest(str_salt + 'password')
+ result = (str_salt + saltedpass).unpack('H*')[0]
+ result.should == password_hash
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb
new file mode 100644
index 0000000..df42b6f
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the strftime function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("strftime").should == "function_strftime"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_strftime([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "using %s should be higher then when I wrote this test" do
+ result = scope.function_strftime(["%s"])
+ result.to_i.should(be > 1311953157)
+ end
+
+ it "using %s should be lower then 1.5 trillion" do
+ result = scope.function_strftime(["%s"])
+ result.to_i.should(be < 1500000000)
+ end
+
+ it "should return a date when given %Y-%m-%d" do
+ result = scope.function_strftime(["%Y-%m-%d"])
+ result.should =~ /^\d{4}-\d{2}-\d{2}$/
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb
new file mode 100644
index 0000000..fccdd26
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb
@@ -0,0 +1,18 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the strip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should exist" do
+ Puppet::Parser::Functions.function("strip").should == "function_strip"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_strip([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should strip a string" do
+ result = scope.function_strip([" ab cd "])
+ result.should(eq('ab cd'))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb
new file mode 100644
index 0000000..c28f719
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the suffix function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("suffix").should == "function_suffix"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_suffix([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a suffixed array" do
+ result = scope.function_suffix([['a','b','c'], 'p'])
+ result.should(eq(['ap','bp','cp']))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb
new file mode 100644
index 0000000..808b415
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb
@@ -0,0 +1,19 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the swapcase function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("swapcase").should == "function_swapcase"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_swapcase([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should swapcase a string" do
+ result = scope.function_swapcase(["aaBBccDD"])
+ result.should(eq('AAbbCCdd'))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb
new file mode 100644
index 0000000..e9fb76e
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb
@@ -0,0 +1,29 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the time function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("time").should == "function_time"
+ end
+
+ it "should raise a ParseError if there is more than 2 arguments" do
+ lambda { scope.function_time(['','']) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a number" do
+ result = scope.function_time([])
+ result.should be_an(Integer)
+ end
+
+ it "should be higher then when I wrote this test" do
+ result = scope.function_time([])
+ result.should(be > 1311953157)
+ end
+
+ it "should be lower then 1.5 trillion" do
+ result = scope.function_time([])
+ result.should(be < 1500000000)
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
new file mode 100755
index 0000000..d1ea4c8
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb
@@ -0,0 +1,58 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the to_bytes function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("to_bytes").should == "function_to_bytes"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_to_bytes([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should convert kB to B" do
+ result = scope.function_to_bytes(["4 kB"])
+ result.should(eq(4096))
+ end
+
+ it "should work without B in unit" do
+ result = scope.function_to_bytes(["4 k"])
+ result.should(eq(4096))
+ end
+
+ it "should work without a space before unit" do
+ result = scope.function_to_bytes(["4k"])
+ result.should(eq(4096))
+ end
+
+ it "should work without a unit" do
+ result = scope.function_to_bytes(["5678"])
+ result.should(eq(5678))
+ end
+
+ it "should convert fractions" do
+ result = scope.function_to_bytes(["1.5 kB"])
+ result.should(eq(1536))
+ end
+
+ it "should convert scientific notation" do
+ result = scope.function_to_bytes(["1.5e2 B"])
+ result.should(eq(150))
+ end
+
+ it "should do nothing with a positive number" do
+ result = scope.function_to_bytes([5678])
+ result.should(eq(5678))
+ end
+
+ it "should should raise a ParseError if input isn't a number" do
+ lambda { scope.function_to_bytes(["foo"]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should should raise a ParseError if prefix is unknown" do
+ lambda { scope.function_to_bytes(["5 uB"]) }.should( raise_error(Puppet::ParseError))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb
new file mode 100644
index 0000000..8fec88f
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb
@@ -0,0 +1,43 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the type function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ it "should exist" do
+ Puppet::Parser::Functions.function("type").should == "function_type"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_type([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return string when given a string" do
+ result = scope.function_type(["aaabbbbcccc"])
+ result.should(eq('string'))
+ end
+
+ it "should return array when given an array" do
+ result = scope.function_type([["aaabbbbcccc","asdf"]])
+ result.should(eq('array'))
+ end
+
+ it "should return hash when given a hash" do
+ result = scope.function_type([{"a"=>1,"b"=>2}])
+ result.should(eq('hash'))
+ end
+
+ it "should return integer when given an integer" do
+ result = scope.function_type(["1"])
+ result.should(eq('integer'))
+ end
+
+ it "should return float when given a float" do
+ result = scope.function_type(["1.34"])
+ result.should(eq('float'))
+ end
+
+ it "should return boolean when given a boolean" do
+ result = scope.function_type([true])
+ result.should(eq('boolean'))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb
new file mode 100644
index 0000000..5d48d49
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the unique function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("unique").should == "function_unique"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_unique([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should remove duplicate elements in a string" do
+ result = scope.function_unique(["aabbc"])
+ result.should(eq('abc'))
+ end
+
+ it "should remove duplicate elements in an array" do
+ result = scope.function_unique([["a","a","b","b","c"]])
+ result.should(eq(['a','b','c']))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb
new file mode 100644
index 0000000..5db5513
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the upcase function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("upcase").should == "function_upcase"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_upcase([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should upcase a string" do
+ result = scope.function_upcase(["abc"])
+ result.should(eq('ABC'))
+ end
+
+ it "should do nothing if a string is already upcase" do
+ result = scope.function_upcase(["ABC"])
+ result.should(eq('ABC'))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb
new file mode 100644
index 0000000..371de46
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb
@@ -0,0 +1,24 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the uriescape function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("uriescape").should == "function_uriescape"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_uriescape([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should uriescape a string" do
+ result = scope.function_uriescape([":/?#[]@!$&'()*+,;= "])
+ result.should(eq('%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%20'))
+ end
+
+ it "should do nothing if a string is already safe" do
+ result = scope.function_uriescape(["ABCdef"])
+ result.should(eq('ABCdef'))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb
new file mode 100644
index 0000000..08aaf78
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb
@@ -0,0 +1,83 @@
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_absolute_path) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ # The subject of these examples is the method itself.
+ subject do
+ # This makes sure the function is loaded within each test
+ function_name = Puppet::Parser::Functions.function(:validate_absolute_path)
+ scope.method(function_name)
+ end
+
+ describe "Valid Paths" do
+ def self.valid_paths
+ %w{
+ C:/
+ C:\\
+ C:\\WINDOWS\\System32
+ C:/windows/system32
+ X:/foo/bar
+ X:\\foo\\bar
+ /var/tmp
+ /var/lib/puppet
+ /var/opt/../lib/puppet
+ }
+ end
+
+ context "Without Puppet::Util.absolute_path? (e.g. Puppet <= 2.6)" do
+ before :each do
+ # The intent here is to mock Puppet to behave like Puppet 2.6 does.
+ # Puppet 2.6 does not have the absolute_path? method. This is only a
+ # convenience test, stdlib should be run with the Puppet 2.6.x in the
+ # $LOAD_PATH in addition to 2.7.x and master.
+ Puppet::Util.expects(:respond_to?).with(:absolute_path?).returns(false)
+ end
+ valid_paths.each do |path|
+ it "validate_absolute_path(#{path.inspect}) should not fail" do
+ expect { subject.call [path] }.not_to raise_error Puppet::ParseError
+ end
+ end
+ end
+
+ context "Puppet without mocking" do
+ valid_paths.each do |path|
+ it "validate_absolute_path(#{path.inspect}) should not fail" do
+ expect { subject.call [path] }.not_to raise_error Puppet::ParseError
+ end
+ end
+ end
+ end
+
+ describe 'Invalid paths' do
+ context 'Garbage inputs' do
+ [
+ nil,
+ [ nil ],
+ { 'foo' => 'bar' },
+ { },
+ '',
+ ].each do |path|
+ it "validate_absolute_path(#{path.inspect}) should fail" do
+ expect { subject.call [path] }.to raise_error Puppet::ParseError
+ end
+ end
+ end
+
+ context 'Relative paths' do
+ %w{
+ relative1
+ .
+ ..
+ ./foo
+ ../foo
+ etc/puppetlabs/puppet
+ opt/puppet/bin
+ }.each do |path|
+ it "validate_absolute_path(#{path.inspect}) should fail" do
+ expect { subject.call [path] }.to raise_error Puppet::ParseError
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb
new file mode 100644
index 0000000..4b31cfd
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb
@@ -0,0 +1,38 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_array) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ describe 'when calling validate_array from puppet' do
+
+ %w{ true false }.each do |the_string|
+ it "should not compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_array('#{the_string}')"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
+ end
+
+ it "should not compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_array(#{the_string})"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
+ end
+ end
+
+ it "should compile when multiple array arguments are passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = [ ]
+ $bar = [ 'one', 'two' ]
+ validate_array($foo, $bar)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+
+ it "should not compile when an undef variable is passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = undef
+ validate_array($foo)
+ ENDofPUPPETcode
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/)
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb
new file mode 100644
index 0000000..ab5c140
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb
@@ -0,0 +1,102 @@
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_augeas), :if => Puppet.features.augeas? do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ # The subject of these examplres is the method itself.
+ subject do
+ # This makes sure the function is loaded within each test
+ function_name = Puppet::Parser::Functions.function(:validate_augeas)
+ scope.method(function_name)
+ end
+
+ context 'Using Puppet::Parser::Scope.new' do
+
+ describe 'Garbage inputs' do
+ inputs = [
+ [ nil ],
+ [ [ nil ] ],
+ [ { 'foo' => 'bar' } ],
+ [ { } ],
+ [ '' ],
+ [ "one", "one", "MSG to User", "4th arg" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should fail" do
+ expect { subject.call [input] }.to raise_error Puppet::ParseError
+ end
+ end
+ end
+
+ describe 'Valid inputs' do
+ inputs = [
+ [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns' ],
+ [ "proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should not fail" do
+ expect { subject.call input }.not_to raise_error
+ end
+ end
+ end
+
+ describe "Valid inputs which should raise an exception without a message" do
+ # The intent here is to make sure valid inputs raise exceptions when they
+ # don't specify an error message to display. This is the behvior in
+ # 2.2.x and prior.
+ inputs = [
+ [ "root:x:0:0:root\n", 'Passwd.lns' ],
+ [ "127.0.1.1\n", 'Hosts.lns' ],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /validate_augeas.*?matched less than it should/
+ end
+ end
+ end
+
+ describe "Nicer Error Messages" do
+ # The intent here is to make sure the function returns the 3rd argument
+ # in the exception thrown
+ inputs = [
+ [ "root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content' ],
+ [ "127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content' ],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /#{input[2]}/
+ end
+ end
+ end
+
+ describe "Passing simple unit tests" do
+ inputs = [
+ [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
+ [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should fail" do
+ expect { subject.call input }.not_to raise_error
+ end
+ end
+ end
+
+ describe "Failing simple unit tests" do
+ inputs = [
+ [ "foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
+ [ "root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
+ ]
+
+ inputs.each do |input|
+ it "validate_augeas(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /testing path/
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb
new file mode 100644
index 0000000..261fb23
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb
@@ -0,0 +1,51 @@
+#! /usr/bin/env/ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_bool) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+ describe 'when calling validate_bool from puppet' do
+
+ %w{ true false }.each do |the_string|
+
+ it "should not compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_bool('#{the_string}')"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
+ end
+
+ it "should compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_bool(#{the_string})"
+ scope.compiler.compile
+ end
+
+ end
+
+ it "should not compile when an arbitrary string is passed" do
+ Puppet[:code] = 'validate_bool("jeff and dan are awesome")'
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
+ end
+
+ it "should not compile when no arguments are passed" do
+ Puppet[:code] = 'validate_bool()'
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /wrong number of arguments/)
+ end
+
+ it "should compile when multiple boolean arguments are passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = true
+ $bar = false
+ validate_bool($foo, $bar, true, false)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+
+ it "should compile when multiple boolean arguments are passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = true
+ $bar = false
+ validate_bool($foo, $bar, true, false, 'jeff')
+ ENDofPUPPETcode
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/)
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb
new file mode 100644
index 0000000..69ea7f4
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb
@@ -0,0 +1,81 @@
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_cmd) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ # The subject of these examplres is the method itself.
+ subject do
+ # This makes sure the function is loaded within each test
+ function_name = Puppet::Parser::Functions.function(:validate_cmd)
+ scope.method(function_name)
+ end
+
+ context 'Using Puppet::Parser::Scope.new' do
+
+ describe 'Garbage inputs' do
+ inputs = [
+ [ nil ],
+ [ [ nil ] ],
+ [ { 'foo' => 'bar' } ],
+ [ { } ],
+ [ '' ],
+ [ "one", "one", "MSG to User", "4th arg" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_cmd(#{input.inspect}) should fail" do
+ expect { subject.call [input] }.to raise_error Puppet::ParseError
+ end
+ end
+ end
+
+ describe 'Valid inputs' do
+ inputs = [
+ [ '/full/path/to/something', '/bin/echo' ],
+ [ '/full/path/to/something', '/bin/cat' ],
+ ]
+
+ inputs.each do |input|
+ it "validate_cmd(#{input.inspect}) should not fail" do
+ expect { subject.call input }.not_to raise_error
+ end
+ end
+ end
+
+ describe "Valid inputs which should raise an exception without a message" do
+ # The intent here is to make sure valid inputs raise exceptions when they
+ # don't specify an error message to display. This is the behvior in
+ # 2.2.x and prior.
+ inputs = [
+ [ "hello", "/bin/false" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_cmd(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /validate_cmd.*?failed to validate content with command/
+ end
+ end
+ end
+
+ describe "Nicer Error Messages" do
+ # The intent here is to make sure the function returns the 3rd argument
+ # in the exception thrown
+ inputs = [
+ [ "hello", [ "bye", "later", "adios" ], "MSG to User" ],
+ [ "greetings", "salutations", "Error, greetings does not match salutations" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_cmd(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /#{input[2]}/
+ end
+ end
+ end
+
+ describe "Test output message" do
+ it "validate_cmd('whatever', 'kthnksbye') should fail" do
+ expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.* returned 1/
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb
new file mode 100644
index 0000000..a0c35c2
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb
@@ -0,0 +1,43 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_hash) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'when calling validate_hash from puppet' do
+
+ %w{ true false }.each do |the_string|
+
+ it "should not compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_hash('#{the_string}')"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
+ end
+
+ it "should not compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_hash(#{the_string})"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
+ end
+
+ end
+
+ it "should compile when multiple hash arguments are passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = {}
+ $bar = { 'one' => 'two' }
+ validate_hash($foo, $bar)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+
+ it "should not compile when an undef variable is passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = undef
+ validate_hash($foo)
+ ENDofPUPPETcode
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/)
+ end
+
+ end
+
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb
new file mode 100644
index 0000000..d189efb
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb
@@ -0,0 +1,76 @@
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_re) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ # The subject of these examplres is the method itself.
+ subject do
+ # This makes sure the function is loaded within each test
+ function_name = Puppet::Parser::Functions.function(:validate_re)
+ scope.method(function_name)
+ end
+
+ context 'Using Puppet::Parser::Scope.new' do
+
+ describe 'Garbage inputs' do
+ inputs = [
+ [ nil ],
+ [ [ nil ] ],
+ [ { 'foo' => 'bar' } ],
+ [ { } ],
+ [ '' ],
+ [ "one", "one", "MSG to User", "4th arg" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_re(#{input.inspect}) should fail" do
+ expect { subject.call [input] }.to raise_error Puppet::ParseError
+ end
+ end
+ end
+
+ describe 'Valid inputs' do
+ inputs = [
+ [ '/full/path/to/something', '^/full' ],
+ [ '/full/path/to/something', 'full' ],
+ [ '/full/path/to/something', ['full', 'absent'] ],
+ [ '/full/path/to/something', ['full', 'absent'], 'Message to the user' ],
+ ]
+
+ inputs.each do |input|
+ it "validate_re(#{input.inspect}) should not fail" do
+ expect { subject.call input }.not_to raise_error
+ end
+ end
+ end
+ describe "Valid inputs which should raise an exception without a message" do
+ # The intent here is to make sure valid inputs raise exceptions when they
+ # don't specify an error message to display. This is the behvior in
+ # 2.2.x and prior.
+ inputs = [
+ [ "hello", [ "bye", "later", "adios" ] ],
+ [ "greetings", "salutations" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_re(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /validate_re.*?does not match/
+ end
+ end
+ end
+ describe "Nicer Error Messages" do
+ # The intent here is to make sure the function returns the 3rd argument
+ # in the exception thrown
+ inputs = [
+ [ "hello", [ "bye", "later", "adios" ], "MSG to User" ],
+ [ "greetings", "salutations", "Error, greetings does not match salutations" ],
+ ]
+
+ inputs.each do |input|
+ it "validate_re(#{input.inspect}) should fail" do
+ expect { subject.call input }.to raise_error /#{input[2]}/
+ end
+ end
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb
new file mode 100755
index 0000000..eccf908
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb
@@ -0,0 +1,48 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe "the validate_slength function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("validate_slength").should == "function_validate_slength"
+ end
+
+ it "should raise a ParseError if there is less than 2 arguments" do
+ expect { scope.function_validate_slength([]) }.to(raise_error(Puppet::ParseError))
+ expect { scope.function_validate_slength(["asdf"]) }.to(raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if argument 2 doesn't convert to a fixnum" do
+ expect { scope.function_validate_slength(["moo",["2"]]) }.to(raise_error(Puppet::ParseError, /Couldn't convert whatever you passed/))
+ end
+
+ it "should raise a ParseError if argument 2 converted, but to 0, e.g. a string" do
+ expect { scope.function_validate_slength(["moo","monkey"]) }.to(raise_error(Puppet::ParseError, /please pass a positive number as max_length/))
+ end
+
+ it "should raise a ParseError if argument 2 converted, but to 0" do
+ expect { scope.function_validate_slength(["moo","0"]) }.to(raise_error(Puppet::ParseError, /please pass a positive number as max_length/))
+ end
+
+ it "should fail if string greater then size" do
+ expect { scope.function_validate_slength(["test", 2]) }.to(raise_error(Puppet::ParseError, /It should have been less than or equal to/))
+ end
+
+ it "should fail if you pass an array of something other than strings" do
+ expect { scope.function_validate_slength([["moo",["moo"],Hash.new["moo" => 7]], 7]) }.to(raise_error(Puppet::ParseError, /is not a string, it's a/))
+ end
+
+ it "should fail if you pass something other than a string or array" do
+ expect { scope.function_validate_slength([Hash.new["moo" => "7"],6]) }.to(raise_error(Puppet::ParseError), /please pass a string, or an array of strings/)
+ end
+
+ it "should not fail if string is smaller or equal to size" do
+ expect { scope.function_validate_slength(["test", 5]) }.to_not(raise_error(Puppet::ParseError))
+ end
+
+ it "should not fail if array of string is are all smaller or equal to size" do
+ expect { scope.function_validate_slength([["moo","foo","bar"], 5]) }.to_not(raise_error(Puppet::ParseError))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb
new file mode 100644
index 0000000..3b4fb3e
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb
@@ -0,0 +1,60 @@
+#! /usr/bin/env ruby -S rspec
+
+require 'spec_helper'
+
+describe Puppet::Parser::Functions.function(:validate_string) do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ describe 'when calling validate_string from puppet' do
+
+ %w{ foo bar baz }.each do |the_string|
+
+ it "should compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_string('#{the_string}')"
+ scope.compiler.compile
+ end
+
+ it "should compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_string(#{the_string})"
+ scope.compiler.compile
+ end
+
+ end
+
+ %w{ true false }.each do |the_string|
+ it "should compile when #{the_string} is a string" do
+ Puppet[:code] = "validate_string('#{the_string}')"
+ scope.compiler.compile
+ end
+
+ it "should not compile when #{the_string} is a bare word" do
+ Puppet[:code] = "validate_string(#{the_string})"
+ expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a string/)
+ end
+ end
+
+ it "should compile when multiple string arguments are passed" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = ''
+ $bar = 'two'
+ validate_string($foo, $bar)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+
+ it "should compile when an explicitly undef variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ $foo = undef
+ validate_string($foo)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+
+ it "should compile when an undefined variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do
+ Puppet[:code] = <<-'ENDofPUPPETcode'
+ validate_string($foobarbazishouldnotexist)
+ ENDofPUPPETcode
+ scope.compiler.compile
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb
new file mode 100644
index 0000000..08e95a5
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb
@@ -0,0 +1,38 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the values_at function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("values_at").should == "function_values_at"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_values_at([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if you try to use a range where stop is greater then start" do
+ lambda { scope.function_values_at([['a','b'],["3-1"]]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return a value at from an array" do
+ result = scope.function_values_at([['a','b','c'],"1"])
+ result.should(eq(['b']))
+ end
+
+ it "should return a value at from an array when passed a range" do
+ result = scope.function_values_at([['a','b','c'],"0-1"])
+ result.should(eq(['a','b']))
+ end
+
+ it "should return chosen values from an array when passed number of indexes" do
+ result = scope.function_values_at([['a','b','c'],["0","2"]])
+ result.should(eq(['a','c']))
+ end
+
+ it "should return chosen values from an array when passed ranges and multiple indexes" do
+ result = scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]])
+ result.should(eq(['a','c','e','f']))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb
new file mode 100644
index 0000000..14ae417
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the values function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("values").should == "function_values"
+ end
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_values([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should return values from a hash" do
+ result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}])
+ # =~ is the RSpec::Matchers::MatchArray matcher.
+ # A.K.A. "array with same elements" (multiset) matching
+ result.should =~ %w{ 1 2 3 }
+ end
+
+ it "should return a multiset" do
+ result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}])
+ result.should =~ %w{ 1 3 3 }
+ result.should_not =~ %w{ 1 3 }
+ end
+
+ it "should raise a ParseError unless a Hash is provided" do
+ lambda { scope.function_values([['a','b','c']]) }.should( raise_error(Puppet::ParseError))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb
new file mode 100644
index 0000000..f45ab17
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb
@@ -0,0 +1,15 @@
+#! /usr/bin/env ruby -S rspec
+require 'spec_helper'
+
+describe "the zip function" do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_zip([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should be able to zip an array" do
+ result = scope.function_zip([['1','2','3'],['4','5','6']])
+ result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]]))
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb
new file mode 100644
index 0000000..7857d39
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb
@@ -0,0 +1,127 @@
+require 'puppet'
+require 'tempfile'
+provider_class = Puppet::Type.type(:file_line).provider(:ruby)
+describe provider_class do
+ context "when adding" do
+ before :each do
+ # TODO: these should be ported over to use the PuppetLabs spec_helper
+ # file fixtures once the following pull request has been merged:
+ # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files
+ tmp = Tempfile.new('tmp')
+ @tmpfile = tmp.path
+ tmp.close!
+ @resource = Puppet::Type::File_line.new(
+ {:name => 'foo', :path => @tmpfile, :line => 'foo'}
+ )
+ @provider = provider_class.new(@resource)
+ end
+ it 'should detect if the line exists in the file' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write('foo')
+ end
+ @provider.exists?.should be_true
+ end
+ it 'should detect if the line does not exist in the file' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write('foo1')
+ end
+ @provider.exists?.should be_nil
+ end
+ it 'should append to an existing file when creating' do
+ @provider.create
+ File.read(@tmpfile).chomp.should == 'foo'
+ end
+ end
+
+ context "when matching" do
+ before :each do
+ # TODO: these should be ported over to use the PuppetLabs spec_helper
+ # file fixtures once the following pull request has been merged:
+ # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files
+ tmp = Tempfile.new('tmp')
+ @tmpfile = tmp.path
+ tmp.close!
+ @resource = Puppet::Type::File_line.new(
+ {
+ :name => 'foo',
+ :path => @tmpfile,
+ :line => 'foo = bar',
+ :match => '^foo\s*=.*$',
+ }
+ )
+ @provider = provider_class.new(@resource)
+ end
+
+ it 'should raise an error if more than one line matches, and should not have modified the file' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz")
+ end
+ @provider.exists?.should be_nil
+ expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/)
+ File.read(@tmpfile).should eql("foo1\nfoo=blah\nfoo2\nfoo=baz")
+ end
+
+ it 'should replace a line that matches' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo=blah\nfoo2")
+ end
+ @provider.exists?.should be_nil
+ @provider.create
+ File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2")
+ end
+ it 'should add a new line if no lines match' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo2")
+ end
+ @provider.exists?.should be_nil
+ @provider.create
+ File.read(@tmpfile).should eql("foo1\nfoo2\nfoo = bar\n")
+ end
+ it 'should do nothing if the exact line already exists' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo = bar\nfoo2")
+ end
+ @provider.exists?.should be_true
+ @provider.create
+ File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2")
+ end
+ end
+
+ context "when removing" do
+ before :each do
+ # TODO: these should be ported over to use the PuppetLabs spec_helper
+ # file fixtures once the following pull request has been merged:
+ # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files
+ tmp = Tempfile.new('tmp')
+ @tmpfile = tmp.path
+ tmp.close!
+ @resource = Puppet::Type::File_line.new(
+ {:name => 'foo', :path => @tmpfile, :line => 'foo', :ensure => 'absent' }
+ )
+ @provider = provider_class.new(@resource)
+ end
+ it 'should remove the line if it exists' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo\nfoo2")
+ end
+ @provider.destroy
+ File.read(@tmpfile).should eql("foo1\nfoo2")
+ end
+
+ it 'should remove the line without touching the last new line' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo\nfoo2\n")
+ end
+ @provider.destroy
+ File.read(@tmpfile).should eql("foo1\nfoo2\n")
+ end
+
+ it 'should remove any occurence of the line' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo\nfoo2\nfoo\nfoo")
+ end
+ @provider.destroy
+ File.read(@tmpfile).should eql("foo1\nfoo2\n")
+ end
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb
new file mode 100644
index 0000000..2030b83
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+
+require 'puppet'
+
+anchor = Puppet::Type.type(:anchor).new(:name => "ntp::begin")
+
+describe anchor do
+ it "should stringify normally" do
+ anchor.to_s.should == "Anchor[ntp::begin]"
+ end
+end
diff --git a/puppet/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb b/puppet/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb
new file mode 100644
index 0000000..edc64bd
--- /dev/null
+++ b/puppet/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb
@@ -0,0 +1,69 @@
+require 'puppet'
+require 'tempfile'
+describe Puppet::Type.type(:file_line) do
+ let :file_line do
+ Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'line', :path => '/tmp/path')
+ end
+ it 'should accept a line and path' do
+ file_line[:line] = 'my_line'
+ file_line[:line].should == 'my_line'
+ file_line[:path] = '/my/path'
+ file_line[:path].should == '/my/path'
+ end
+ it 'should accept a match regex' do
+ file_line[:match] = '^foo.*$'
+ file_line[:match].should == '^foo.*$'
+ end
+ it 'should not accept a match regex that does not match the specified line' do
+ expect {
+ Puppet::Type.type(:file_line).new(
+ :name => 'foo',
+ :path => '/my/path',
+ :line => 'foo=bar',
+ :match => '^bar=blah$'
+ )}.to raise_error(Puppet::Error, /the value must be a regex that matches/)
+ end
+ it 'should accept a match regex that does match the specified line' do
+ expect {
+ Puppet::Type.type(:file_line).new(
+ :name => 'foo',
+ :path => '/my/path',
+ :line => 'foo=bar',
+ :match => '^\s*foo=.*$'
+ )}.not_to raise_error
+ end
+ it 'should accept posix filenames' do
+ file_line[:path] = '/tmp/path'
+ file_line[:path].should == '/tmp/path'
+ end
+ it 'should not accept unqualified path' do
+ expect { file_line[:path] = 'file' }.to raise_error(Puppet::Error, /File paths must be fully qualified/)
+ end
+ it 'should require that a line is specified' do
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => '/tmp/file') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
+ end
+ it 'should require that a file is specified' do
+ expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /Both line and path are required attributes/)
+ end
+ it 'should default to ensure => present' do
+ file_line[:ensure].should eq :present
+ end
+
+ it "should autorequire the file it manages" do
+ catalog = Puppet::Resource::Catalog.new
+ file = Puppet::Type.type(:file).new(:name => "/tmp/path")
+ catalog.add_resource file
+ catalog.add_resource file_line
+
+ relationship = file_line.autorequire.find do |rel|
+ (rel.source.to_s == "File[/tmp/path]") and (rel.target.to_s == file_line.to_s)
+ end
+ relationship.should be_a Puppet::Relationship
+ end
+
+ it "should not autorequire the file it manages if it is not managed" do
+ catalog = Puppet::Resource::Catalog.new
+ catalog.add_resource file_line
+ file_line.autorequire.should be_empty
+ end
+end
diff --git a/puppet/modules/stdlib/spec/watchr.rb b/puppet/modules/stdlib/spec/watchr.rb
new file mode 100644
index 0000000..885ef1d
--- /dev/null
+++ b/puppet/modules/stdlib/spec/watchr.rb
@@ -0,0 +1,86 @@
+ENV['FOG_MOCK'] ||= 'true'
+ENV['AUTOTEST'] = 'true'
+ENV['WATCHR'] = '1'
+
+system 'clear'
+
+def growl(message)
+ growlnotify = `which growlnotify`.chomp
+ title = "Watchr Test Results"
+ image = case message
+ when /(\d+)\s+?(failure|error)/i
+ ($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
+ else
+ '~/.watchr_images/unknown.png'
+ end
+ options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
+ system %(#{growlnotify} #{options} &)
+end
+
+def run(cmd)
+ puts(cmd)
+ `#{cmd}`
+end
+
+def run_spec_test(file)
+ if File.exist? file
+ result = run "rspec --format p --color #{file}"
+ growl result.split("\n").last
+ puts result
+ else
+ puts "FIXME: No test #{file} [#{Time.now}]"
+ end
+end
+
+def filter_rspec(data)
+ data.split("\n").find_all do |l|
+ l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/
+ end.join("\n")
+end
+
+def run_all_tests
+ system('clear')
+ files = Dir.glob("spec/**/*_spec.rb").join(" ")
+ result = run "rspec #{files}"
+ growl_results = filter_rspec result
+ growl growl_results
+ puts result
+ puts "GROWL: #{growl_results}"
+end
+
+# Ctrl-\
+Signal.trap 'QUIT' do
+ puts " --- Running all tests ---\n\n"
+ run_all_tests
+end
+
+@interrupted = false
+
+# Ctrl-C
+Signal.trap 'INT' do
+ if @interrupted then
+ @wants_to_quit = true
+ abort("\n")
+ else
+ puts "Interrupt a second time to quit"
+ @interrupted = true
+ Kernel.sleep 1.5
+ # raise Interrupt, nil # let the run loop catch it
+ run_suite
+ end
+end
+
+def file2spec(file)
+ result = file.sub('lib/puppet/', 'spec/unit/puppet/').gsub(/\.rb$/, '_spec.rb')
+ result = file.sub('lib/facter/', 'spec/unit/facter/').gsub(/\.rb$/, '_spec.rb')
+end
+
+
+watch( 'spec/.*_spec\.rb' ) do |md|
+ #run_spec_test(md[0])
+ run_all_tests
+end
+watch( 'lib/.*\.rb' ) do |md|
+ # run_spec_test(file2spec(md[0]))
+ run_all_tests
+end
diff --git a/puppet/modules/stdlib/tests/file_line.pp b/puppet/modules/stdlib/tests/file_line.pp
new file mode 100644
index 0000000..eea693e
--- /dev/null
+++ b/puppet/modules/stdlib/tests/file_line.pp
@@ -0,0 +1,9 @@
+# This is a simple smoke test
+# of the file_line resource type.
+file { '/tmp/dansfile':
+ ensure => present
+}->
+file_line { 'dans_line':
+ line => 'dan is awesome',
+ path => '/tmp/dansfile',
+}
diff --git a/puppet/modules/stdlib/tests/has_interface_with.pp b/puppet/modules/stdlib/tests/has_interface_with.pp
new file mode 100644
index 0000000..e1f1353
--- /dev/null
+++ b/puppet/modules/stdlib/tests/has_interface_with.pp
@@ -0,0 +1,10 @@
+include stdlib
+info('has_interface_with(\'lo\'):', has_interface_with('lo'))
+info('has_interface_with(\'loX\'):', has_interface_with('loX'))
+info('has_interface_with(\'ipaddress\', \'127.0.0.1\'):', has_interface_with('ipaddress', '127.0.0.1'))
+info('has_interface_with(\'ipaddress\', \'127.0.0.100\'):', has_interface_with('ipaddress', '127.0.0.100'))
+info('has_interface_with(\'network\', \'127.0.0.0\'):', has_interface_with('network', '127.0.0.0'))
+info('has_interface_with(\'network\', \'128.0.0.0\'):', has_interface_with('network', '128.0.0.0'))
+info('has_interface_with(\'netmask\', \'255.0.0.0\'):', has_interface_with('netmask', '255.0.0.0'))
+info('has_interface_with(\'netmask\', \'256.0.0.0\'):', has_interface_with('netmask', '256.0.0.0'))
+
diff --git a/puppet/modules/stdlib/tests/has_ip_address.pp b/puppet/modules/stdlib/tests/has_ip_address.pp
new file mode 100644
index 0000000..8429a88
--- /dev/null
+++ b/puppet/modules/stdlib/tests/has_ip_address.pp
@@ -0,0 +1,3 @@
+include stdlib
+info('has_ip_address(\'192.168.1.256\'):', has_ip_address('192.168.1.256'))
+info('has_ip_address(\'127.0.0.1\'):', has_ip_address('127.0.0.1'))
diff --git a/puppet/modules/stdlib/tests/has_ip_network.pp b/puppet/modules/stdlib/tests/has_ip_network.pp
new file mode 100644
index 0000000..a15d8c0
--- /dev/null
+++ b/puppet/modules/stdlib/tests/has_ip_network.pp
@@ -0,0 +1,4 @@
+include stdlib
+info('has_ip_network(\'127.0.0.0\'):', has_ip_network('127.0.0.0'))
+info('has_ip_network(\'128.0.0.0\'):', has_ip_network('128.0.0.0'))
+
diff --git a/puppet/modules/stdlib/tests/init.pp b/puppet/modules/stdlib/tests/init.pp
new file mode 100644
index 0000000..9675d83
--- /dev/null
+++ b/puppet/modules/stdlib/tests/init.pp
@@ -0,0 +1 @@
+include stdlib
diff --git a/puppet/modules/wget/Gemfile b/puppet/modules/wget/Gemfile
new file mode 100644
index 0000000..bdce7a9
--- /dev/null
+++ b/puppet/modules/wget/Gemfile
@@ -0,0 +1,10 @@
+source "https://rubygems.org"
+
+group :rake do
+ gem 'puppet', '>=2.7.17'
+ gem 'rspec-puppet', '>=0.1.3'
+ gem 'rake', '>=0.9.2.2'
+ gem 'puppet-lint', '>=0.1.12'
+ gem 'puppetlabs_spec_helper'
+ gem 'puppet-blacksmith', '>=1.0.5'
+end
diff --git a/puppet/modules/wget/Gemfile.lock b/puppet/modules/wget/Gemfile.lock
new file mode 100644
index 0000000..22c99ae
--- /dev/null
+++ b/puppet/modules/wget/Gemfile.lock
@@ -0,0 +1,56 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ diff-lcs (1.2.4)
+ facter (1.7.2)
+ hiera (1.2.1)
+ json_pure
+ json_pure (1.8.0)
+ metaclass (0.0.1)
+ mime-types (1.24)
+ mini_portile (0.5.1)
+ mocha (0.14.0)
+ metaclass (~> 0.0.1)
+ nokogiri (1.6.0)
+ mini_portile (~> 0.5.0)
+ puppet (3.2.4)
+ facter (~> 1.6)
+ hiera (~> 1.0)
+ rgen (~> 0.6.5)
+ puppet-blacksmith (1.0.5)
+ nokogiri
+ puppet (>= 2.7.16)
+ puppetlabs_spec_helper (>= 0.3.0)
+ rake
+ rest-client
+ puppet-lint (0.3.2)
+ puppetlabs_spec_helper (0.4.1)
+ mocha (>= 0.10.5)
+ rake
+ rspec (>= 2.9.0)
+ rspec-puppet (>= 0.1.1)
+ rake (10.1.0)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ rgen (0.6.5)
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.5)
+ rspec-expectations (2.14.2)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.3)
+ rspec-puppet (0.1.6)
+ rspec
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ puppet (>= 2.7.17)
+ puppet-blacksmith (>= 1.0.5)
+ puppet-lint (>= 0.1.12)
+ puppetlabs_spec_helper
+ rake (>= 0.9.2.2)
+ rspec-puppet (>= 0.1.3)
diff --git a/puppet/modules/wget/Modulefile b/puppet/modules/wget/Modulefile
new file mode 100644
index 0000000..99b6487
--- /dev/null
+++ b/puppet/modules/wget/Modulefile
@@ -0,0 +1,8 @@
+name 'maestrodev-wget'
+version '1.2.2'
+source 'http://github.com/maestrodev/puppet-wget.git'
+author 'maestrodev'
+license 'Apache License, Version 2.0'
+summary 'Download files with wget'
+description 'A module for wget that allows downloading of files, supporting authentication'
+project_page 'http://github.com/maestrodev/puppet-wget'
diff --git a/puppet/modules/wget/README.md b/puppet/modules/wget/README.md
new file mode 100644
index 0000000..617b905
--- /dev/null
+++ b/puppet/modules/wget/README.md
@@ -0,0 +1,55 @@
+A Puppet module to download files with wget, supporting authentication.
+
+# Example
+
+install wget:
+
+```puppet
+ include wget
+```
+
+```puppet
+ wget::fetch { "download Google's index":
+ source => 'http://www.google.com/index.html',
+ destination => '/tmp/index.html',
+ timeout => 0,
+ verbose => false,
+ }
+```
+or alternatively:
+
+```puppet
+ wget::fetch { 'http://www.google.com/index.html':
+ destination => '/tmp/index.html',
+ timeout => 0,
+ verbose => false,
+ }
+```
+This fetches a document which requires authentication:
+
+```puppet
+ wget::authfetch { 'Fetch secret PDF':
+ source => 'https://confidential.example.com/secret.pdf',
+ destination => '/tmp/secret.pdf',
+ user => 'user',
+ password => 'p$ssw0rd',
+ timeout => 0,
+ verbose => false,
+ }
+```
+
+# License
+
+Copyright 2011-2013 MaestroDev
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/puppet/modules/wget/Rakefile b/puppet/modules/wget/Rakefile
new file mode 100644
index 0000000..9159082
--- /dev/null
+++ b/puppet/modules/wget/Rakefile
@@ -0,0 +1,13 @@
+require 'bundler'
+Bundler.require(:rake)
+require 'rake/clean'
+
+CLEAN.include('spec/fixtures/', 'doc', 'pkg')
+CLOBBER.include('.tmp', '.librarian')
+
+require 'puppetlabs_spec_helper/rake_tasks'
+require 'puppet_blacksmith/rake_tasks'
+
+PuppetLint.configuration.send("disable_80chars")
+
+task :default => [:clean, :spec]
diff --git a/puppet/modules/wget/manifests/authfetch.pp b/puppet/modules/wget/manifests/authfetch.pp
new file mode 100644
index 0000000..e29a219
--- /dev/null
+++ b/puppet/modules/wget/manifests/authfetch.pp
@@ -0,0 +1,72 @@
+################################################################################
+# Definition: wget::authfetch
+#
+# This class will download files from the internet. You may define a web proxy
+# using $::http_proxy if necessary. Username must be provided. And the user's
+# password must be stored in the password variable within the .wgetrc file.
+#
+################################################################################
+define wget::authfetch (
+ $destination,
+ $user,
+ $source = $title,
+ $password = '',
+ $timeout = '0',
+ $verbose = false,
+ $redownload = false,
+ $nocheckcertificate = false,
+ $execuser = 'root',
+) {
+
+ include wget
+
+ if $::http_proxy {
+ $environment = [ "HTTP_PROXY=${::http_proxy}", "http_proxy=${::http_proxy}", "WGETRC=/tmp/wgetrc-${name}" ]
+ }
+ else {
+ $environment = [ "WGETRC=/tmp/wgetrc-${name}" ]
+ }
+
+ $verbose_option = $verbose ? {
+ true => '--verbose',
+ false => '--no-verbose'
+ }
+
+ $unless_test = $redownload ? {
+ true => 'test',
+ false => "test -s ${destination}"
+ }
+
+ $nocheckcert_option = $nocheckcertificate ? {
+ true => ' --no-check-certificate',
+ false => ''
+ }
+
+ case $::operatingsystem {
+ 'Darwin': {
+ # This is to work around an issue with macports wget and out of date CA cert bundle. This requires
+ # installing the curl-ca-bundle package like so:
+ #
+ # sudo port install curl-ca-bundle
+ $wgetrc_content = "password=${password}\nCA_CERTIFICATE=/opt/local/share/curl/curl-ca-bundle.crt\n"
+ }
+ default: {
+ $wgetrc_content = "password=${password}"
+ }
+ }
+
+ file { "/tmp/wgetrc-${name}":
+ owner => 'root',
+ mode => '0600',
+ content => $wgetrc_content,
+ } ->
+ exec { "wget-${name}":
+ command => "wget ${verbose_option}${nocheckcert_option} --user=${user} --output-document='${destination}' '${source}'",
+ timeout => $timeout,
+ unless => $unless_test,
+ environment => $environment,
+ user => $execuser,
+ path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin:/opt/local/bin',
+ require => Class['wget'],
+ }
+}
diff --git a/puppet/modules/wget/manifests/fetch.pp b/puppet/modules/wget/manifests/fetch.pp
new file mode 100644
index 0000000..a8d3901
--- /dev/null
+++ b/puppet/modules/wget/manifests/fetch.pp
@@ -0,0 +1,54 @@
+################################################################################
+# Definition: wget::fetch
+#
+# This class will download files from the internet. You may define a web proxy
+# using $http_proxy if necessary.
+#
+################################################################################
+define wget::fetch (
+ $destination,
+ $source = $title,
+ $timeout = '0',
+ $verbose = false,
+ $redownload = false,
+ $nocheckcertificate = false,
+ $execuser = 'root',
+) {
+
+ include wget
+
+ # using "unless" with test instead of "creates" to re-attempt download
+ # on empty files.
+ # wget creates an empty file when a download fails, and then it wouldn't try
+ # again to download the file
+ if $::http_proxy {
+ $environment = [ "HTTP_PROXY=${::http_proxy}", "http_proxy=${::http_proxy}" ]
+ } else {
+ $environment = []
+ }
+
+ $verbose_option = $verbose ? {
+ true => '--verbose',
+ false => '--no-verbose'
+ }
+
+ $unless_test = $redownload ? {
+ true => 'test',
+ false => "test -s ${destination}"
+ }
+
+ $nocheckcert_option = $nocheckcertificate ? {
+ true => ' --no-check-certificate',
+ false => ''
+ }
+
+ exec { "wget-${name}":
+ command => "wget ${verbose_option}${nocheckcert_option} --output-document='${destination}' '${source}'",
+ timeout => $timeout,
+ unless => $unless_test,
+ environment => $environment,
+ user => $execuser,
+ path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin:/opt/local/bin',
+ require => Class['wget'],
+ }
+}
diff --git a/puppet/modules/wget/manifests/init.pp b/puppet/modules/wget/manifests/init.pp
new file mode 100644
index 0000000..4dc2cf7
--- /dev/null
+++ b/puppet/modules/wget/manifests/init.pp
@@ -0,0 +1,16 @@
+################################################################################
+# Class: wget
+#
+# This class will install wget - a tool used to download content from the web.
+#
+################################################################################
+class wget (
+ $version = present,
+) {
+
+ if $::operatingsystem != 'Darwin' {
+ if ! defined(Package['wget']) {
+ package { 'wget': ensure => $version }
+ }
+ }
+}
diff --git a/puppet/modules/wget/metadata.json b/puppet/modules/wget/metadata.json
new file mode 100644
index 0000000..9e754cd
--- /dev/null
+++ b/puppet/modules/wget/metadata.json
@@ -0,0 +1,30 @@
+{
+ "name": "maestrodev-wget",
+ "version": "1.2.2",
+ "source": "http://github.com/maestrodev/puppet-wget.git",
+ "author": "maestrodev",
+ "license": "Apache License, Version 2.0",
+ "summary": "Download files with wget",
+ "description": "A module for wget that allows downloading of files, supporting authentication",
+ "project_page": "http://github.com/maestrodev/puppet-wget",
+ "dependencies": [
+
+ ],
+ "types": [
+
+ ],
+ "checksums": {
+ "Gemfile": "e5baf638115a41d73cb299daf9ad9502",
+ "Gemfile.lock": "a19a873ba6ef14190e91851332d79f4c",
+ "Modulefile": "68e4ce1c27fec65fa5feb82141a3f51e",
+ "README.md": "5ce4d709d50ff635f78b7580fa291142",
+ "Rakefile": "31adafa1c0ed7d932985b6d1af89ecff",
+ "manifests/authfetch.pp": "8fe8e554f4d99777e5ad242ff84ccf3e",
+ "manifests/fetch.pp": "617d2950b21b86d8e5212b325a778f67",
+ "manifests/init.pp": "582c44cad08f204e424fc361327842b7",
+ "spec/classes/init_spec.rb": "154db01e3fff4f58689fc8729ec1a721",
+ "spec/defines/authfetch_spec.rb": "b6876f4b3319410f11c11d3a985c210b",
+ "spec/defines/fetch_spec.rb": "68133dec0512ea777afa581f763c79a1",
+ "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc"
+ }
+}
\ No newline at end of file
diff --git a/puppet/modules/wget/spec/classes/init_spec.rb b/puppet/modules/wget/spec/classes/init_spec.rb
new file mode 100644
index 0000000..d822d2b
--- /dev/null
+++ b/puppet/modules/wget/spec/classes/init_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe 'wget' do
+
+ context 'running on OS X' do
+ let(:facts) { {:operatingsystem => 'Darwin'} }
+
+ it { should_not contain_package('wget') }
+ end
+
+ context 'running on CentOS' do
+ let(:facts) { {:operatingsystem => 'CentOS'} }
+
+ it { should contain_package('wget') }
+ end
+
+ context 'no version specified' do
+ it { should contain_package('wget').with_ensure('present') }
+ end
+
+ context 'version is 1.2.3' do
+ let(:params) { {:version => '1.2.3'} }
+
+ it { should contain_package('wget').with_ensure('1.2.3') }
+ end
+end
diff --git a/puppet/modules/wget/spec/defines/authfetch_spec.rb b/puppet/modules/wget/spec/defines/authfetch_spec.rb
new file mode 100644
index 0000000..fc8b6aa
--- /dev/null
+++ b/puppet/modules/wget/spec/defines/authfetch_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+describe 'wget::authfetch' do
+ let(:title) { 'authtest' }
+ let(:params) {{
+ :source => 'http://localhost/source',
+ :destination => '/tmp/dest',
+ :user => 'myuser',
+ :password => 'mypassword',
+ }}
+
+ context "with default params" do
+ it { should contain_exec('wget-authtest').with({
+ 'command' => "wget --no-verbose --user=myuser --output-document='/tmp/dest' 'http://localhost/source'",
+ 'environment' => 'WGETRC=/tmp/wgetrc-authtest'
+ })
+ }
+ it { should contain_file('/tmp/wgetrc-authtest').with_content('password=mypassword') }
+ end
+
+ context "with user" do
+ let(:params) { super().merge({
+ :execuser => 'testuser',
+ })}
+
+ it { should contain_exec('wget-authtest').with({
+ 'command' => "wget --no-verbose --user=myuser --output-document='/tmp/dest' 'http://localhost/source'",
+ 'user' => 'testuser'
+ }) }
+ end
+end
diff --git a/puppet/modules/wget/spec/defines/fetch_spec.rb b/puppet/modules/wget/spec/defines/fetch_spec.rb
new file mode 100644
index 0000000..363238c
--- /dev/null
+++ b/puppet/modules/wget/spec/defines/fetch_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'wget::fetch' do
+ let(:title) { 'test' }
+
+ let(:params) {{
+ :source => 'http://localhost/source',
+ :destination => '/tmp/dest',
+ }}
+
+ context "with default params" do
+ it { should contain_exec('wget-test').with_command("wget --no-verbose --output-document='/tmp/dest' 'http://localhost/source'") }
+ end
+
+ context "with user" do
+ let(:params) { super().merge({
+ :execuser => 'testuser',
+ })}
+
+ it { should contain_exec('wget-test').with({
+ 'command' => "wget --no-verbose --output-document='/tmp/dest' 'http://localhost/source'",
+ 'user' => 'testuser'
+ }) }
+ end
+end
diff --git a/puppet/modules/wget/spec/spec_helper.rb b/puppet/modules/wget/spec/spec_helper.rb
new file mode 100644
index 0000000..2c6f566
--- /dev/null
+++ b/puppet/modules/wget/spec/spec_helper.rb
@@ -0,0 +1 @@
+require 'puppetlabs_spec_helper/module_spec_helper'
diff --git a/web/app_dev.php b/web/app_dev.php
index 872a882..80c7639 100644
--- a/web/app_dev.php
+++ b/web/app_dev.php
@@ -11,7 +11,7 @@ use Symfony\Component\Debug\Debug;
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
- || !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
+ || !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1', '192.168.33.1'))
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
@@ -23,7 +23,10 @@ Debug::enable();
require_once __DIR__.'/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
-$kernel->loadClassCache();
+//This check tries to detect a XDebug session to prevent the load of class cache
+if (!extension_loaded('xdebug') || (!isset($_REQUEST['XDEBUG_SESSION_START']) && !isset($_COOKIE['XDEBUG_SESSION']) && ini_get('xdebug.remote_autostart') == false)) {
+ $kernel->loadClassCache();
+}
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();

SF2 VAGRANT

This is a simple patch to add Vagrant support to any standard Symfony 2 Framework app.

It will create a Debian Wheezy box and the project files will be shared with NFS so you must have the NFS server installed in your host machine. If you want to access to your dev machine with a domain name, insted of the default IP (192.168.10.33), you should add an entry to your /etc/hosts file:

192.168.33.10 sf2.localdomain

The XDebug extension is available and the config param xdebug.remote_connect_back enabled +info.

The cache and logs dirs were moved to /tmp for dev and test environments, the access to app_dev.php were enabled from 192.168.33.1 and the kernel will skip to load the class cache when an XDebug session is detected.

After booting and provisioning your VM, you can point your browser to http://192.168.33.10/app_dev.php.

The VM default locale is es_ES.UTF-8. You can change it executing dpkg-reconfigure locales.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment