Commit 8ea032b218e6bc009099b2c54f1f8920d3546c6e

Authored by Sergio Oliveira
1 parent 9450256c

Installing nginx from ppa

Showing 278 changed files with 12212 additions and 2 deletions   Show diff stats

Too many changes.

To preserve performance only 100 of 278 files displayed.

puppet/modules/apt/.bundle/config 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +---
  2 +BUNDLE_WITHOUT: development
... ...
puppet/modules/apt/.fixtures.yml 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +fixtures:
  2 + repositories:
  3 + "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
  4 + symlinks:
  5 + "apt": "#{source_dir}"
... ...
puppet/modules/apt/.forge-release/pom.xml 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 + <modelVersion>4.0.0</modelVersion>
  4 + <groupId>puppetlabs</groupId>
  5 + <artifactId>ghpublisher</artifactId>
  6 + <version>1.0.0</version>
  7 + <packaging>puppet-module</packaging>
  8 + <name>ghpublisher</name>
  9 +
  10 + <properties>
  11 + <forge.login>${env.PUBLISHER_LOGIN}</forge.login>
  12 + <forge.password>${env.PUBLISHER_PASSWORD}</forge.password>
  13 + </properties>
  14 +
  15 + <build>
  16 + <plugins>
  17 + <plugin>
  18 + <groupId>org.cloudsmith.geppetto</groupId>
  19 + <artifactId>forge-maven-plugin</artifactId>
  20 + <version>3.2.0</version>
  21 + <extensions>true</extensions>
  22 + <configuration>
  23 + <enablePuppetLintValidation>false</enablePuppetLintValidation>
  24 + <cacheLocation>${project.build.directory}/forgeCache</cacheLocation>
  25 + </configuration>
  26 + </plugin>
  27 + </plugins>
  28 + </build>
  29 +</project>
... ...
puppet/modules/apt/.forge-release/publish 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +#!/bin/sh
  2 +#
  3 +# Perform GitHub publish
  4 +if [ -z "$PUBLISHER_LOGIN" ]
  5 +then
  6 + echo "Environment variable PUBLISHER_LOGIN must be set"
  7 + exit 1
  8 +fi
  9 +
  10 +if [ -z "$PUBLISHER_PASSWORD" ]
  11 +then
  12 + echo "Environment variable PUBLISHER_PASSWORD must be set"
  13 + exit 1
  14 +fi
  15 +
  16 +MODULES_ROOT=`pwd`
  17 +cd $(dirname $0)
  18 +mvn -q -s settings.xml -Dforge.modules.root="$MODULES_ROOT" deploy
0 19 \ No newline at end of file
... ...
puppet/modules/apt/.forge-release/settings.xml 0 → 100644
... ... @@ -0,0 +1,34 @@
  1 +<settings>
  2 + <profiles>
  3 + <profile>
  4 + <id>cloudsmith</id>
  5 + <repositories>
  6 + <repository>
  7 + <id>cloudsmith</id>
  8 + <url>https://am0.cloudsmith.com/nexus/content/repositories/releases/</url>
  9 + <releases>
  10 + <enabled>true</enabled>
  11 + </releases>
  12 + <snapshots>
  13 + <enabled>false</enabled>
  14 + </snapshots>
  15 + </repository>
  16 + </repositories>
  17 + <pluginRepositories>
  18 + <pluginRepository>
  19 + <id>cloudsmith</id>
  20 + <url>https://am0.cloudsmith.com/nexus/content/repositories/releases/</url>
  21 + <releases>
  22 + <enabled>true</enabled>
  23 + </releases>
  24 + <snapshots>
  25 + <enabled>false</enabled>
  26 + </snapshots>
  27 + </pluginRepository>
  28 + </pluginRepositories>
  29 + </profile>
  30 + </profiles>
  31 + <activeProfiles>
  32 + <activeProfile>cloudsmith</activeProfile>
  33 + </activeProfiles>
  34 +</settings>
... ...
puppet/modules/apt/.forge-release/validate 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +#!/bin/sh
  2 +#
  3 +# Perform GitHub publish
  4 +MODULES_ROOT=`pwd`
  5 +cd $(dirname $0)
  6 +mvn -q -s settings.xml -Dforge.modules.root="$MODULES_ROOT" compile
0 7 \ No newline at end of file
... ...
puppet/modules/apt/.nodeset.yml 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +---
  2 +default_set: 'ubuntu-server-12042-x64'
  3 +sets:
  4 + 'debian-607-x64':
  5 + nodes:
  6 + "main.foo.vm":
  7 + prefab: 'debian-607-x64'
  8 + 'debian-70rc1-x64':
  9 + nodes:
  10 + "main.foo.vm":
  11 + prefab: 'debian-70rc1-x64'
  12 + 'ubuntu-server-10044-x64':
  13 + nodes:
  14 + "main.foo.vm":
  15 + prefab: 'ubuntu-server-10044-x64'
  16 + 'ubuntu-server-12042-x64':
  17 + nodes:
  18 + "main.foo.vm":
  19 + prefab: 'ubuntu-server-12042-x64'
... ...
puppet/modules/apt/.travis.yml 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +---
  2 +branches:
  3 + only:
  4 + - master
  5 +language: ruby
  6 +bundler_args: --without development
  7 +script: bundle exec rake spec SPEC_OPTS='--format documentation'
  8 +after_success:
  9 + - git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-release
  10 + - .forge-release/publish
  11 +rvm:
  12 + - 1.8.7
  13 + - 1.9.3
  14 + - 2.0.0
  15 +env:
  16 + matrix:
  17 + - PUPPET_GEM_VERSION="~> 2.7.0"
  18 + - PUPPET_GEM_VERSION="~> 3.0.0"
  19 + - PUPPET_GEM_VERSION="~> 3.1.0"
  20 + - PUPPET_GEM_VERSION="~> 3.2.0"
  21 + global:
  22 + - PUBLISHER_LOGIN=puppetlabs
  23 + - secure: |-
  24 + ipB/CV1rVSTXU9ZDuzrFOlzJrRmJob36tKns2xszuH4r9s5P9qivNAngRGdV
  25 + msb69xvOlzQykM0WRF+4kJ6TZ7AbMiDI+VZ8GDtsRaU5/q3BpsvFe8aato+6
  26 + QeyFtBG62OsosTEhGws4mqiFsPDu3dHlakuJc9zevlTuhNwbKSs=
  27 +matrix:
  28 + exclude:
  29 + - rvm: 1.9.3
  30 + env: PUPPET_GEM_VERSION="~> 2.7.0"
  31 + - rvm: 2.0.0
  32 + env: PUPPET_GEM_VERSION="~> 2.7.0"
  33 + - rvm: 2.0.0
  34 + env: PUPPET_GEM_VERSION="~> 3.0.0"
  35 + - rvm: 2.0.0
  36 + env: PUPPET_GEM_VERSION="~> 3.1.0"
  37 + - rvm: 1.8.7
  38 + env: PUPPET_GEM_VERSION="~> 3.2.0"
  39 +notifications:
  40 + email: false
... ...
puppet/modules/apt/CHANGELOG 0 → 100644
... ... @@ -0,0 +1,183 @@
  1 +2013-10-08 1.4.0
  2 +
  3 +Summary:
  4 +
  5 +Minor bugfix and allow the timeout to be adjusted.
  6 +
  7 +Features:
  8 +- Add an `updates_timeout` to apt::params
  9 +
  10 +Fixes:
  11 +- Ensure apt::ppa can readd a ppa removed by hand.
  12 +
  13 +Summary
  14 +
  15 +1.3.0
  16 +=====
  17 +
  18 +Summary:
  19 +
  20 +This major feature in this release is the new apt::unattended_upgrades class,
  21 +allowing you to handle Ubuntu's unattended feature. This allows you to select
  22 +specific packages to automatically upgrade without any further user
  23 +involvement.
  24 +
  25 +In addition we extend our Wheezy support, add proxy support to apt:ppa and do
  26 +various cleanups and tweaks.
  27 +
  28 +Features:
  29 +- Add apt::unattended_upgrades support for Ubuntu.
  30 +- Add wheezy backports support.
  31 +- Use the geoDNS http.debian.net instead of the main debian ftp server.
  32 +- Add `options` parameter to apt::ppa in order to pass options to apt-add-repository command.
  33 +- Add proxy support for apt::ppa (uses proxy_host and proxy_port from apt).
  34 +
  35 +Bugfixes:
  36 +- Fix regsubst() calls to quote single letters (for future parser).
  37 +- Fix lint warnings and other misc cleanup.
  38 +
  39 +1.2.0
  40 +=====
  41 +
  42 +Features:
  43 +- Add geppetto `.project` natures
  44 +- Add GH auto-release
  45 +- Add `apt::key::key_options` parameter
  46 +- Add complex pin support using distribution properties for `apt::pin` via new properties:
  47 + - `apt::pin::codename`
  48 + - `apt::pin::release_version`
  49 + - `apt::pin::component`
  50 + - `apt::pin::originator`
  51 + - `apt::pin::label`
  52 +- Add source architecture support to `apt::source::architecture`
  53 +
  54 +Bugfixes:
  55 +- Use apt-get instead of aptitude in apt::force
  56 +- Update default backports location
  57 +- Add dependency for required packages before apt-get update
  58 +
  59 +
  60 +1.1.1
  61 +=====
  62 +
  63 +This is a bug fix release that resolves a number of issues:
  64 +
  65 +* By changing template variable usage, we remove the deprecation warnings
  66 + for Puppet 3.2.x
  67 +* Fixed proxy file removal, when proxy absent
  68 +
  69 +Some documentation, style and whitespaces changes were also merged. This
  70 +release also introduced proper rspec-puppet unit testing on Travis-CI to help
  71 +reduce regression.
  72 +
  73 +Thanks to all the community contributors below that made this patch possible.
  74 +
  75 +#### Detail Changes
  76 +
  77 +* fix minor comment type (Chris Rutter)
  78 +* whitespace fixes (Michael Moll)
  79 +* Update travis config file (William Van Hevelingen)
  80 +* Build all branches on travis (William Van Hevelingen)
  81 +* Standardize travis.yml on pattern introduced in stdlib (William Van Hevelingen)
  82 +* Updated content to conform to README best practices template (Lauren Rother)
  83 +* Fix apt::release example in readme (Brian Galey)
  84 +* add @ to variables in template (Peter Hoeg)
  85 +* Remove deprecation warnings for pin.pref.erb as well (Ken Barber)
  86 +* Update travis.yml to latest versions of puppet (Ken Barber)
  87 +* Fix proxy file removal (Scott Barber)
  88 +* Add spec test for removing proxy configuration (Dean Reilly)
  89 +* Fix apt::key listing longer than 8 chars (Benjamin Knofe)
  90 +
  91 +
  92 +---------------------------------------
  93 +
  94 +1.1.0
  95 +=====
  96 +
  97 +This release includes Ubuntu 12.10 (Quantal) support for PPAs.
  98 +
  99 +---------------------------------------
  100 +
  101 +2012-05-25 Puppet Labs <info@puppetlabs.com> - 0.0.4
  102 + * Fix ppa list filename when there is a period in the PPA name
  103 + * Add .pref extension to apt preferences files
  104 + * Allow preferences to be purged
  105 + * Extend pin support
  106 +
  107 +2012-05-04 Puppet Labs <info@puppetlabs.com> - 0.0.3
  108 + * only invoke apt-get update once
  109 + * only install python-software-properties if a ppa is added
  110 + * support 'ensure => absent' for all defined types
  111 + * add apt::conf
  112 + * add apt::backports
  113 + * fixed Modulefile for module tool dependency resolution
  114 + * configure proxy before doing apt-get update
  115 + * use apt-get update instead of aptitude for apt::ppa
  116 + * add support to pin release
  117 +
  118 +
  119 +2012-03-26 Puppet Labs <info@puppetlabs.com> - 0.0.2
  120 +41cedbb (#13261) Add real examples to smoke tests.
  121 +d159a78 (#13261) Add key.pp smoke test
  122 +7116c7a (#13261) Replace foo source with puppetlabs source
  123 +1ead0bf Ignore pkg directory.
  124 +9c13872 (#13289) Fix some more style violations
  125 +0ea4ffa (#13289) Change test scaffolding to use a module & manifest dir fixture path
  126 +a758247 (#13289) Clean up style violations and fix corresponding tests
  127 +99c3fd3 (#13289) Add puppet lint tests to Rakefile
  128 +5148cbf (#13125) Apt keys should be case insensitive
  129 +b9607a4 Convert apt::key to use anchors
  130 +
  131 +2012-03-07 Puppet Labs <info@puppetlabs.com> - 0.0.1
  132 +d4fec56 Modify apt::source release parameter test
  133 +1132a07 (#12917) Add contributors to README
  134 +8cdaf85 (#12823) Add apt::key defined type and modify apt::source to use it
  135 +7c0d10b (#12809) $release should use $lsbdistcodename and fall back to manual input
  136 +be2cc3e (#12522) Adjust spec test for splitting purge
  137 +7dc60ae (#12522) Split purge option to spare sources.list
  138 +9059c4e Fix source specs to test all key permutations
  139 +8acb202 Add test for python-software-properties package
  140 +a4af11f Check if python-software-properties is defined before attempting to define it.
  141 +1dcbf3d Add tests for required_packages change
  142 +f3735d2 Allow duplicate $required_packages
  143 +74c8371 (#12430) Add tests for changes to apt module
  144 +97ebb2d Test two sources with the same key
  145 +1160bcd (#12526) Add ability to reverse apt { disable_keys => true }
  146 +2842d73 Add Modulefile to puppet-apt
  147 +c657742 Allow the use of the same key in multiple sources
  148 +8c27963 (#12522) Adding purge option to apt class
  149 +997c9fd (#12529) Add unit test for apt proxy settings
  150 +50f3cca (#12529) Add parameter to support setting a proxy for apt
  151 +d522877 (#12094) Replace chained .with_* with a hash
  152 +8cf1bd0 (#12094) Remove deprecated spec.opts file
  153 +2d688f4 (#12094) Add rspec-puppet tests for apt
  154 +0fb5f78 (#12094) Replace name with path in file resources
  155 +f759bc0 (#11953) Apt::force passes $version to aptitude
  156 +f71db53 (#11413) Add spec test for apt::force to verify changes to unless
  157 +2f5d317 (#11413) Update dpkg query used by apt::force
  158 +cf6caa1 (#10451) Add test coverage to apt::ppa
  159 +0dd697d include_src parameter in example; Whitespace cleanup
  160 +b662eb8 fix typos in "repositories"
  161 +1be7457 Fix (#10451) - apt::ppa fails to "apt-get update" when new PPA source is added
  162 +864302a Set the pin priority before adding the source (Fix #10449)
  163 +1de4e0a Refactored as per mlitteken
  164 +1af9a13 Added some crazy bash madness to check if the ppa is installed already. Otherwise the manifest tries to add it on every run!
  165 +52ca73e (#8720) Replace Apt::Ppa with Apt::Builddep
  166 +5c05fa0 added builddep command.
  167 +a11af50 added the ability to specify the content of a key
  168 +c42db0f Fixes ppa test.
  169 +77d2b0d reformatted whitespace to match recommended style of 2 space indentation.
  170 +27ebdfc ignore swap files.
  171 +377d58a added smoke tests for module.
  172 +18f614b reformatted apt::ppa according to recommended style.
  173 +d8a1e4e Created a params class to hold global data.
  174 +636ae85 Added two params for apt class
  175 +148fc73 Update LICENSE.
  176 +ed2d19e Support ability to add more than one PPA
  177 +420d537 Add call to apt-update after add-apt-repository in apt::ppa
  178 +945be77 Add package definition for python-software-properties
  179 +71fc425 Abs paths for all commands
  180 +9d51cd1 Adding LICENSE
  181 +71796e3 Heading fix in README
  182 +87777d8 Typo in README
  183 +f848bac First commit
... ...
puppet/modules/apt/Gemfile 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +source 'https://rubygems.org'
  2 +
  3 +group :development, :test do
  4 + gem 'rake', :require => false
  5 + gem 'rspec-puppet', :require => false
  6 + gem 'puppetlabs_spec_helper', :require => false
  7 + gem 'rspec-system', :require => false
  8 + gem 'rspec-system-puppet', :require => false
  9 + gem 'rspec-system-serverspec', :require => false
  10 +end
  11 +
  12 +if puppetversion = ENV['PUPPET_GEM_VERSION']
  13 + gem 'puppet', puppetversion, :require => false
  14 +else
  15 + gem 'puppet', :require => false
  16 +end
... ...
puppet/modules/apt/Gemfile.lock 0 → 100644
... ... @@ -0,0 +1,70 @@
  1 +GEM
  2 + remote: https://rubygems.org/
  3 + specs:
  4 + builder (3.2.2)
  5 + diff-lcs (1.2.4)
  6 + facter (1.6.18)
  7 + hiera (1.0.0)
  8 + highline (1.6.19)
  9 + kwalify (0.7.2)
  10 + metaclass (0.0.1)
  11 + mocha (0.14.0)
  12 + metaclass (~> 0.0.1)
  13 + net-scp (1.1.2)
  14 + net-ssh (>= 2.6.5)
  15 + net-ssh (2.7.0)
  16 + nokogiri (1.5.10)
  17 + puppet (3.0.2)
  18 + facter (~> 1.6.11)
  19 + hiera (~> 1.0.0)
  20 + puppetlabs_spec_helper (0.4.1)
  21 + mocha (>= 0.10.5)
  22 + rake
  23 + rspec (>= 2.9.0)
  24 + rspec-puppet (>= 0.1.1)
  25 + rake (10.1.0)
  26 + rbvmomi (1.6.0)
  27 + builder
  28 + nokogiri (>= 1.4.1)
  29 + trollop
  30 + rspec (2.14.1)
  31 + rspec-core (~> 2.14.0)
  32 + rspec-expectations (~> 2.14.0)
  33 + rspec-mocks (~> 2.14.0)
  34 + rspec-core (2.14.5)
  35 + rspec-expectations (2.14.3)
  36 + diff-lcs (>= 1.1.3, < 2.0)
  37 + rspec-mocks (2.14.3)
  38 + rspec-puppet (0.1.6)
  39 + rspec
  40 + rspec-system (2.3.0)
  41 + kwalify (~> 0.7.2)
  42 + net-scp (~> 1.1)
  43 + net-ssh (~> 2.6)
  44 + nokogiri (~> 1.5.9)
  45 + rbvmomi (~> 1.6)
  46 + rspec (~> 2.13)
  47 + systemu (~> 2.5)
  48 + rspec-system-puppet (2.2.0)
  49 + rspec-system (~> 2.0)
  50 + rspec-system-serverspec (1.0.1)
  51 + rspec-system (~> 2.0)
  52 + serverspec (~> 0.0)
  53 + serverspec (0.10.5)
  54 + highline
  55 + net-ssh
  56 + rspec (>= 2.13.0)
  57 + systemu (2.5.2)
  58 + trollop (2.0)
  59 +
  60 +PLATFORMS
  61 + ruby
  62 +
  63 +DEPENDENCIES
  64 + puppet (~> 3.0.0)
  65 + puppetlabs_spec_helper
  66 + rake
  67 + rspec-puppet
  68 + rspec-system
  69 + rspec-system-puppet
  70 + rspec-system-serverspec
... ...
puppet/modules/apt/LICENSE 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +Copyright (c) 2011 Evolving Web Inc.
  2 +
  3 +Permission is hereby granted, free of charge, to any person obtaining a copy
  4 +of this software and associated documentation files (the "Software"), to deal
  5 +in the Software without restriction, including without limitation the rights
  6 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7 +copies of the Software, and to permit persons to whom the Software is
  8 +furnished to do so, subject to the following conditions:
  9 +
  10 +The above copyright notice and this permission notice shall be included in
  11 +all copies or substantial portions of the Software.
  12 +
  13 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19 +THE SOFTWARE.
... ...
puppet/modules/apt/Modulefile 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +name 'puppetlabs-apt'
  2 +version '1.4.0'
  3 +source 'https://github.com/puppetlabs/puppetlabs-apt'
  4 +author 'Evolving Web / Puppet Labs'
  5 +license 'Apache License 2.0'
  6 +summary 'Puppet Labs Apt Module'
  7 +description 'APT Module for Puppet'
  8 +project_page 'https://github.com/puppetlabs/puppetlabs-apt'
  9 +
  10 +## Add dependencies, if any:
  11 +#dependency 'puppetlabs/stdlib', '2.x'
  12 +# The dependency should be written as above but librarian-puppet
  13 +# does not support the expression as the PMT does.
  14 +dependency 'puppetlabs/stdlib', '>= 2.2.1'
... ...
puppet/modules/apt/README.md 0 → 100644
... ... @@ -0,0 +1,226 @@
  1 +apt
  2 +===
  3 +
  4 +[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-apt.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-apt)
  5 +
  6 +## Description
  7 +Provides helpful definitions for dealing with Apt.
  8 +=======
  9 +Overview
  10 +--------
  11 +
  12 +The APT module provides a simple interface for managing APT source, key, and definitions with Puppet.
  13 +
  14 +Module Description
  15 +------------------
  16 +
  17 +APT automates obtaining and installing software packages on *nix systems.
  18 +
  19 +Setup
  20 +-----
  21 +
  22 +**What APT affects:**
  23 +
  24 +* package/service/configuration files for APT
  25 +* your system's `sources.list` file and `sources.list.d` directory
  26 + * 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'.
  27 +* system repositories
  28 +* authentication keys
  29 +* wget (optional)
  30 +
  31 +###Beginning with APT
  32 +
  33 +To begin using the APT module with default parameters, declare the class
  34 +
  35 + class { 'apt': }
  36 +
  37 +Puppet code that uses anything from the APT module requires that the core apt class be declared.
  38 +
  39 +Usage
  40 +-----
  41 +
  42 +Using the APT module consists predominantly in declaring classes that provide desired functionality and features.
  43 +
  44 +###apt
  45 +
  46 +`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.
  47 +
  48 +The parameters for `apt` are not required in general and are predominantly for development environment use-cases.
  49 +
  50 + class { 'apt':
  51 + always_apt_update => false,
  52 + disable_keys => undef,
  53 + proxy_host => false,
  54 + proxy_port => '8080',
  55 + purge_sources_list => false,
  56 + purge_sources_list_d => false,
  57 + purge_preferences_d => false,
  58 + update_timeout => undef
  59 + }
  60 +
  61 +Puppet will manage your system's `sources.list` file and `sources.list.d` directory but will do its best to respect existing content.
  62 +
  63 +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.
  64 +
  65 +###apt::builddep
  66 +
  67 +Installs the build depends of a specified package.
  68 +
  69 + apt::builddep { 'glusterfs-server': }
  70 +
  71 +###apt::force
  72 +
  73 +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.
  74 +
  75 + apt::force { 'glusterfs-server':
  76 + release => 'unstable',
  77 + version => '3.0.3',
  78 + require => Apt::Source['debian_unstable'],
  79 + }
  80 +
  81 +###apt::key
  82 +
  83 +Adds a key to the list of keys used by APT to authenticate packages.
  84 +
  85 + apt::key { 'puppetlabs':
  86 + key => '4BD6EC30',
  87 + key_server => 'pgp.mit.edu',
  88 + }
  89 +
  90 + apt::key { 'jenkins':
  91 + key => 'D50582E6',
  92 + key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
  93 + }
  94 +
  95 +Note that use of `key_source` requires wget to be installed and working.
  96 +
  97 +###apt::pin
  98 +
  99 +Adds an apt pin for a certain release.
  100 +
  101 + apt::pin { 'karmic': priority => 700 }
  102 + apt::pin { 'karmic-updates': priority => 700 }
  103 + apt::pin { 'karmic-security': priority => 700 }
  104 +
  105 +Note you can also specifying more complex pins using distribution properties.
  106 +
  107 + apt::pin { 'stable':
  108 + priority => -10,
  109 + originator => 'Debian',
  110 + release_version => '3.0',
  111 + component => 'main',
  112 + label => 'Debian'
  113 + }
  114 +
  115 +###apt::ppa
  116 +
  117 +Adds a ppa repository using `add-apt-repository`.
  118 +
  119 + apt::ppa { 'ppa:drizzle-developers/ppa': }
  120 +
  121 +###apt::release
  122 +
  123 +Sets the default apt release. This class is particularly useful when using repositories, like Debian, that are unstable in Ubuntu.
  124 +
  125 + class { 'apt::release':
  126 + release_id => 'precise',
  127 + }
  128 +
  129 +###apt::source
  130 +
  131 +Adds an apt source to `/etc/apt/sources.list.d/`.
  132 +
  133 + apt::source { 'debian_unstable':
  134 + location => 'http://debian.mirror.iweb.ca/debian/',
  135 + release => 'unstable',
  136 + repos => 'main contrib non-free',
  137 + required_packages => 'debian-keyring debian-archive-keyring',
  138 + key => '55BE302B',
  139 + key_server => 'subkeys.pgp.net',
  140 + pin => '-10',
  141 + include_src => true
  142 + }
  143 +
  144 +If you would like to configure your system so the source is the Puppet Labs APT repository
  145 +
  146 + apt::source { 'puppetlabs':
  147 + location => 'http://apt.puppetlabs.com',
  148 + repos => 'main',
  149 + key => '4BD6EC30',
  150 + key_server => 'pgp.mit.edu',
  151 + }
  152 +
  153 +###Testing
  154 +
  155 +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.
  156 +
  157 +####Example Test
  158 +
  159 +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
  160 +
  161 + apt::source { 'puppetlabs':
  162 + location => 'http://apt.puppetlabs.com',
  163 + repos => 'main',
  164 + key => '4BD6EC30',
  165 + key_server => 'pgp.mit.edu',
  166 + }
  167 +
  168 +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.
  169 +
  170 +Check your smoke test for syntax errors
  171 +
  172 + $ puppet parser validate tests/puppetlabs-apt.pp
  173 +
  174 +If you receive no output from that command, it means nothing is wrong. Then apply the code
  175 +
  176 + $ puppet apply --verbose tests/puppetlabs-apt.pp
  177 + notice: /Stage[main]//Apt::Source[puppetlabs]/File[puppetlabs.list]/ensure: defined content as '{md5}3be1da4923fb910f1102a233b77e982e'
  178 + info: /Stage[main]//Apt::Source[puppetlabs]/File[puppetlabs.list]: Scheduling refresh of Exec[puppetlabs apt update]
  179 + notice: /Stage[main]//Apt::Source[puppetlabs]/Exec[puppetlabs apt update]: Triggered 'refresh' from 1 events>
  180 +
  181 +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.
  182 +
  183 +Implementation
  184 +--------------
  185 +
  186 +###apt::backports
  187 +
  188 +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).
  189 +
  190 +Limitations
  191 +-----------
  192 +
  193 +This module should work across all versions of Debian/Ubuntu and support all major APT repository management features.
  194 +
  195 +Development
  196 +------------
  197 +
  198 +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.
  199 +
  200 +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.
  201 +
  202 +You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing)
  203 +
  204 +Contributors
  205 +------------
  206 +
  207 +A lot of great people have contributed to this module. A somewhat current list follows:
  208 +
  209 +* Ben Godfrey <ben.godfrey@wonga.com>
  210 +* Branan Purvine-Riley <branan@puppetlabs.com>
  211 +* Christian G. Warden <cwarden@xerus.org>
  212 +* Dan Bode <bodepd@gmail.com> <dan@puppetlabs.com>
  213 +* Garrett Honeycutt <github@garretthoneycutt.com>
  214 +* Jeff Wallace <jeff@evolvingweb.ca> <jeff@tjwallace.ca>
  215 +* Ken Barber <ken@bob.sh>
  216 +* Matthaus Litteken <matthaus@puppetlabs.com> <mlitteken@gmail.com>
  217 +* Matthias Pigulla <mp@webfactory.de>
  218 +* Monty Taylor <mordred@inaugust.com>
  219 +* Peter Drake <pdrake@allplayers.com>
  220 +* Reid Vandewiele <marut@cat.pdx.edu>
  221 +* Robert Navarro <rnavarro@phiivo.com>
  222 +* Ryan Coleman <ryan@puppetlabs.com>
  223 +* Scott McLeod <scott.mcleod@theice.com>
  224 +* Spencer Krum <spencer@puppetlabs.com>
  225 +* William Van Hevelingen <blkperl@cat.pdx.edu> <wvan13@gmail.com>
  226 +* Zach Leslie <zach@puppetlabs.com>
... ...
puppet/modules/apt/Rakefile 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +require 'puppetlabs_spec_helper/rake_tasks'
  2 +require 'rspec-system/rake_task'
... ...
puppet/modules/apt/manifests/backports.pp 0 → 100644
... ... @@ -0,0 +1,48 @@
  1 +# This adds the necessary components to get backports for ubuntu and debian
  2 +#
  3 +# == Parameters
  4 +#
  5 +# [*release*]
  6 +# The ubuntu/debian release name. Defaults to $lsbdistcodename. Setting this
  7 +# manually can cause undefined behavior. (Read: universe exploding)
  8 +#
  9 +# == Examples
  10 +#
  11 +# include apt::backports
  12 +#
  13 +# class { 'apt::backports':
  14 +# release => 'natty',
  15 +# }
  16 +#
  17 +# == Authors
  18 +#
  19 +# Ben Hughes, I think. At least blame him if this goes wrong.
  20 +# I just added puppet doc.
  21 +#
  22 +# == Copyright
  23 +#
  24 +# Copyright 2011 Puppet Labs Inc, unless otherwise noted.
  25 +class apt::backports(
  26 + $release = $::lsbdistcodename,
  27 + $location = $apt::params::backports_location
  28 +) inherits apt::params {
  29 +
  30 + $release_real = downcase($release)
  31 + $key = $::lsbdistid ? {
  32 + 'debian' => '55BE302B',
  33 + 'ubuntu' => '437D05B5',
  34 + }
  35 + $repos = $::lsbdistid ? {
  36 + 'debian' => 'main contrib non-free',
  37 + 'ubuntu' => 'main universe multiverse restricted',
  38 + }
  39 +
  40 + apt::source { 'backports':
  41 + location => $location,
  42 + release => "${release_real}-backports",
  43 + repos => $repos,
  44 + key => $key,
  45 + key_server => 'pgp.mit.edu',
  46 + pin => '200',
  47 + }
  48 +}
... ...
puppet/modules/apt/manifests/builddep.pp 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +# builddep.pp
  2 +
  3 +define apt::builddep() {
  4 + include apt::update
  5 +
  6 + exec { "apt-builddep-${name}":
  7 + command => "/usr/bin/apt-get -y --force-yes build-dep ${name}",
  8 + logoutput => 'on_failure',
  9 + notify => Exec['apt_update'],
  10 + }
  11 +
  12 + # Need anchor to provide containment for dependencies.
  13 + anchor { "apt::builddep::${name}":
  14 + require => Class['apt::update'],
  15 + }
  16 +}
... ...
puppet/modules/apt/manifests/conf.pp 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +define apt::conf (
  2 + $content,
  3 + $ensure = present,
  4 + $priority = '50'
  5 +) {
  6 +
  7 + include apt::params
  8 +
  9 + $apt_conf_d = $apt::params::apt_conf_d
  10 +
  11 + file { "${apt_conf_d}/${priority}${name}":
  12 + ensure => $ensure,
  13 + content => $content,
  14 + owner => root,
  15 + group => root,
  16 + mode => '0644',
  17 + }
  18 +}
... ...
puppet/modules/apt/manifests/debian/testing.pp 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +# testing.pp
  2 +
  3 +class apt::debian::testing {
  4 + include apt
  5 +
  6 + # deb http://debian.mirror.iweb.ca/debian/ testing main contrib non-free
  7 + # deb-src http://debian.mirror.iweb.ca/debian/ testing main contrib non-free
  8 + # Key: 55BE302B Server: subkeys.pgp.net
  9 + # debian-keyring
  10 + # debian-archive-keyring
  11 +
  12 + apt::source { 'debian_testing':
  13 + location => 'http://debian.mirror.iweb.ca/debian/',
  14 + release => 'testing',
  15 + repos => 'main contrib non-free',
  16 + required_packages => 'debian-keyring debian-archive-keyring',
  17 + key => '55BE302B',
  18 + key_server => 'subkeys.pgp.net',
  19 + pin => '-10',
  20 + }
  21 +}
... ...
puppet/modules/apt/manifests/debian/unstable.pp 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +# unstable.pp
  2 +
  3 +class apt::debian::unstable {
  4 + include apt
  5 +
  6 + # deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
  7 + # deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
  8 + # Key: 55BE302B Server: subkeys.pgp.net
  9 + # debian-keyring
  10 + # debian-archive-keyring
  11 +
  12 + apt::source { 'debian_unstable':
  13 + location => 'http://debian.mirror.iweb.ca/debian/',
  14 + release => 'unstable',
  15 + repos => 'main contrib non-free',
  16 + required_packages => 'debian-keyring debian-archive-keyring',
  17 + key => '55BE302B',
  18 + key_server => 'subkeys.pgp.net',
  19 + pin => '-10',
  20 + }
  21 +}
... ...
puppet/modules/apt/manifests/force.pp 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +# force.pp
  2 +# force a package from a specific release
  3 +
  4 +define apt::force(
  5 + $release = 'testing',
  6 + $version = false,
  7 + $timeout = 300
  8 +) {
  9 +
  10 + $version_string = $version ? {
  11 + false => undef,
  12 + default => "=${version}",
  13 + }
  14 +
  15 + $install_check = $version ? {
  16 + false => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'",
  17 + default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'",
  18 + }
  19 + exec { "/usr/bin/apt-get -y -t ${release} install ${name}${version_string}":
  20 + unless => $install_check,
  21 + logoutput => 'on_failure',
  22 + timeout => $timeout,
  23 + }
  24 +}
... ...
puppet/modules/apt/manifests/init.pp 0 → 100644
... ... @@ -0,0 +1,121 @@
  1 +# Class: apt
  2 +#
  3 +# This module manages the initial configuration of apt.
  4 +#
  5 +# Parameters:
  6 +# The parameters listed here are not required in general and were
  7 +# added for use cases related to development environments.
  8 +# disable_keys - disables the requirement for all packages to be signed
  9 +# always_apt_update - rather apt should be updated on every run (intended
  10 +# for development environments where package updates are frequent)
  11 +# purge_sources_list - Accepts true or false. Defaults to false If set to
  12 +# true, Puppet will purge all unmanaged entries from sources.list
  13 +# purge_sources_list_d - Accepts true or false. Defaults to false. If set
  14 +# to true, Puppet will purge all unmanaged entries from sources.list.d
  15 +# update_timeout - Overrides the exec timeout in seconds for apt-get update.
  16 +# If not set defaults to Exec's default (300)
  17 +#
  18 +# Actions:
  19 +#
  20 +# Requires:
  21 +# puppetlabs/stdlib
  22 +# Sample Usage:
  23 +# class { 'apt': }
  24 +
  25 +class apt(
  26 + $always_apt_update = false,
  27 + $disable_keys = undef,
  28 + $proxy_host = false,
  29 + $proxy_port = '8080',
  30 + $purge_sources_list = false,
  31 + $purge_sources_list_d = false,
  32 + $purge_preferences_d = false,
  33 + $update_timeout = undef
  34 +) {
  35 +
  36 + include apt::params
  37 + include apt::update
  38 +
  39 + validate_bool($purge_sources_list, $purge_sources_list_d, $purge_preferences_d)
  40 +
  41 + $sources_list_content = $purge_sources_list ? {
  42 + false => undef,
  43 + true => "# Repos managed by puppet.\n",
  44 + }
  45 +
  46 + if $always_apt_update == true {
  47 + Exec <| title=='apt_update' |> {
  48 + refreshonly => false,
  49 + }
  50 + }
  51 +
  52 + $root = $apt::params::root
  53 + $apt_conf_d = $apt::params::apt_conf_d
  54 + $sources_list_d = $apt::params::sources_list_d
  55 + $preferences_d = $apt::params::preferences_d
  56 + $provider = $apt::params::provider
  57 +
  58 + file { 'sources.list':
  59 + ensure => present,
  60 + path => "${root}/sources.list",
  61 + owner => root,
  62 + group => root,
  63 + mode => '0644',
  64 + content => $sources_list_content,
  65 + notify => Exec['apt_update'],
  66 + }
  67 +
  68 + file { 'sources.list.d':
  69 + ensure => directory,
  70 + path => $sources_list_d,
  71 + owner => root,
  72 + group => root,
  73 + purge => $purge_sources_list_d,
  74 + recurse => $purge_sources_list_d,
  75 + notify => Exec['apt_update'],
  76 + }
  77 +
  78 + file { 'preferences.d':
  79 + ensure => directory,
  80 + path => $preferences_d,
  81 + owner => root,
  82 + group => root,
  83 + purge => $purge_preferences_d,
  84 + recurse => $purge_preferences_d,
  85 + }
  86 +
  87 + case $disable_keys {
  88 + true: {
  89 + file { '99unauth':
  90 + ensure => present,
  91 + content => "APT::Get::AllowUnauthenticated 1;\n",
  92 + path => "${apt_conf_d}/99unauth",
  93 + }
  94 + }
  95 + false: {
  96 + file { '99unauth':
  97 + ensure => absent,
  98 + path => "${apt_conf_d}/99unauth",
  99 + }
  100 + }
  101 + undef: { } # do nothing
  102 + default: { fail('Valid values for disable_keys are true or false') }
  103 + }
  104 +
  105 + $proxy_set = $proxy_host ? {
  106 + false => absent,
  107 + default => present
  108 + }
  109 +
  110 + file { 'configure-apt-proxy':
  111 + ensure => $proxy_set,
  112 + path => "${apt_conf_d}/proxy",
  113 + content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
  114 + notify => Exec['apt_update'],
  115 + }
  116 +
  117 + # Need anchor to provide containment for dependencies.
  118 + anchor { 'apt::update':
  119 + require => Class['apt::update'],
  120 + }
  121 +}
... ...
puppet/modules/apt/manifests/key.pp 0 → 100644
... ... @@ -0,0 +1,90 @@
  1 +define apt::key (
  2 + $key = $title,
  3 + $ensure = present,
  4 + $key_content = false,
  5 + $key_source = false,
  6 + $key_server = 'keyserver.ubuntu.com',
  7 + $key_options = false
  8 +) {
  9 +
  10 + include apt::params
  11 +
  12 + $upkey = upcase($key)
  13 + # trim the key to the last 8 chars so we can match longer keys with apt-key list too
  14 + $trimmedkey = regsubst($upkey, '^.*(.{8})$', '\1')
  15 +
  16 + if $key_content {
  17 + $method = 'content'
  18 + } elsif $key_source {
  19 + $method = 'source'
  20 + } elsif $key_server {
  21 + $method = 'server'
  22 + }
  23 +
  24 + # This is a hash of the parts of the key definition that we care about.
  25 + # It is used as a unique identifier for this instance of apt::key. It gets
  26 + # hashed to ensure that the resource name doesn't end up being pages and
  27 + # pages (e.g. in the situation where key_content is specified).
  28 + $digest = sha1("${upkey}/${key_content}/${key_source}/${key_server}/")
  29 +
  30 + # Allow multiple ensure => present for the same key to account for many
  31 + # apt::source resources that all reference the same key.
  32 + case $ensure {
  33 + present: {
  34 +
  35 + anchor { "apt::key/${title}": }
  36 +
  37 + if defined(Exec["apt::key ${upkey} absent"]) {
  38 + fail("Cannot ensure Apt::Key[${upkey}] present; ${upkey} already ensured absent")
  39 + }
  40 +
  41 + if !defined(Anchor["apt::key ${upkey} present"]) {
  42 + anchor { "apt::key ${upkey} present": }
  43 + }
  44 +
  45 + if $key_options{
  46 + $options_string = "--keyserver-options ${key_options}"
  47 + }
  48 + else{
  49 + $options_string = ''
  50 + }
  51 +
  52 + if !defined(Exec[$digest]) {
  53 + $digest_command = $method ? {
  54 + 'content' => "echo '${key_content}' | /usr/bin/apt-key add -",
  55 + 'source' => "wget -q '${key_source}' -O- | apt-key add -",
  56 + 'server' => "apt-key adv --keyserver '${key_server}' ${options_string} --recv-keys '${upkey}'",
  57 + }
  58 + exec { $digest:
  59 + command => $digest_command,
  60 + path => '/bin:/usr/bin',
  61 + unless => "/usr/bin/apt-key list | /bin/grep '${trimmedkey}'",
  62 + logoutput => 'on_failure',
  63 + before => Anchor["apt::key ${upkey} present"],
  64 + }
  65 + }
  66 +
  67 + Anchor["apt::key ${upkey} present"] -> Anchor["apt::key/${title}"]
  68 +
  69 + }
  70 + absent: {
  71 +
  72 + if defined(Anchor["apt::key ${upkey} present"]) {
  73 + fail("Cannot ensure Apt::Key[${upkey}] absent; ${upkey} already ensured present")
  74 + }
  75 +
  76 + exec { "apt::key ${upkey} absent":
  77 + command => "apt-key del '${upkey}'",
  78 + path => '/bin:/usr/bin',
  79 + onlyif => "apt-key list | grep '${trimmedkey}'",
  80 + user => 'root',
  81 + group => 'root',
  82 + logoutput => 'on_failure',
  83 + }
  84 + }
  85 +
  86 + default: {
  87 + fail "Invalid 'ensure' value '${ensure}' for aptkey"
  88 + }
  89 + }
  90 +}
... ...
puppet/modules/apt/manifests/params.pp 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +class apt::params {
  2 + $root = '/etc/apt'
  3 + $provider = '/usr/bin/apt-get'
  4 + $sources_list_d = "${root}/sources.list.d"
  5 + $apt_conf_d = "${root}/apt.conf.d"
  6 + $preferences_d = "${root}/preferences.d"
  7 +
  8 + case $::lsbdistid {
  9 + 'debian': {
  10 + case $::lsbdistcodename {
  11 + 'squeeze': {
  12 + $backports_location = 'http://backports.debian.org/debian-backports'
  13 + }
  14 + 'wheezy': {
  15 + $backports_location = 'http://ftp.debian.org/debian/'
  16 + }
  17 + default: {
  18 + $backports_location = 'http://http.debian.net/debian/'
  19 + }
  20 + }
  21 + }
  22 + 'ubuntu': {
  23 + case $::lsbdistcodename {
  24 + 'hardy','lucid','maverick','natty','oneiric','precise': {
  25 + $backports_location = 'http://us.archive.ubuntu.com/ubuntu'
  26 + }
  27 + default: {
  28 + $backports_location = 'http://old-releases.ubuntu.com/ubuntu'
  29 + }
  30 + }
  31 + }
  32 + }
  33 +}
... ...
puppet/modules/apt/manifests/pin.pp 0 → 100644
... ... @@ -0,0 +1,73 @@
  1 +# pin.pp
  2 +# pin a release in apt, useful for unstable repositories
  3 +
  4 +define apt::pin(
  5 + $ensure = present,
  6 + $explanation = "${::caller_module_name}: ${name}",
  7 + $order = '',
  8 + $packages = '*',
  9 + $priority = 0,
  10 + $release = '', # a=
  11 + $origin = '',
  12 + $version = '',
  13 + $codename = '', # n=
  14 + $release_version = '', # v=
  15 + $component = '', # c=
  16 + $originator = '', # o=
  17 + $label = '' # l=
  18 +) {
  19 +
  20 + include apt::params
  21 +
  22 + $preferences_d = $apt::params::preferences_d
  23 +
  24 + if $order != '' and !is_integer($order) {
  25 + fail('Only integers are allowed in the apt::pin order param')
  26 + }
  27 +
  28 + $pin_release_array = [
  29 + $release,
  30 + $codename,
  31 + $release_version,
  32 + $component,
  33 + $originator,
  34 + $label]
  35 + $pin_release = join($pin_release_array, '')
  36 +
  37 + # Read the manpage 'apt_preferences(5)', especially the chapter
  38 + # 'Thea Effect of APT Preferences' to understand the following logic
  39 + # and the difference between specific and general form
  40 + if $packages != '*' { # specific form
  41 +
  42 + if ( $pin_release != '' and ( $origin != '' or $version != '' )) or
  43 + ( $origin != '' and ( $pin_release != '' or $version != '' )) or
  44 + ( $version != '' and ( $pin_release != '' or $origin != '' )) {
  45 + fail('parameters release, origin, and version are mutually exclusive')
  46 + }
  47 +
  48 + } else { # general form
  49 +
  50 + if $version != '' {
  51 + fail('parameter version cannot be used in general form')
  52 + }
  53 +
  54 + if ( $pin_release != '' and $origin != '' ) or
  55 + ( $origin != '' and $pin_release != '' ) {
  56 + fail('parmeters release and origin are mutually exclusive')
  57 + }
  58 +
  59 + }
  60 +
  61 + $path = $order ? {
  62 + '' => "${preferences_d}/${name}.pref",
  63 + default => "${preferences_d}/${order}-${name}.pref",
  64 + }
  65 + file { "${name}.pref":
  66 + ensure => $ensure,
  67 + path => $path,
  68 + owner => root,
  69 + group => root,
  70 + mode => '0644',
  71 + content => template('apt/pin.pref.erb'),
  72 + }
  73 +}
... ...
puppet/modules/apt/manifests/ppa.pp 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +# ppa.pp
  2 +
  3 +define apt::ppa(
  4 + $release = $::lsbdistcodename,
  5 + $options = '-y'
  6 +) {
  7 + include apt::params
  8 + include apt::update
  9 +
  10 + $sources_list_d = $apt::params::sources_list_d
  11 +
  12 + if ! $release {
  13 + fail('lsbdistcodename fact not available: release parameter required')
  14 + }
  15 +
  16 + $filename_without_slashes = regsubst($name, '/', '-', 'G')
  17 + $filename_without_dots = regsubst($filename_without_slashes, '\.', '_', 'G')
  18 + $filename_without_ppa = regsubst($filename_without_dots, '^ppa:', '', 'G')
  19 + $sources_list_d_filename = "${filename_without_ppa}-${release}.list"
  20 +
  21 + $package = $::lsbdistrelease ? {
  22 + /^[1-9]\..*|1[01]\..*|12.04$/ => 'python-software-properties',
  23 + default => 'software-properties-common',
  24 + }
  25 +
  26 + if ! defined(Package[$package]) {
  27 + package { $package: }
  28 + }
  29 +
  30 + if defined(Class[apt]) {
  31 + $proxy_host = getparam(Class[apt], 'proxy_host')
  32 + $proxy_port = getparam(Class[apt], 'proxy_port')
  33 + case $proxy_host {
  34 + false, '': {
  35 + $proxy_env = []
  36 + }
  37 + default: {$proxy_env = ["http_proxy=http://${proxy_host}:${proxy_port}", "https_proxy=http://${proxy_host}:${proxy_port}"]}
  38 + }
  39 + } else {
  40 + $proxy_env = []
  41 + }
  42 + exec { "add-apt-repository-${name}":
  43 + environment => $proxy_env,
  44 + command => "/usr/bin/add-apt-repository ${options} ${name}",
  45 + unless => "/usr/bin/test -s ${sources_list_d}/${sources_list_d_filename}",
  46 + logoutput => 'on_failure',
  47 + notify => Exec['apt_update'],
  48 + require => [
  49 + File[$sources_list_d],
  50 + Package[$package],
  51 + ],
  52 + }
  53 +
  54 + file { "${sources_list_d}/${sources_list_d_filename}":
  55 + ensure => file,
  56 + require => Exec["add-apt-repository-${name}"],
  57 + }
  58 +
  59 + # Need anchor to provide containment for dependencies.
  60 + anchor { "apt::ppa::${name}":
  61 + require => Class['apt::update'],
  62 + }
  63 +}
... ...
puppet/modules/apt/manifests/release.pp 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +# release.pp
  2 +
  3 +class apt::release (
  4 + $release_id
  5 +) {
  6 +
  7 + include apt::params
  8 +
  9 + $root = $apt::params::root
  10 +
  11 + file { "${root}/apt.conf.d/01release":
  12 + owner => root,
  13 + group => root,
  14 + mode => '0644',
  15 + content => "APT::Default-Release \"${release_id}\";"
  16 + }
  17 +}
... ...
puppet/modules/apt/manifests/source.pp 0 → 100644
... ... @@ -0,0 +1,85 @@
  1 +# source.pp
  2 +# add an apt source
  3 +
  4 +define apt::source(
  5 + $ensure = present,
  6 + $location = '',
  7 + $release = 'UNDEF',
  8 + $repos = 'main',
  9 + $include_src = true,
  10 + $required_packages = false,
  11 + $key = false,
  12 + $key_server = 'keyserver.ubuntu.com',
  13 + $key_content = false,
  14 + $key_source = false,
  15 + $pin = false,
  16 + $architecture = undef
  17 +) {
  18 +
  19 + include apt::params
  20 + include apt::update
  21 +
  22 + $sources_list_d = $apt::params::sources_list_d
  23 + $provider = $apt::params::provider
  24 +
  25 + if $release == 'UNDEF' {
  26 + if $::lsbdistcodename == undef {
  27 + fail('lsbdistcodename fact not available: release parameter required')
  28 + } else {
  29 + $release_real = $::lsbdistcodename
  30 + }
  31 + } else {
  32 + $release_real = $release
  33 + }
  34 +
  35 + file { "${name}.list":
  36 + ensure => $ensure,
  37 + path => "${sources_list_d}/${name}.list",
  38 + owner => root,
  39 + group => root,
  40 + mode => '0644',
  41 + content => template("${module_name}/source.list.erb"),
  42 + notify => Exec['apt_update'],
  43 + }
  44 +
  45 +
  46 + if ($pin != false) {
  47 + # Get the host portion out of the url so we can pin to origin
  48 + $url_split = split($location, '/')
  49 + $host = $url_split[2]
  50 +
  51 + apt::pin { $name:
  52 + ensure => $ensure,
  53 + priority => $pin,
  54 + before => File["${name}.list"],
  55 + origin => $host,
  56 + }
  57 + }
  58 +
  59 + if ($required_packages != false) and ($ensure == 'present') {
  60 + exec { "Required packages: '${required_packages}' for ${name}":
  61 + command => "${provider} -y install ${required_packages}",
  62 + logoutput => 'on_failure',
  63 + refreshonly => true,
  64 + subscribe => File["${name}.list"],
  65 + before => Exec['apt_update'],
  66 + }
  67 + }
  68 +
  69 + # We do not want to remove keys when the source is absent.
  70 + if ($key != false) and ($ensure == 'present') {
  71 + apt::key { "Add key: ${key} from Apt::Source ${title}":
  72 + ensure => present,
  73 + key => $key,
  74 + key_server => $key_server,
  75 + key_content => $key_content,
  76 + key_source => $key_source,
  77 + before => File["${name}.list"],
  78 + }
  79 + }
  80 +
  81 + # Need anchor to provide containment for dependencies.
  82 + anchor { "apt::source::${name}":
  83 + require => Class['apt::update'],
  84 + }
  85 +}
... ...
puppet/modules/apt/manifests/unattended_upgrades.pp 0 → 100644
... ... @@ -0,0 +1,68 @@
  1 +# Class: apt::unattended_upgrades
  2 +#
  3 +# This class manages the unattended-upgrades package and related configuration
  4 +# files for ubuntu
  5 +#
  6 +# origins are the repositories to automatically upgrade included packages
  7 +# blacklist is a list of packages to not automatically upgrade
  8 +# update is how often to run "apt-get update" in days
  9 +# download is how often to run "apt-get upgrade --download-only" in days
  10 +# upgrade is how often to upgrade packages included in the origins list in days
  11 +# autoclean is how often to run "apt-get autoclean" in days
  12 +#
  13 +# information on the other options can be found in the 50unattended-upgrades
  14 +# file and in /etc/cron.daily/apt
  15 +#
  16 +class apt::unattended_upgrades (
  17 + $origins = ['${distro_id}:${distro_codename}-security'],
  18 + $blacklist = [],
  19 + $update = "1",
  20 + $download = "1",
  21 + $upgrade = "1",
  22 + $autoclean = "7",
  23 + $auto_fix = true,
  24 + $minimal_steps = false,
  25 + $install_on_shutdown = false,
  26 + $mail_to = "NONE",
  27 + $mail_only_on_error = false,
  28 + $remove_unused = true,
  29 + $auto_reboot = false,
  30 + $dl_limit = "NONE",
  31 + $enable = "1",
  32 + $backup_interval = "0",
  33 + $backup_level = "3",
  34 + $max_age = "0",
  35 + $min_age = "0",
  36 + $max_size = "0",
  37 + $download_delta = "0",
  38 + $verbose = "0",
  39 +) {
  40 +
  41 + validate_bool(
  42 + $auto_fix,
  43 + $minimal_steps,
  44 + $install_on_shutdown,
  45 + $mail_only_on_error,
  46 + $remove_unused,
  47 + $auto_reboot
  48 + )
  49 +
  50 + package { 'unattended-upgrades':
  51 + ensure => present,
  52 + }
  53 +
  54 + File {
  55 + ensure => file,
  56 + owner => 'root',
  57 + group => 'root',
  58 + mode => '0644',
  59 + require => Package['unattended-upgrades'],
  60 + }
  61 +
  62 + file {
  63 + '/etc/apt/apt.conf.d/50unattended-upgrades':
  64 + content => template('apt/50unattended-upgrades.erb');
  65 + '/etc/apt/apt.conf.d/10periodic':
  66 + content => template('apt/10periodic.erb');
  67 + }
  68 +}
... ...
puppet/modules/apt/manifests/update.pp 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class apt::update {
  2 + include apt::params
  3 +
  4 + exec { 'apt_update':
  5 + command => "${apt::params::provider} update",
  6 + logoutput => 'on_failure',
  7 + refreshonly => true,
  8 + timeout => $apt::update_timeout,
  9 + }
  10 +}
... ...
puppet/modules/apt/metadata.json 0 → 100644
... ... @@ -0,0 +1,87 @@
  1 +{
  2 + "name": "puppetlabs-apt",
  3 + "version": "1.4.0",
  4 + "summary": "Puppet Labs Apt Module",
  5 + "author": "Evolving Web / Puppet Labs",
  6 + "description": "APT Module for Puppet",
  7 + "dependencies": [
  8 + {
  9 + "name": "puppetlabs/stdlib",
  10 + "version_requirement": "\u003e\u003d 2.2.1"
  11 + }
  12 + ],
  13 + "types": [],
  14 + "checksums": {
  15 + ".bundle/config": "7f1c988748783d2a8d455376eed1470c",
  16 + ".fixtures.yml": "0c43f56b0bb8e8d04e8051a0e7aa37a5",
  17 + ".forge-release/pom.xml": "c650a84961ad88de03192e23b63b3549",
  18 + ".forge-release/publish": "1c1d6dd64ef52246db485eb5459aa941",
  19 + ".forge-release/settings.xml": "06d768a57d582fe1ee078b563427e750",
  20 + ".forge-release/validate": "7fffde8112f42a1ec986d49ba80ac219",
  21 + ".nodeset.yml": "78d78c172336a387a1067464434ffbcb",
  22 + ".travis.yml": "782420dcc9d6412c79c30f03b1f3613c",
  23 + "CHANGELOG": "f5488e1e891a8f8c47143dac790ddab3",
  24 + "Gemfile": "1bfa7eb6e30346c9ddb4a8b144b0d255",
  25 + "Gemfile.lock": "8ff8bc3d32bb7412bd97e48190a93b2f",
  26 + "LICENSE": "20bcc606fc61ffba2b8cea840e8dce4d",
  27 + "Modulefile": "b34e93626fbc137cbb651952e7509839",
  28 + "README.md": "65176b395f7202fe5d222ae7b0de4e05",
  29 + "Rakefile": "0428ea3759a4692c91604396c406a9c1",
  30 + "manifests/backports.pp": "09f1d86603d0f44a2169acb3eeea2a70",
  31 + "manifests/builddep.pp": "4f313b5140c84aa7d5793b5a073c30dd",
  32 + "manifests/conf.pp": "5ddf258195d414d93284dfd281a8d6e3",
  33 + "manifests/debian/testing.pp": "aeb625bacb6a8df46c864ee9ee1cb5a5",
  34 + "manifests/debian/unstable.pp": "108038596b05dc1d28975884693f73f5",
  35 + "manifests/force.pp": "cf871e869f4114f32ab164de2a67e7e2",
  36 + "manifests/init.pp": "5ec106a7a03313c544159a9a1f6b78e6",
  37 + "manifests/key.pp": "3cf082ed91a3933ab7218d1be3464f4f",
  38 + "manifests/params.pp": "ca4ce3730a65c43f884ab3e6445f1661",
  39 + "manifests/pin.pp": "dea8cbaabc37010ce25838080608802b",
  40 + "manifests/ppa.pp": "754a83944ae79b5001fc0c0a8c775985",
  41 + "manifests/release.pp": "427f3ee70a6a1e55fa291e58655bd5d9",
  42 + "manifests/source.pp": "6eab8d33c173a066f5dec8474efdedb6",
  43 + "manifests/unattended_upgrades.pp": "e97f908b42010ff9a85be4afd2c721ab",
  44 + "manifests/update.pp": "436c79f160f2cb603710795a9ec71ac7",
  45 + "spec/classes/apt_spec.rb": "54841b04b42026770ed6d744a82c55df",
  46 + "spec/classes/backports_spec.rb": "7d2454a881cc26edd3dcd3acb7ffd20f",
  47 + "spec/classes/debian_testing_spec.rb": "fad1384cb9d3c99b2663d7df4762dc0e",
  48 + "spec/classes/debian_unstable_spec.rb": "11131efffd18db3c96e2bbe3d98a2fb7",
  49 + "spec/classes/params_spec.rb": "a25396d3f0bbac784a7951f03ad7e8f4",
  50 + "spec/classes/release_spec.rb": "d8f01a3cf0c2f6f6952b835196163ce4",
  51 + "spec/classes/unattended_upgrades_spec.rb": "a2e206bda79d24cdb43312d035eff66f",
  52 + "spec/defines/builddep_spec.rb": "e1300bb4f3abbd34029b11d8b733a6e5",
  53 + "spec/defines/conf_spec.rb": "b7fc9fb6cb270c276aacbfa4a43f228c",
  54 + "spec/defines/force_spec.rb": "97098c5b123be49e321e71cda288fe53",
  55 + "spec/defines/key_spec.rb": "7800c30647b1ddf799b991110109cba0",
  56 + "spec/defines/pin_spec.rb": "c912e59e9e3d1145280d659cccabe72b",
  57 + "spec/defines/ppa_spec.rb": "72ce037a1d6ea0a33f369b1f3d98b3d6",
  58 + "spec/defines/source_spec.rb": "e553bb9598dbe2becba6ae7f91d4deb0",
  59 + "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc",
  60 + "spec/spec_helper_system.rb": "e67d2574baae312f1095f90d78fdf5e9",
  61 + "spec/system/apt_builddep_spec.rb": "97be5a48d2d16d96cb7c35ccdbcdcb69",
  62 + "spec/system/apt_key_spec.rb": "098835d0c53c69390d4c3b6ea8ef3815",
  63 + "spec/system/apt_ppa_spec.rb": "c96f6d0bbdafac39beaf0d5e6eba9010",
  64 + "spec/system/apt_source_spec.rb": "df5aa98b03688884903c564bb507469f",
  65 + "spec/system/basic_spec.rb": "0a5b33d18254bedcb7886e34846ebff6",
  66 + "spec/system/class_spec.rb": "2ba4265236f00685c23cb00f908defc1",
  67 + "templates/10periodic.erb": "2aeea866a39f19a62254abbb4f1bc59d",
  68 + "templates/50unattended-upgrades.erb": "ae995ade214fdaefab51d335c85819ae",
  69 + "templates/pin.pref.erb": "623249839cee7788fa0805a3474396db",
  70 + "templates/source.list.erb": "65a016e60daf065c481f3d5f2c883324",
  71 + "tests/builddep.pp": "4773f57072111e58f2ed833fa4489a88",
  72 + "tests/debian/testing.pp": "1cbee56baddd6a91d981db8fddec70fb",
  73 + "tests/debian/unstable.pp": "4b2a090afeb315752262386f4dbcd8ca",
  74 + "tests/force.pp": "2bb6cf0b3d655cb51f95aeb79035e600",
  75 + "tests/init.pp": "551138eb704e71ab3687932dda429a81",
  76 + "tests/key.pp": "371a695e1332d51a38e283a87be52798",
  77 + "tests/params.pp": "900db40f3fc84b0be173278df2ebff35",
  78 + "tests/pin.pp": "4b4c3612d75a19dba8eb7227070fa4ab",
  79 + "tests/ppa.pp": "b902cce8159128b5e8b21bed540743ff",
  80 + "tests/release.pp": "53ce5debe6fa5bee42821767599cc768",
  81 + "tests/source.pp": "9cecd9aa0dcde250fe49be9e26971a98",
  82 + "tests/unattended-upgrades.pp": "cdc853f1b58e5206c5a538621ddca161"
  83 + },
  84 + "source": "https://github.com/puppetlabs/puppetlabs-apt",
  85 + "project_page": "https://github.com/puppetlabs/puppetlabs-apt",
  86 + "license": "Apache License 2.0"
  87 +}
0 88 \ No newline at end of file
... ...
puppet/modules/apt/spec/classes/apt_spec.rb 0 → 100644
... ... @@ -0,0 +1,133 @@
  1 +require 'spec_helper'
  2 +describe 'apt', :type => :class do
  3 + let :default_params do
  4 + {
  5 + :disable_keys => :undef,
  6 + :always_apt_update => false,
  7 + :purge_sources_list => false,
  8 + :purge_sources_list_d => false,
  9 + }
  10 + end
  11 +
  12 + [{},
  13 + {
  14 + :disable_keys => true,
  15 + :always_apt_update => true,
  16 + :proxy_host => true,
  17 + :proxy_port => '3128',
  18 + :purge_sources_list => true,
  19 + :purge_sources_list_d => true,
  20 + },
  21 + {
  22 + :disable_keys => false
  23 + }
  24 + ].each do |param_set|
  25 + describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
  26 + let :param_hash do
  27 + default_params.merge(param_set)
  28 + end
  29 +
  30 + let :params do
  31 + param_set
  32 + end
  33 +
  34 + let :refresh_only_apt_update do
  35 + if param_hash[:always_apt_update]
  36 + false
  37 + else
  38 + true
  39 + end
  40 + end
  41 +
  42 + it { should include_class("apt::params") }
  43 +
  44 + it {
  45 + if param_hash[:purge_sources_list]
  46 + should contain_file("sources.list").with({
  47 + 'path' => "/etc/apt/sources.list",
  48 + 'ensure' => "present",
  49 + 'owner' => "root",
  50 + 'group' => "root",
  51 + 'mode' => "0644",
  52 + "content" => "# Repos managed by puppet.\n"
  53 + })
  54 + else
  55 + should contain_file("sources.list").with({
  56 + 'path' => "/etc/apt/sources.list",
  57 + 'ensure' => "present",
  58 + 'owner' => "root",
  59 + 'group' => "root",
  60 + 'mode' => "0644",
  61 + 'content' => nil
  62 + })
  63 + end
  64 + }
  65 + it {
  66 + if param_hash[:purge_sources_list_d]
  67 + should create_file("sources.list.d").with({
  68 + 'path' => "/etc/apt/sources.list.d",
  69 + 'ensure' => "directory",
  70 + 'owner' => "root",
  71 + 'group' => "root",
  72 + 'purge' => true,
  73 + 'recurse' => true,
  74 + 'notify' => 'Exec[apt_update]'
  75 + })
  76 + else
  77 + should create_file("sources.list.d").with({
  78 + 'path' => "/etc/apt/sources.list.d",
  79 + 'ensure' => "directory",
  80 + 'owner' => "root",
  81 + 'group' => "root",
  82 + 'purge' => false,
  83 + 'recurse' => false,
  84 + 'notify' => 'Exec[apt_update]'
  85 + })
  86 + end
  87 + }
  88 +
  89 + it {
  90 + should contain_exec("apt_update").with({
  91 + 'command' => "/usr/bin/apt-get update",
  92 + 'refreshonly' => refresh_only_apt_update
  93 + })
  94 + }
  95 +
  96 + it {
  97 + if param_hash[:disable_keys] == true
  98 + should create_file("99unauth").with({
  99 + 'content' => "APT::Get::AllowUnauthenticated 1;\n",
  100 + 'ensure' => "present",
  101 + 'path' => "/etc/apt/apt.conf.d/99unauth"
  102 + })
  103 + elsif param_hash[:disable_keys] == false
  104 + should create_file("99unauth").with({
  105 + 'ensure' => "absent",
  106 + 'path' => "/etc/apt/apt.conf.d/99unauth"
  107 + })
  108 + elsif param_hash[:disable_keys] != :undef
  109 + should_not create_file("99unauth").with({
  110 + 'path' => "/etc/apt/apt.conf.d/99unauth"
  111 + })
  112 + end
  113 + }
  114 + describe 'when setting a proxy' do
  115 + it {
  116 + if param_hash[:proxy_host]
  117 + should contain_file('configure-apt-proxy').with(
  118 + 'path' => '/etc/apt/apt.conf.d/proxy',
  119 + 'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";",
  120 + 'notify' => "Exec[apt_update]"
  121 + )
  122 + else
  123 + should contain_file('configure-apt-proxy').with(
  124 + 'path' => '/etc/apt/apt.conf.d/proxy',
  125 + 'notify' => 'Exec[apt_update]',
  126 + 'ensure' => 'absent'
  127 + )
  128 + end
  129 + }
  130 + end
  131 + end
  132 + end
  133 +end
... ...
puppet/modules/apt/spec/classes/backports_spec.rb 0 → 100644
... ... @@ -0,0 +1,71 @@
  1 +require 'spec_helper'
  2 +describe 'apt::backports', :type => :class do
  3 +
  4 + describe 'when turning on backports for ubuntu karmic' do
  5 +
  6 + let :facts do
  7 + {
  8 + 'lsbdistcodename' => 'Karmic',
  9 + 'lsbdistid' => 'Ubuntu'
  10 + }
  11 + end
  12 +
  13 + it { should contain_apt__source('backports').with({
  14 + 'location' => 'http://old-releases.ubuntu.com/ubuntu',
  15 + 'release' => 'karmic-backports',
  16 + 'repos' => 'main universe multiverse restricted',
  17 + 'key' => '437D05B5',
  18 + 'key_server' => 'pgp.mit.edu',
  19 + 'pin' => '200',
  20 + })
  21 + }
  22 + end
  23 +
  24 + describe "when turning on backports for debian squeeze" do
  25 +
  26 + let :facts do
  27 + {
  28 + 'lsbdistcodename' => 'Squeeze',
  29 + 'lsbdistid' => 'Debian',
  30 + }
  31 + end
  32 +
  33 + it { should contain_apt__source('backports').with({
  34 + 'location' => 'http://backports.debian.org/debian-backports',
  35 + 'release' => 'squeeze-backports',
  36 + 'repos' => 'main contrib non-free',
  37 + 'key' => '55BE302B',
  38 + 'key_server' => 'pgp.mit.edu',
  39 + 'pin' => '200',
  40 + })
  41 + }
  42 + end
  43 +
  44 + describe "when turning on backports for debian squeeze but using your own mirror" do
  45 +
  46 + let :facts do
  47 + {
  48 + 'lsbdistcodename' => 'Squeeze',
  49 + 'lsbdistid' => 'Debian'
  50 + }
  51 + end
  52 +
  53 + let :location do
  54 + 'http://mirrors.example.com/debian-backports'
  55 + end
  56 +
  57 + let :params do
  58 + { 'location' => location }
  59 + end
  60 +
  61 + it { should contain_apt__source('backports').with({
  62 + 'location' => location,
  63 + 'release' => 'squeeze-backports',
  64 + 'repos' => 'main contrib non-free',
  65 + 'key' => '55BE302B',
  66 + 'key_server' => 'pgp.mit.edu',
  67 + 'pin' => '200',
  68 + })
  69 + }
  70 + end
  71 +end
... ...
puppet/modules/apt/spec/classes/debian_testing_spec.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +require 'spec_helper'
  2 +describe 'apt::debian::testing', :type => :class do
  3 + it {
  4 + should contain_apt__source("debian_testing").with({
  5 + "location" => "http://debian.mirror.iweb.ca/debian/",
  6 + "release" => "testing",
  7 + "repos" => "main contrib non-free",
  8 + "required_packages" => "debian-keyring debian-archive-keyring",
  9 + "key" => "55BE302B",
  10 + "key_server" => "subkeys.pgp.net",
  11 + "pin" => "-10"
  12 + })
  13 + }
  14 +end
... ...
puppet/modules/apt/spec/classes/debian_unstable_spec.rb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +require 'spec_helper'
  2 +describe 'apt::debian::unstable', :type => :class do
  3 + it {
  4 + should contain_apt__source("debian_unstable").with({
  5 + "location" => "http://debian.mirror.iweb.ca/debian/",
  6 + "release" => "unstable",
  7 + "repos" => "main contrib non-free",
  8 + "required_packages" => "debian-keyring debian-archive-keyring",
  9 + "key" => "55BE302B",
  10 + "key_server" => "subkeys.pgp.net",
  11 + "pin" => "-10"
  12 + })
  13 + }
  14 +end
... ...
puppet/modules/apt/spec/classes/params_spec.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +require 'spec_helper'
  2 +describe 'apt::params', :type => :class do
  3 + let (:title) { 'my_package' }
  4 +
  5 + it { should contain_apt__params }
  6 +
  7 + # There are 4 resources in this class currently
  8 + # there should not be any more resources because it is a params class
  9 + # The resources are class[apt::params], class[main], class[settings], stage[main]
  10 + it "Should not contain any resources" do
  11 + subject.resources.size.should == 4
  12 + end
  13 +end
... ...
puppet/modules/apt/spec/classes/release_spec.rb 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +require 'spec_helper'
  2 +describe 'apt::release', :type => :class do
  3 + let (:title) { 'my_package' }
  4 +
  5 + let :param_set do
  6 + { :release_id => 'precise' }
  7 + end
  8 +
  9 + let (:params) { param_set }
  10 +
  11 + it { should include_class("apt::params") }
  12 +
  13 + it {
  14 + should contain_file("/etc/apt/apt.conf.d/01release").with({
  15 + "mode" => "0644",
  16 + "owner" => "root",
  17 + "group" => "root",
  18 + "content" => "APT::Default-Release \"#{param_set[:release_id]}\";"
  19 + })
  20 + }
  21 +end
  22 +
... ...
puppet/modules/apt/spec/classes/unattended_upgrades_spec.rb 0 → 100644
... ... @@ -0,0 +1,204 @@
  1 +require 'spec_helper'
  2 +describe 'apt::unattended_upgrades', :type => :class do
  3 + let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' }
  4 + let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' }
  5 +
  6 + it { should contain_package("unattended-upgrades") }
  7 +
  8 + it {
  9 + should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({
  10 + "owner" => "root",
  11 + "group" => "root",
  12 + "mode" => "0644",
  13 + "require" => "Package[unattended-upgrades]",
  14 + })
  15 + }
  16 +
  17 + it {
  18 + should create_file("/etc/apt/apt.conf.d/10periodic").with({
  19 + "owner" => "root",
  20 + "group" => "root",
  21 + "mode" => "0644",
  22 + "require" => "Package[unattended-upgrades]",
  23 + })
  24 + }
  25 +
  26 + describe "origins" do
  27 + describe "with param defaults" do
  28 + let(:params) {{ }}
  29 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"\${distro_id}:\${distro_codename}-security";\n\};$/) }
  30 + end
  31 +
  32 + describe "with origins => ['ubuntu:precise-security']" do
  33 + let :params do
  34 + { :origins => ['ubuntu:precise-security'] }
  35 + end
  36 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"ubuntu:precise-security";\n\};$/) }
  37 + end
  38 + end
  39 +
  40 + describe "blacklist" do
  41 + describe "with param defaults" do
  42 + let(:params) {{ }}
  43 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
  44 + end
  45 +
  46 + describe "with blacklist => []" do
  47 + let :params do
  48 + { :blacklist => ['libc6', 'libc6-dev'] }
  49 + end
  50 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
  51 + end
  52 + end
  53 +
  54 + describe "with update => 2" do
  55 + let :params do
  56 + { :update => "2" }
  57 + end
  58 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
  59 + end
  60 +
  61 + describe "with download => 2" do
  62 + let :params do
  63 + { :download => "2" }
  64 + end
  65 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
  66 + end
  67 +
  68 + describe "with upgrade => 2" do
  69 + let :params do
  70 + { :upgrade => "2" }
  71 + end
  72 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
  73 + end
  74 +
  75 + describe "with autoclean => 2" do
  76 + let :params do
  77 + { :autoclean => "2" }
  78 + end
  79 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
  80 + end
  81 +
  82 + describe "with auto_fix => false" do
  83 + let :params do
  84 + { :auto_fix => false }
  85 + end
  86 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
  87 + end
  88 +
  89 + describe "with minimal_steps => true" do
  90 + let :params do
  91 + { :minimal_steps => true }
  92 + end
  93 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
  94 + end
  95 +
  96 + describe "with install_on_shutdown => true" do
  97 + let :params do
  98 + { :install_on_shutdown => true }
  99 + end
  100 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
  101 + end
  102 +
  103 + describe "mail_to" do
  104 + describe "param defaults" do
  105 + let(:params) {{ }}
  106 + it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
  107 + it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
  108 + end
  109 +
  110 + describe "with mail_to => user@website, mail_only_on_error => true" do
  111 + let :params do
  112 + { :mail_to => "user@website",
  113 + :mail_only_on_error => true }
  114 + end
  115 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
  116 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
  117 + end
  118 + end
  119 +
  120 + describe "with remove_unused => false" do
  121 + let :params do
  122 + { :remove_unused => false }
  123 + end
  124 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
  125 + end
  126 +
  127 + describe "with auto_reboot => true" do
  128 + let :params do
  129 + { :auto_reboot => true }
  130 + end
  131 + it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
  132 + end
  133 +
  134 + describe "dl_limit" do
  135 + describe "param defaults" do
  136 + let(:params) {{ }}
  137 + it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
  138 + end
  139 +
  140 + describe "with dl_limit => 70" do
  141 + let :params do
  142 + { :dl_limit => "70" }
  143 + end
  144 + it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
  145 + end
  146 + end
  147 +
  148 + describe "with enable => 0" do
  149 + let :params do
  150 + { :enable => "0" }
  151 + end
  152 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
  153 + end
  154 +
  155 + describe "with backup_interval => 1" do
  156 + let :params do
  157 + { :backup_interval => "1" }
  158 + end
  159 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
  160 + end
  161 +
  162 + describe "with backup_level => 0" do
  163 + let :params do
  164 + { :backup_level => "0" }
  165 + end
  166 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
  167 + end
  168 +
  169 + describe "with max_age => 1" do
  170 + let :params do
  171 + { :max_age => "1" }
  172 + end
  173 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
  174 + end
  175 +
  176 + describe "with min_age => 1" do
  177 + let :params do
  178 + { :min_age => "1" }
  179 + end
  180 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
  181 + end
  182 +
  183 + describe "with max_size => 1" do
  184 + let :params do
  185 + { :max_size => "1" }
  186 + end
  187 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
  188 + end
  189 +
  190 + describe "with download_delta => 2" do
  191 + let :params do
  192 + { :download_delta => "2" }
  193 + end
  194 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
  195 + end
  196 +
  197 + describe "with verbose => 2" do
  198 + let :params do
  199 + { :verbose => "2" }
  200 + end
  201 + it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }
  202 + end
  203 +
  204 +end
... ...
puppet/modules/apt/spec/defines/builddep_spec.rb 0 → 100644
... ... @@ -0,0 +1,18 @@
  1 +require 'spec_helper'
  2 +describe 'apt::builddep', :type => :define do
  3 +
  4 + let(:title) { 'my_package' }
  5 +
  6 + describe "should require apt-get update" do
  7 + it { should contain_exec("apt_update").with({
  8 + 'command' => "/usr/bin/apt-get update",
  9 + 'refreshonly' => true
  10 + })
  11 + }
  12 + it { should contain_anchor("apt::builddep::my_package").with({
  13 + 'require' => 'Class[Apt::Update]',
  14 + })
  15 + }
  16 + end
  17 +
  18 +end
... ...
puppet/modules/apt/spec/defines/conf_spec.rb 0 → 100644
... ... @@ -0,0 +1,57 @@
  1 +require 'spec_helper'
  2 +describe 'apt::conf', :type => :define do
  3 + let :title do
  4 + 'norecommends'
  5 + end
  6 +
  7 + describe "when creating an apt preference" do
  8 + let :params do
  9 + {
  10 + :priority => '00',
  11 + :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
  12 + }
  13 + end
  14 +
  15 + let :filename do
  16 + "/etc/apt/apt.conf.d/00norecommends"
  17 + end
  18 +
  19 + it { should contain_apt__conf('norecommends').with({
  20 + 'priority' => '00',
  21 + 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
  22 + })
  23 + }
  24 +
  25 + it { should contain_file(filename).with({
  26 + 'ensure' => 'present',
  27 + 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
  28 + 'owner' => 'root',
  29 + 'group' => 'root',
  30 + 'mode' => '0644',
  31 + })
  32 + }
  33 + end
  34 +
  35 + describe "when removing an apt preference" do
  36 + let :params do
  37 + {
  38 + :ensure => 'absent',
  39 + :priority => '00',
  40 + :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
  41 + }
  42 + end
  43 +
  44 + let :filename do
  45 + "/etc/apt/apt.conf.d/00norecommends"
  46 + end
  47 +
  48 + it { should contain_file(filename).with({
  49 + 'ensure' => 'absent',
  50 + 'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
  51 + 'owner' => 'root',
  52 + 'group' => 'root',
  53 + 'mode' => '0644',
  54 + })
  55 + }
  56 + end
  57 +end
... ...
puppet/modules/apt/spec/defines/force_spec.rb 0 → 100644
... ... @@ -0,0 +1,41 @@
  1 +require 'spec_helper'
  2 +describe 'apt::force', :type => :define do
  3 + let :title do
  4 + 'my_package'
  5 + end
  6 +
  7 + let :default_params do
  8 + {
  9 + :release => 'testing',
  10 + :version => false
  11 + }
  12 + end
  13 +
  14 + [{},
  15 + {
  16 + :release => 'stable',
  17 + :version => '1'
  18 + }
  19 + ].each do |param_set|
  20 + describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
  21 + let :param_hash do
  22 + default_params.merge(param_set)
  23 + end
  24 +
  25 + let :params do
  26 + param_set
  27 + end
  28 +
  29 + let :unless_query do
  30 + base_command = "/usr/bin/dpkg -s #{title} | grep -q "
  31 + base_command + (params[:version] ? "'Version: #{params[:version]}'" : "'Status: install'")
  32 + end
  33 +
  34 + let :exec_title do
  35 + base_exec = "/usr/bin/apt-get -y -t #{param_hash[:release]} install #{title}"
  36 + base_exec + (params[:version] ? "=#{params[:version]}" : "")
  37 + end
  38 + it { should contain_exec(exec_title).with_unless(unless_query) }
  39 + end
  40 + end
  41 +end
... ...
puppet/modules/apt/spec/defines/key_spec.rb 0 → 100644
... ... @@ -0,0 +1,123 @@
  1 +require 'spec_helper'
  2 +describe 'apt::key', :type => :define do
  3 + let :title do
  4 + '8347A27F'
  5 + end
  6 +
  7 + let :default_params do
  8 + {
  9 + :key => title,
  10 + :ensure => 'present',
  11 + :key_server => "keyserver.ubuntu.com",
  12 + :key_source => false,
  13 + :key_content => false
  14 + }
  15 + end
  16 +
  17 + [{},
  18 + {
  19 + :ensure => 'absent'
  20 + },
  21 + {
  22 + :ensure => 'random'
  23 + },
  24 + {
  25 + :key_source => 'ftp://ftp.example.org/key',
  26 + },
  27 + {
  28 + :key_content => 'deadbeef',
  29 + }
  30 + ].each do |param_set|
  31 +
  32 + let :param_hash do
  33 + param_hash = default_params.merge(param_set)
  34 + param_hash[:key].upcase! if param_hash[:key]
  35 + param_hash
  36 + end
  37 +
  38 + let :params do
  39 + param_set
  40 + end
  41 +
  42 + let :digest do
  43 + str = String.new
  44 + str << param_hash[:key].to_s << '/'
  45 + str << param_hash[:key_content].to_s << '/'
  46 + str << param_hash[:key_source].to_s << '/'
  47 + str << param_hash[:key_server].to_s << '/'
  48 + Digest::SHA1.hexdigest(str)
  49 + end
  50 +
  51 + describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
  52 +
  53 + it {
  54 + if [:present, 'present', :absent, 'absent'].include? param_hash[:ensure]
  55 + should contain_apt__params
  56 + end
  57 + }
  58 +
  59 + it {
  60 + if [:present, 'present'].include? param_hash[:ensure]
  61 + should_not contain_exec("apt::key #{param_hash[:key]} absent")
  62 + should contain_anchor("apt::key #{param_hash[:key]} present")
  63 + should contain_exec(digest).with({
  64 + "path" => "/bin:/usr/bin",
  65 + "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'"
  66 + })
  67 + elsif [:absent, 'absent'].include? param_hash[:ensure]
  68 + should_not contain_anchor("apt::key #{param_hash[:key]} present")
  69 + should contain_exec("apt::key #{param_hash[:key]} absent").with({
  70 + "path" => "/bin:/usr/bin",
  71 + "onlyif" => "apt-key list | grep '#{param_hash[:key]}'",
  72 + "command" => "apt-key del '#{param_hash[:key]}'"
  73 + })
  74 + else
  75 + expect { should raise_error(Puppet::Error) }
  76 + end
  77 + }
  78 +
  79 + it {
  80 + if [:present, 'present'].include? param_hash[:ensure]
  81 + if param_hash[:key_content]
  82 + should contain_exec(digest).with({
  83 + "command" => "echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -"
  84 + })
  85 + elsif param_hash[:key_source]
  86 + should contain_exec(digest).with({
  87 + "command" => "wget -q '#{param_hash[:key_source]}' -O- | apt-key add -"
  88 + })
  89 + elsif param_hash[:key_server]
  90 + should contain_exec(digest).with({
  91 + "command" => "apt-key adv --keyserver '#{param_hash[:key_server]}' --recv-keys '#{param_hash[:key]}'"
  92 + })
  93 + end
  94 + end
  95 + }
  96 +
  97 + end
  98 + end
  99 +
  100 + [{ :ensure => 'present' }, { :ensure => 'absent' }].each do |param_set|
  101 + describe "should correctly handle duplicate definitions" do
  102 +
  103 + let :pre_condition do
  104 + "apt::key { 'duplicate': key => '#{title}'; }"
  105 + end
  106 +
  107 + let(:params) { param_set }
  108 +
  109 + it {
  110 + if param_set[:ensure] == 'present'
  111 + should contain_anchor("apt::key #{title} present")
  112 + should contain_apt__key(title)
  113 + should contain_apt__key("duplicate")
  114 + elsif param_set[:ensure] == 'absent'
  115 + expect { should raise_error(Puppet::Error) }
  116 + end
  117 + }
  118 +
  119 + end
  120 + end
  121 +
  122 +end
  123 +
... ...
puppet/modules/apt/spec/defines/pin_spec.rb 0 → 100644
... ... @@ -0,0 +1,101 @@
  1 +require 'spec_helper'
  2 +describe 'apt::pin', :type => :define do
  3 + let(:title) { 'my_pin' }
  4 +
  5 + let :default_params do
  6 + {
  7 + :ensure => 'present',
  8 + :order => '',
  9 + :packages => '*',
  10 + :priority => '0',
  11 + :release => nil
  12 + }
  13 + end
  14 +
  15 + [
  16 + { :params => {},
  17 + :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: release a=my_pin\nPin-Priority: 0\n"
  18 + },
  19 + {
  20 + :params => {
  21 + :packages => 'apache',
  22 + :priority => '1'
  23 + },
  24 + :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
  25 + },
  26 + {
  27 + :params => {
  28 + :order => 50,
  29 + :packages => 'apache',
  30 + :priority => '1'
  31 + },
  32 + :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
  33 + },
  34 + {
  35 + :params => {
  36 + :ensure => 'absent',
  37 + :packages => 'apache',
  38 + :priority => '1'
  39 + },
  40 + :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
  41 + },
  42 + {
  43 + :params => {
  44 + :packages => 'apache',
  45 + :priority => '1',
  46 + :release => 'my_newpin'
  47 + },
  48 + :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_newpin\nPin-Priority: 1\n"
  49 + },
  50 + {
  51 + :params => {
  52 + :packages => 'apache',
  53 + :priority => '1',
  54 + :version => '2.2.16*'
  55 + },
  56 + :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: version 2.2.16*\nPin-Priority: 1\n"
  57 + },
  58 + {
  59 + :params => {
  60 + :priority => '1',
  61 + :origin => 'ftp.de.debian.org'
  62 + },
  63 + :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: origin \"ftp.de.debian.org\"\nPin-Priority: 1\n"
  64 + },
  65 + {
  66 + :params => {
  67 + :packages => 'apache',
  68 + :priority => '1',
  69 + :release => 'stable',
  70 + :codename => 'wheezy',
  71 + :release_version => '3.0',
  72 + :component => 'main',
  73 + :originator => 'Debian',
  74 + :label => 'Debian'
  75 + },
  76 + :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"
  77 + },
  78 + ].each do |param_set|
  79 + describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
  80 + let :param_hash do
  81 + default_params.merge(param_set[:params])
  82 + end
  83 +
  84 + let :params do
  85 + param_set[:params]
  86 + end
  87 +
  88 + it { should include_class("apt::params") }
  89 +
  90 + it { should contain_file("#{title}.pref").with({
  91 + 'ensure' => param_hash[:ensure],
  92 + 'path' => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
  93 + 'owner' => 'root',
  94 + 'group' => 'root',
  95 + 'mode' => '0644',
  96 + 'content' => param_set[:content],
  97 + })
  98 + }
  99 + end
  100 + end
  101 +end
... ...
puppet/modules/apt/spec/defines/ppa_spec.rb 0 → 100644
... ... @@ -0,0 +1,143 @@
  1 +require 'spec_helper'
  2 +describe 'apt::ppa', :type => :define do
  3 + [ { :lsbdistrelease => '11.04',
  4 + :lsbdistcodename => 'natty',
  5 + :package => 'python-software-properties'},
  6 + { :lsbdistrelease => '12.10',
  7 + :lsbdistcodename => 'quantal',
  8 + :package => 'software-properties-common'},
  9 + ].each do |platform|
  10 + context "on #{platform[:lsbdistcodename]}" do
  11 + let :facts do
  12 + {
  13 + :lsbdistrelease => platform[:lsbdistrelease],
  14 + :lsbdistcodename => platform[:lsbdistcodename],
  15 + }
  16 + end
  17 + let :release do
  18 + "#{platform[:lsbdistcodename]}"
  19 + end
  20 + let :package do
  21 + "#{platform[:package]}"
  22 + end
  23 + let :options do
  24 + "-y"
  25 + end
  26 + ['ppa:dans_ppa', 'dans_ppa','ppa:dans-daily/ubuntu'].each do |t|
  27 + describe "with title #{t}" do
  28 + let :pre_condition do
  29 + 'class { "apt": }'
  30 + end
  31 + let :title do
  32 + t
  33 + end
  34 + let :filename do
  35 + t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list"
  36 + end
  37 +
  38 + it { should contain_package("#{package}") }
  39 +
  40 + it { should contain_exec("apt_update").with(
  41 + 'command' => '/usr/bin/apt-get update',
  42 + 'refreshonly' => true
  43 + )
  44 + }
  45 +
  46 + it { should contain_exec("add-apt-repository-#{t}").with(
  47 + 'command' => "/usr/bin/add-apt-repository #{options} #{t}",
  48 + 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
  49 + 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"],
  50 + 'notify' => "Exec[apt_update]"
  51 + )
  52 + }
  53 +
  54 + it { should create_file("/etc/apt/sources.list.d/#{filename}").with(
  55 + 'ensure' => 'file',
  56 + 'require' => "Exec[add-apt-repository-#{t}]"
  57 + )
  58 + }
  59 + end
  60 + end
  61 + describe 'without a proxy defined' do
  62 + let :title do
  63 + 'rspec_ppa'
  64 + end
  65 + let :pre_condition do
  66 + 'class { "apt":
  67 + proxy_host => false
  68 + }'
  69 + end
  70 + let :filename do
  71 + "#{title}-#{release}.list"
  72 + end
  73 +
  74 + it { should contain_exec("add-apt-repository-#{title}").with(
  75 + 'environment' => [],
  76 + 'command' => "/usr/bin/add-apt-repository #{options} #{title}",
  77 + 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
  78 + 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"],
  79 + 'notify' => "Exec[apt_update]"
  80 + )
  81 + }
  82 + end
  83 +
  84 + describe 'behind a proxy' do
  85 + let :title do
  86 + 'rspec_ppa'
  87 + end
  88 + let :pre_condition do
  89 + 'class { "apt":
  90 + proxy_host => "user:pass@proxy",
  91 + }'
  92 + end
  93 + let :filename do
  94 + "#{title}-#{release}.list"
  95 + end
  96 +
  97 + it { should contain_exec("add-apt-repository-#{title}").with(
  98 + 'environment' => [
  99 + "http_proxy=http://user:pass@proxy:8080",
  100 + "https_proxy=http://user:pass@proxy:8080",
  101 + ],
  102 + 'command' => "/usr/bin/add-apt-repository #{options} #{title}",
  103 + 'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
  104 + 'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"],
  105 + 'notify' => "Exec[apt_update]"
  106 + )
  107 + }
  108 + end
  109 + end
  110 + end
  111 +
  112 + [ { :lsbdistcodename => 'natty',
  113 + :package => 'python-software-properties' },
  114 + { :lsbdistcodename => 'quantal',
  115 + :package => 'software-properties-common'},
  116 + ].each do |platform|
  117 + context "on #{platform[:lsbdistcodename]}" do
  118 + describe "it should not error if package['#{platform[:package]}'] is already defined" do
  119 + let :pre_condition do
  120 + 'class {"apt": }' +
  121 + 'package { "#{platform[:package]}": }->Apt::Ppa["ppa"]'
  122 + end
  123 + let :facts do
  124 + {:lsbdistcodename => '#{platform[:lsbdistcodename]}'}
  125 + end
  126 + let(:title) { "ppa" }
  127 + let(:release) { "#{platform[:lsbdistcodename]}" }
  128 + it { should contain_package('#{platform[:package]}') }
  129 + end
  130 + end
  131 + end
  132 +
  133 + describe "without Class[apt] should raise a Puppet::Error" do
  134 + let(:release) { "natty" }
  135 + let(:title) { "ppa" }
  136 + it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
  137 + end
  138 +
  139 + describe "without release should raise a Puppet::Error" do
  140 + let(:title) { "ppa:" }
  141 + it { expect { should contain_apt__ppa(:release) }.to raise_error(Puppet::Error) }
  142 + end
  143 +end
... ...
puppet/modules/apt/spec/defines/source_spec.rb 0 → 100644
... ... @@ -0,0 +1,166 @@
  1 +require 'spec_helper'
  2 +describe 'apt::source', :type => :define do
  3 + let :title do
  4 + 'my_source'
  5 + end
  6 +
  7 + let :default_params do
  8 + {
  9 + :ensure => 'present',
  10 + :location => '',
  11 + :release => 'karmic',
  12 + :repos => 'main',
  13 + :include_src => true,
  14 + :required_packages => false,
  15 + :key => false,
  16 + :key_server => 'keyserver.ubuntu.com',
  17 + :key_content => false,
  18 + :key_source => false,
  19 + :pin => false
  20 + }
  21 + end
  22 +
  23 + [{},
  24 + {
  25 + :location => 'http://example.com',
  26 + :release => 'precise',
  27 + :repos => 'security',
  28 + :include_src => false,
  29 + :required_packages => 'apache',
  30 + :key => 'key_name',
  31 + :key_server => 'keyserver.debian.com',
  32 + :pin => '600',
  33 + :key_content => 'ABCD1234'
  34 + },
  35 + {
  36 + :key => 'key_name',
  37 + :key_server => 'keyserver.debian.com',
  38 + :key_content => false,
  39 + },
  40 + {
  41 + :ensure => 'absent',
  42 + :location => 'http://example.com',
  43 + :release => 'precise',
  44 + :repos => 'security',
  45 + },
  46 + {
  47 + :release => '',
  48 + },
  49 + {
  50 + :release => 'custom',
  51 + },
  52 + {
  53 + :architecture => 'amd64',
  54 + }
  55 + ].each do |param_set|
  56 + describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
  57 + let :param_hash do
  58 + default_params.merge(param_set)
  59 + end
  60 +
  61 + let :facts do
  62 + {:lsbdistcodename => 'karmic'}
  63 + end
  64 +
  65 + let :params do
  66 + param_set
  67 + end
  68 +
  69 + let :filename do
  70 + "/etc/apt/sources.list.d/#{title}.list"
  71 + end
  72 +
  73 + let :content do
  74 + content = "# #{title}"
  75 + if param_hash[:architecture]
  76 + arch = "[arch=#{param_hash[:architecture]}]"
  77 + end
  78 + content << "\ndeb #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
  79 +
  80 + if param_hash[:include_src]
  81 + content << "deb-src #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
  82 + end
  83 + content
  84 + end
  85 +
  86 + it { should contain_apt__params }
  87 +
  88 + it { should contain_file("#{title}.list").with({
  89 + 'ensure' => param_hash[:ensure],
  90 + 'path' => filename,
  91 + 'owner' => 'root',
  92 + 'group' => 'root',
  93 + 'mode' => '0644',
  94 + 'content' => content,
  95 + })
  96 + }
  97 +
  98 + it {
  99 + if param_hash[:pin]
  100 + should contain_apt__pin(title).with({
  101 + "priority" => param_hash[:pin],
  102 + "before" => "File[#{title}.list]"
  103 + })
  104 + else
  105 + should_not contain_apt__pin(title).with({
  106 + "priority" => param_hash[:pin],
  107 + "before" => "File[#{title}.list]"
  108 + })
  109 + end
  110 + }
  111 +
  112 + it {
  113 + should contain_exec("apt_update").with({
  114 + "command" => "/usr/bin/apt-get update",
  115 + "refreshonly" => true
  116 + })
  117 + }
  118 +
  119 + it {
  120 + if param_hash[:required_packages]
  121 + should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
  122 + "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
  123 + "subscribe" => "File[#{title}.list]",
  124 + "refreshonly" => true,
  125 + "before" => 'Exec[apt_update]',
  126 + })
  127 + else
  128 + should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
  129 + "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
  130 + "subscribe" => "File[#{title}.list]",
  131 + "refreshonly" => true
  132 + })
  133 + end
  134 + }
  135 +
  136 + it {
  137 + if param_hash[:key]
  138 + should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
  139 + "key" => param_hash[:key],
  140 + "ensure" => :present,
  141 + "key_server" => param_hash[:key_server],
  142 + "key_content" => param_hash[:key_content],
  143 + "key_source" => param_hash[:key_source],
  144 + "before" => "File[#{title}.list]"
  145 + })
  146 + else
  147 + should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
  148 + "key" => param_hash[:key],
  149 + "ensure" => :present,
  150 + "key_server" => param_hash[:key_server],
  151 + "key_content" => param_hash[:key_content],
  152 + "key_source" => param_hash[:key_source],
  153 + "before" => "File[#{title}.list]"
  154 + })
  155 + end
  156 + }
  157 + end
  158 + end
  159 + describe "without release should raise a Puppet::Error" do
  160 + let(:default_params) { Hash.new }
  161 + let(:facts) { Hash.new }
  162 + it { expect { should raise_error(Puppet::Error) } }
  163 + let(:facts) { { :lsbdistcodename => 'lucid' } }
  164 + it { should contain_apt__source(title) }
  165 + end
  166 +end
... ...
puppet/modules/apt/spec/spec_helper.rb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +require 'puppetlabs_spec_helper/module_spec_helper'
... ...
puppet/modules/apt/spec/spec_helper_system.rb 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +require 'rspec-system/spec_helper'
  2 +require 'rspec-system-puppet/helpers'
  3 +require 'rspec-system-serverspec/helpers'
  4 +
  5 +include RSpecSystemPuppet::Helpers
  6 +
  7 +include Serverspec::Helper::RSpecSystem
  8 +include Serverspec::Helper::DetectOS
  9 +
  10 +RSpec.configure do |c|
  11 + # Project root
  12 + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
  13 +
  14 + # Enable colour
  15 + c.tty = true
  16 +
  17 + c.include RSpecSystemPuppet::Helpers
  18 +
  19 + # This is where we 'setup' the nodes before running our tests
  20 + c.before :suite do
  21 + # May as well update here as this can only run on apt-get machines.
  22 + shell('apt-get update')
  23 + # Install puppet
  24 + puppet_install
  25 +
  26 + # Install modules and dependencies
  27 + puppet_module_install(:source => proj_root, :module_name => 'apt')
  28 + shell('puppet module install puppetlabs-stdlib')
  29 + end
  30 +end
... ...
puppet/modules/apt/spec/system/apt_builddep_spec.rb 0 → 100644
... ... @@ -0,0 +1,38 @@
  1 +require 'spec_helper_system'
  2 +
  3 +describe 'apt::builddep' do
  4 +
  5 + context 'reset' do
  6 + it 'removes packages' do
  7 + shell('apt-get -y remove glusterfs-server')
  8 + shell('apt-get -y remove g++')
  9 + end
  10 + end
  11 +
  12 + context 'apt::builddep' do
  13 + it 'should work with no errors' do
  14 + pp = <<-EOS
  15 + include '::apt'
  16 + apt::builddep { 'glusterfs-server': }
  17 + EOS
  18 +
  19 + puppet_apply(pp) do |r|
  20 + r.exit_code.should_not == 1
  21 + end
  22 + end
  23 +
  24 + describe 'should install g++ as a dependency' do
  25 + describe package('g++') do
  26 + it { should be_installed }
  27 + end
  28 + end
  29 + end
  30 +
  31 + context 'reset' do
  32 + it 'removes packages' do
  33 + shell('apt-get -y remove glusterfs-server')
  34 + shell('apt-get -y remove g++')
  35 + end
  36 + end
  37 +
  38 +end
... ...
puppet/modules/apt/spec/system/apt_key_spec.rb 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +require 'spec_helper_system'
  2 +
  3 +describe 'apt::key' do
  4 +
  5 + context 'reset' do
  6 + it 'clean up keys' do
  7 + shell('apt-key del 4BD6EC30')
  8 + shell('apt-key del D50582E6')
  9 + end
  10 + end
  11 +
  12 + context 'apt::key' do
  13 + it 'should work with no errors' do
  14 + pp = <<-EOS
  15 + include '::apt'
  16 + apt::key { 'puppetlabs':
  17 + key => '4BD6EC30',
  18 + key_server => 'pgp.mit.edu',
  19 + }
  20 +
  21 + apt::key { 'jenkins':
  22 + key => 'D50582E6',
  23 + key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
  24 + }
  25 + EOS
  26 +
  27 + puppet_apply(pp) do |r|
  28 + r.exit_code.should_not == 1
  29 + end
  30 + end
  31 +
  32 + describe 'keys should exist' do
  33 + it 'finds puppetlabs key' do
  34 + shell('apt-key list | grep 4BD6EC30') do |r|
  35 + r.exit_code.should be_zero
  36 + end
  37 + end
  38 + it 'finds jenkins key' do
  39 + shell('apt-key list | grep D50582E6') do |r|
  40 + r.exit_code.should be_zero
  41 + end
  42 + end
  43 + end
  44 + end
  45 +
  46 + context 'reset' do
  47 + it 'clean up keys' do
  48 + shell('apt-key del 4BD6EC30')
  49 + shell('apt-key del D50582E6')
  50 + end
  51 + end
  52 +
  53 +end
... ...
puppet/modules/apt/spec/system/apt_ppa_spec.rb 0 → 100644
... ... @@ -0,0 +1,59 @@
  1 +require 'spec_helper_system'
  2 +
  3 +describe 'apt::ppa' do
  4 +
  5 + context 'reset' do
  6 + it 'removes ppa' do
  7 + shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*')
  8 + shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*')
  9 + end
  10 + end
  11 +
  12 + context 'adding a ppa that doesnt exist' do
  13 + it 'should work with no errors' do
  14 + pp = <<-EOS
  15 + include '::apt'
  16 + apt::ppa { 'ppa:drizzle-developers/ppa': }
  17 + EOS
  18 +
  19 + puppet_apply(pp) do |r|
  20 + r.exit_code.should_not == 1
  21 + end
  22 + end
  23 +
  24 + describe 'contains the source file' do
  25 + it 'contains a drizzle ppa source' do
  26 + shell('ls /etc/apt/sources.list.d/drizzle-developers-ppa-*.list') do |r|
  27 + r.exit_code.should be_zero
  28 + end
  29 + end
  30 + end
  31 + end
  32 +
  33 + context 'readding a removed ppa.' do
  34 + it 'setup' do
  35 + shell('add-apt-repository -y ppa:raravena80/collectd5')
  36 + # This leaves a blank file
  37 + shell('add-apt-repository --remove ppa:raravena80/collectd5')
  38 + end
  39 +
  40 + it 'should readd it successfully' do
  41 + pp = <<-EOS
  42 + include '::apt'
  43 + apt::ppa { 'ppa:raravena80/collectd5': }
  44 + EOS
  45 +
  46 + puppet_apply(pp) do |r|
  47 + r.exit_code.should_not == 1
  48 + end
  49 + end
  50 + end
  51 +
  52 + context 'reset' do
  53 + it 'removes added ppas' do
  54 + shell('rm /etc/apt/sources.list.d/drizzle-developers-ppa*')
  55 + shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*')
  56 + end
  57 + end
  58 +
  59 +end
... ...
puppet/modules/apt/spec/system/apt_source_spec.rb 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +require 'spec_helper_system'
  2 +
  3 +describe 'apt::source' do
  4 +
  5 + context 'reset' do
  6 + it 'clean up puppetlabs repo' do
  7 + shell('apt-key del 4BD6EC30')
  8 + shell('rm /etc/apt/sources.list.d/puppetlabs.list')
  9 + end
  10 + end
  11 +
  12 + context 'apt::source' do
  13 + it 'should work with no errors' do
  14 + pp = <<-EOS
  15 + include '::apt'
  16 + apt::source { 'puppetlabs':
  17 + location => 'http://apt.puppetlabs.com',
  18 + repos => 'main',
  19 + key => '4BD6EC30',
  20 + key_server => 'pgp.mit.edu',
  21 + }
  22 + EOS
  23 +
  24 + puppet_apply(pp) do |r|
  25 + r.exit_code.should_not == 1
  26 + end
  27 + end
  28 +
  29 + describe 'key should exist' do
  30 + it 'finds puppetlabs key' do
  31 + shell('apt-key list | grep 4BD6EC30') do |r|
  32 + r.exit_code.should be_zero
  33 + end
  34 + end
  35 + end
  36 +
  37 + describe 'source should exist' do
  38 + describe file('/etc/apt/sources.list.d/puppetlabs.list') do
  39 + it { should be_file }
  40 + end
  41 + end
  42 + end
  43 +
  44 + context 'reset' do
  45 + it 'clean up puppetlabs repo' do
  46 + shell('apt-key del 4BD6EC30')
  47 + shell('rm /etc/apt/sources.list.d/puppetlabs.list')
  48 + end
  49 + end
  50 +
  51 +end
... ...
puppet/modules/apt/spec/system/basic_spec.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +require 'spec_helper_system'
  2 +
  3 +describe 'basic tests:' do
  4 + # Using puppet_apply as a subject
  5 + context puppet_apply 'notice("foo")' do
  6 + its(:stdout) { should =~ /foo/ }
  7 + its(:stderr) { should be_empty }
  8 + its(:exit_code) { should be_zero }
  9 + end
  10 +end
... ...
puppet/modules/apt/spec/system/class_spec.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +require 'spec_helper_system'
  2 +
  3 +describe 'apt class' do
  4 +
  5 + context 'default parameters' do
  6 + # Using puppet_apply as a helper
  7 + it 'should work with no errors' do
  8 + pp = <<-EOS
  9 + class { 'apt': }
  10 + EOS
  11 +
  12 + # Run it twice and test for idempotency
  13 + puppet_apply(pp) do |r|
  14 + r.exit_code.should_not == 1
  15 + r.refresh
  16 + r.exit_code.should be_zero
  17 + end
  18 + end
  19 + end
  20 +end
... ...
puppet/modules/apt/templates/10periodic.erb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +APT::Periodic::Enable "<%= @enable %>";
  2 +APT::Periodic::BackUpArchiveInterval "<%= @backup_interval %>";
  3 +APT::Periodic::BackUpLevel "<%= @backup_level %>";
  4 +APT::Periodic::MaxAge "<%= @max_age %>";
  5 +APT::Periodic::MinAge "<%= @min_age %>";
  6 +APT::Periodic::MaxSize "<%= @max_size %>";
  7 +APT::Periodic::Update-Package-Lists "<%= @update %>";
  8 +APT::Periodic::Download-Upgradeable-Packages "<%= @download %>";
  9 +APT::Periodic::Download-Upgradeable-Packages-Debdelta "<%= @download_delta %>";
  10 +APT::Periodic::Unattended-Upgrade "<%= @upgrade %>";
  11 +APT::Periodic::AutocleanInterval "<%= @autoclean %>";
  12 +APT::Periodic::Verbose "<%= @verbose %>";
... ...
puppet/modules/apt/templates/50unattended-upgrades.erb 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +// Automatically upgrade packages from these (origin:archive) pairs
  2 +Unattended-Upgrade::Allowed-Origins {
  3 +<% @origins.each do |origin| -%>
  4 + "<%= origin %>";
  5 +<% end -%>
  6 +};
  7 +
  8 +// List of packages to not update
  9 +Unattended-Upgrade::Package-Blacklist {
  10 +<% @blacklist.each do |package| -%>
  11 + "<%= package %>";
  12 +<% end -%>
  13 +};
  14 +
  15 +// This option allows you to control if on a unclean dpkg exit
  16 +// unattended-upgrades will automatically run
  17 +// dpkg --force-confold --configure -a
  18 +// The default is true, to ensure updates keep getting installed
  19 +Unattended-Upgrade::AutoFixInterruptedDpkg "<%= @auto_fix %>";
  20 +
  21 +// Split the upgrade into the smallest possible chunks so that
  22 +// they can be interrupted with SIGUSR1. This makes the upgrade
  23 +// a bit slower but it has the benefit that shutdown while a upgrade
  24 +// is running is possible (with a small delay)
  25 +Unattended-Upgrade::MinimalSteps "<%= @minimal_steps %>";
  26 +
  27 +// Install all unattended-upgrades when the machine is shuting down
  28 +// instead of doing it in the background while the machine is running
  29 +// This will (obviously) make shutdown slower
  30 +Unattended-Upgrade::InstallOnShutdown "<%= @install_on_shutdown %>";
  31 +
  32 +// Send email to this address for problems or packages upgrades
  33 +// If empty or unset then no email is sent, make sure that you
  34 +// have a working mail setup on your system. A package that provides
  35 +// 'mailx' must be installed.
  36 +<% if @mail_to != "NONE" %>Unattended-Upgrade::Mail "<%= @mail_to %>";<% end %>
  37 +
  38 +// Set this value to "true" to get emails only on errors. Default
  39 +// is to always send a mail if Unattended-Upgrade::Mail is set
  40 +<% if @mail_to != "NONE" %>Unattended-Upgrade::MailOnlyOnError "<%= @mail_only_on_error %>";<% end %>
  41 +
  42 +// Do automatic removal of new unused dependencies after the upgrade
  43 +// (equivalent to apt-get autoremove)
  44 +Unattended-Upgrade::Remove-Unused-Dependencies "<%= @remove_unused %>";
  45 +
  46 +// Automatically reboot *WITHOUT CONFIRMATION* if a
  47 +// the file /var/run/reboot-required is found after the upgrade
  48 +Unattended-Upgrade::Automatic-Reboot "<%= @auto_reboot %>";
  49 +
  50 +
  51 +// Use apt bandwidth limit feature, this example limits the download
  52 +// speed to 70kb/sec
  53 +<% if @dl_limit != "NONE" %>Acquire::http::Dl-Limit "<%= @dl_limit %>";<% end %>
... ...
puppet/modules/apt/templates/pin.pref.erb 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +<%-
  2 +@pin = "release a=#{@name}" # default value
  3 +if @pin_release.length > 0
  4 + options = []
  5 + options.push("a=#{@release}") if @release.length > 0
  6 + options.push("n=#{@codename}") if @codename.length > 0
  7 + options.push("v=#{@release_version}") if @release_version.length > 0
  8 + options.push("c=#{@component}") if @component.length > 0
  9 + options.push("o=#{@originator}") if @originator.length > 0
  10 + options.push("l=#{@label}") if @label.length > 0
  11 + @pin = "release #{options.join(', ')}"
  12 +elsif @version.length > 0
  13 + @pin = "version #{@version}"
  14 +elsif @origin.length > 0
  15 + @pin = "origin \"#{@origin}\""
  16 +end
  17 +-%>
  18 +# <%= @name %>
  19 +Explanation: <%= @explanation %>
  20 +Package: <%= @packages %>
  21 +Pin: <%= @pin %>
  22 +Pin-Priority: <%= @priority %>
... ...
puppet/modules/apt/templates/source.list.erb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +# <%= @name %>
  2 +deb <% if @architecture %>[arch=<%= @architecture %>]<% end %><%= @location %> <%= @release_real %> <%= @repos %>
  3 +<%- if @include_src then -%>
  4 +deb-src <% if @architecture %>[arch=<%= @architecture %>]<% end %><%= @location %> <%= @release_real %> <%= @repos %>
  5 +<%- end -%>
... ...
puppet/modules/apt/tests/builddep.pp 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class { 'apt': }
  2 +apt::builddep{ 'glusterfs-server': }
... ...
puppet/modules/apt/tests/debian/testing.pp 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class { 'apt': }
  2 +class { 'apt::debian::testing': }
... ...
puppet/modules/apt/tests/debian/unstable.pp 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +class { 'apt': }
  2 +class { 'apt::debian::unstable': }
... ...
puppet/modules/apt/tests/force.pp 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +# force.pp
  2 +# force a package from a specific release
  3 +
  4 +apt::force { 'package':
  5 + release => 'testing',
  6 + version => false
  7 +}
... ...
puppet/modules/apt/tests/init.pp 0 → 100644
... ... @@ -0,0 +1 @@
  1 +class { 'apt': }
... ...
puppet/modules/apt/tests/key.pp 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +# Declare Apt key for apt.puppetlabs.com source
  2 +apt::key { 'puppetlabs':
  3 + key => '4BD6EC30',
  4 + key_server => 'pgp.mit.edu',
  5 + key_options => 'http-proxy="http://proxyuser:proxypass@example.org:3128"',
  6 +}
... ...
puppet/modules/apt/tests/params.pp 0 → 100644
... ... @@ -0,0 +1 @@
  1 +include apt::params
... ...
puppet/modules/apt/tests/pin.pp 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +# pin a release in apt, useful for unstable repositories
  2 +apt::pin { 'foo':
  3 + packages => '*',
  4 + priority => 0,
  5 +}
... ...
puppet/modules/apt/tests/ppa.pp 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +class { 'apt': }
  2 +
  3 +# Example declaration of an Apt PPA
  4 +apt::ppa{ 'ppa:openstack-ppa/bleeding-edge': }
... ...
puppet/modules/apt/tests/release.pp 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +class { 'apt': }
  2 +class { 'apt::release':
  3 + release_id => 'karmic'
  4 +}
... ...
puppet/modules/apt/tests/source.pp 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +# Declare the apt class to manage /etc/apt/sources.list and /etc/sources.list.d
  2 +class { 'apt': }
  3 +
  4 +# Install the puppetlabs apt source
  5 +# Release is automatically obtained from lsbdistcodename fact if available.
  6 +apt::source { 'puppetlabs':
  7 + location => 'http://apt.puppetlabs.com',
  8 + repos => 'main',
  9 + key => '4BD6EC30',
  10 + key_server => 'pgp.mit.edu',
  11 +}
  12 +
  13 +# test two sources with the same key
  14 +apt::source { 'debian_testing':
  15 + location => 'http://debian.mirror.iweb.ca/debian/',
  16 + release => 'testing',
  17 + repos => 'main contrib non-free',
  18 + key => '55BE302B',
  19 + key_server => 'subkeys.pgp.net',
  20 + pin => '-10',
  21 +}
  22 +apt::source { 'debian_unstable':
  23 + location => 'http://debian.mirror.iweb.ca/debian/',
  24 + release => 'unstable',
  25 + repos => 'main contrib non-free',
  26 + key => '55BE302B',
  27 + key_server => 'subkeys.pgp.net',
  28 + pin => '-10',
  29 +}
... ...
puppet/modules/apt/tests/unattended-upgrades.pp 0 → 100644
... ... @@ -0,0 +1 @@
  1 +include apt::unattended-upgrades
... ...
puppet/modules/colab/manifests/init.pp
1 1  
2 2 class colab {
3 3 # Common
  4 + include apt
4 5 include ps1
5 6 include vim
6 7 include ntp
... ... @@ -8,10 +9,15 @@ class colab {
8 9 include timezone
9 10 include postfix
10 11  
11   - include nginx
12 12 include supervisor
13 13 include colab::requirements
14 14  
  15 + apt::ppa { 'ppa:nginx/stable': }
  16 +
  17 + class { 'nginx':
  18 + require => Apt::Ppa['ppa:nginx/stable'],
  19 + }
  20 +
15 21 group { 'colab':
16 22 ensure => present,
17 23 }
... ...
puppet/modules/nginx/manifests/init.pp
... ... @@ -43,7 +43,7 @@ class nginx (
43 43 }
44 44 if ! defined(Package[$nginx_packages]) {
45 45 package { $nginx_packages:
46   - ensure => installed
  46 + ensure => latest
47 47 }
48 48 }
49 49  
... ...
puppet/modules/stdlib/CHANGELOG 0 → 100644
... ... @@ -0,0 +1,278 @@
  1 +2013-05-06 - Jeff McCune <jeff@puppetlabs.com> - 4.1.0
  2 + * (#20582) Restore facter_dot_d to stdlib for PE users (3b887c8)
  3 + * (maint) Update Gemfile with GEM_FACTER_VERSION (f44d535)
  4 +
  5 +2013-05-06 - Alex Cline <acline@us.ibm.com> - 4.1.0
  6 + * Terser method of string to array conversion courtesy of ethooz. (d38bce0)
  7 +
  8 +2013-05-06 - Alex Cline <acline@us.ibm.com> 4.1.0
  9 + * Refactor ensure_resource expectations (b33cc24)
  10 +
  11 +2013-05-06 - Alex Cline <acline@us.ibm.com> 4.1.0
  12 + * Changed str-to-array conversion and removed abbreviation. (de253db)
  13 +
  14 +2013-05-03 - Alex Cline <acline@us.ibm.com> 4.1.0
  15 + * (#20548) Allow an array of resource titles to be passed into the ensure_resource function (e08734a)
  16 +
  17 +2013-05-02 - Raphaël Pinson <raphael.pinson@camptocamp.com> - 4.1.0
  18 + * Add a dirname function (2ba9e47)
  19 +
  20 +2013-04-29 - Mark Smith-Guerrero <msmithgu@gmail.com> - 4.1.0
  21 + * (maint) Fix a small typo in hash() description (928036a)
  22 +
  23 +2013-04-12 - Jeff McCune <jeff@puppetlabs.com> - 4.0.2
  24 + * Update user information in gemspec to make the intent of the Gem clear.
  25 +
  26 +2013-04-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.1
  27 + * Fix README function documentation (ab3e30c)
  28 +
  29 +2013-04-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
  30 + * stdlib 4.0 drops support with Puppet 2.7
  31 + * stdlib 4.0 preserves support with Puppet 3
  32 +
  33 +2013-04-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
  34 + * Add ability to use puppet from git via bundler (9c5805f)
  35 +
  36 +2013-04-10 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
  37 + * (maint) Make stdlib usable as a Ruby GEM (e81a45e)
  38 +
  39 +2013-04-10 - Erik Dalén <dalen@spotify.com> - 4.0.0
  40 + * Add a count function (f28550e)
  41 +
  42 +2013-03-31 - Amos Shapira <ashapira@atlassian.com> - 4.0.0
  43 + * (#19998) Implement any2array (7a2fb80)
  44 +
  45 +2013-03-29 - Steve Huff <shuff@vecna.org> - 4.0.0
  46 + * (19864) num2bool match fix (8d217f0)
  47 +
  48 +2013-03-20 - Erik Dalén <dalen@spotify.com> - 4.0.0
  49 + * Allow comparisons of Numeric and number as String (ff5dd5d)
  50 +
  51 +2013-03-26 - Richard Soderberg <rsoderberg@mozilla.com> - 4.0.0
  52 + * add suffix function to accompany the prefix function (88a93ac)
  53 +
  54 +2013-03-19 - Kristof Willaert <kristof.willaert@gmail.com> - 4.0.0
  55 + * Add floor function implementation and unit tests (0527341)
  56 +
  57 +2012-04-03 - Eric Shamow <eric@puppetlabs.com> - 4.0.0
  58 + * (#13610) Add is_function_available to stdlib (961dcab)
  59 +
  60 +2012-12-17 - Justin Lambert <jlambert@eml.cc> - 4.0.0
  61 + * str2bool should return a boolean if called with a boolean (5d5a4d4)
  62 +
  63 +2012-10-23 - Uwe Stuehler <ustuehler@team.mobile.de> - 4.0.0
  64 + * Fix number of arguments check in flatten() (e80207b)
  65 +
  66 +2013-03-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
  67 + * Add contributing document (96e19d0)
  68 +
  69 +2013-03-04 - Raphaël Pinson <raphael.pinson@camptocamp.com> - 4.0.0
  70 + * Add missing documentation for validate_augeas and validate_cmd to README.markdown (a1510a1)
  71 +
  72 +2013-02-14 - Joshua Hoblitt <jhoblitt@cpan.org> - 4.0.0
  73 + * (#19272) Add has_element() function (95cf3fe)
  74 +
  75 +2013-02-07 - Raphaël Pinson <raphael.pinson@camptocamp.com> - 4.0.0
  76 + * validate_cmd(): Use Puppet::Util::Execution.execute when available (69248df)
  77 +
  78 +2012-12-06 - Raphaël Pinson <raphink@gmail.com> - 4.0.0
  79 + * Add validate_augeas function (3a97c23)
  80 +
  81 +2012-12-06 - Raphaël Pinson <raphink@gmail.com> - 4.0.0
  82 + * Add validate_cmd function (6902cc5)
  83 +
  84 +2013-01-14 - David Schmitt <david@dasz.at> - 4.0.0
  85 + * Add geppetto project definition (b3fc0a3)
  86 +
  87 +2013-01-02 - Jaka Hudoklin <jakahudoklin@gmail.com> - 4.0.0
  88 + * Add getparam function to get defined resource parameters (20e0e07)
  89 +
  90 +2013-01-05 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
  91 + * (maint) Add Travis CI Support (d082046)
  92 +
  93 +2012-12-04 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
  94 + * Clarify that stdlib 3 supports Puppet 3 (3a6085f)
  95 +
  96 +2012-11-30 - Erik Dalén <dalen@spotify.com> - 4.0.0
  97 + * maint: style guideline fixes (7742e5f)
  98 +
  99 +2012-11-09 - James Fryman <james@frymanet.com> - 4.0.0
  100 + * puppet-lint cleanup (88acc52)
  101 +
  102 +2012-11-06 - Joe Julian <me@joejulian.name> - 4.0.0
  103 + * Add function, uriescape, to URI.escape strings. Redmine #17459 (fd52b8d)
  104 +
  105 +2012-09-18 - Chad Metcalf <chad@wibidata.com> - 3.2.0
  106 + * Add an ensure_packages function. (8a8c09e)
  107 +
  108 +2012-11-23 - Erik Dalén <dalen@spotify.com> - 3.2.0
  109 + * (#17797) min() and max() functions (9954133)
  110 +
  111 +2012-05-23 - Peter Meier <peter.meier@immerda.ch> - 3.2.0
  112 + * (#14670) autorequire a file_line resource's path (dfcee63)
  113 +
  114 +2012-11-19 - Joshua Harlan Lifton <lifton@puppetlabs.com> - 3.2.0
  115 + * Add join_keys_to_values function (ee0f2b3)
  116 +
  117 +2012-11-17 - Joshua Harlan Lifton <lifton@puppetlabs.com> - 3.2.0
  118 + * Extend delete function for strings and hashes (7322e4d)
  119 +
  120 +2012-08-03 - Gary Larizza <gary@puppetlabs.com> - 3.2.0
  121 + * Add the pick() function (ba6dd13)
  122 +
  123 +2012-03-20 - Wil Cooley <wcooley@pdx.edu> - 3.2.0
  124 + * (#13974) Add predicate functions for interface facts (f819417)
  125 +
  126 +2012-11-06 - Joe Julian <me@joejulian.name> - 3.2.0
  127 + * Add function, uriescape, to URI.escape strings. Redmine #17459 (70f4a0e)
  128 +
  129 +2012-10-25 - Jeff McCune <jeff@puppetlabs.com> - 3.1.1
  130 + * (maint) Fix spec failures resulting from Facter API changes (97f836f)
  131 +
  132 +2012-10-23 - Matthaus Owens <matthaus@puppetlabs.com> - 3.1.0
  133 + * Add PE facts to stdlib (cdf3b05)
  134 +
  135 +2012-08-16 - Jeff McCune <jeff@puppetlabs.com> - 3.0.1
  136 + * Fix accidental removal of facts_dot_d.rb in 3.0.0 release
  137 +
  138 +2012-08-16 - Jeff McCune <jeff@puppetlabs.com> - 3.0.0
  139 + * stdlib 3.0 drops support with Puppet 2.6
  140 + * stdlib 3.0 preserves support with Puppet 2.7
  141 +
  142 +2012-08-07 - Dan Bode <dan@puppetlabs.com> - 3.0.0
  143 + * Add function ensure_resource and defined_with_params (ba789de)
  144 +
  145 +2012-07-10 - Hailee Kenney <hailee@puppetlabs.com> - 3.0.0
  146 + * (#2157) Remove facter_dot_d for compatibility with external facts (f92574f)
  147 +
  148 +2012-04-10 - Chris Price <chris@puppetlabs.com> - 3.0.0
  149 + * (#13693) moving logic from local spec_helper to puppetlabs_spec_helper (85f96df)
  150 +
  151 +2012-10-25 - Jeff McCune <jeff@puppetlabs.com> - 2.5.1
  152 + * (maint) Fix spec failures resulting from Facter API changes (97f836f)
  153 +
  154 +2012-10-23 - Matthaus Owens <matthaus@puppetlabs.com> - 2.5.0
  155 + * Add PE facts to stdlib (cdf3b05)
  156 +
  157 +2012-08-15 - Dan Bode <dan@puppetlabs.com> - 2.5.0
  158 + * Explicitly load functions used by ensure_resource (9fc3063)
  159 +
  160 +2012-08-13 - Dan Bode <dan@puppetlabs.com> - 2.5.0
  161 + * Add better docs about duplicate resource failures (97d327a)
  162 +
  163 +2012-08-13 - Dan Bode <dan@puppetlabs.com> - 2.5.0
  164 + * Handle undef for parameter argument (4f8b133)
  165 +
  166 +2012-08-07 - Dan Bode <dan@puppetlabs.com> - 2.5.0
  167 + * Add function ensure_resource and defined_with_params (a0cb8cd)
  168 +
  169 +2012-08-20 - Jeff McCune <jeff@puppetlabs.com> - 2.5.0
  170 + * Disable tests that fail on 2.6.x due to #15912 (c81496e)
  171 +
  172 +2012-08-20 - Jeff McCune <jeff@puppetlabs.com> - 2.5.0
  173 + * (Maint) Fix mis-use of rvalue functions as statements (4492913)
  174 +
  175 +2012-08-20 - Jeff McCune <jeff@puppetlabs.com> - 2.5.0
  176 + * Add .rspec file to repo root (88789e8)
  177 +
  178 +2012-06-07 - Chris Price <chris@puppetlabs.com> - 2.4.0
  179 + * Add support for a 'match' parameter to file_line (a06c0d8)
  180 +
  181 +2012-08-07 - Erik Dalén <dalen@spotify.com> - 2.4.0
  182 + * (#15872) Add to_bytes function (247b69c)
  183 +
  184 +2012-07-19 - Jeff McCune <jeff@puppetlabs.com> - 2.4.0
  185 + * (Maint) use PuppetlabsSpec::PuppetInternals.scope (master) (deafe88)
  186 +
  187 +2012-07-10 - Hailee Kenney <hailee@puppetlabs.com> - 2.4.0
  188 + * (#2157) Make facts_dot_d compatible with external facts (5fb0ddc)
  189 +
  190 +2012-03-16 - Steve Traylen <steve.traylen@cern.ch> - 2.4.0
  191 + * (#13205) Rotate array/string randomley based on fqdn, fqdn_rotate() (fef247b)
  192 +
  193 +2012-05-22 - Peter Meier <peter.meier@immerda.ch> - 2.3.3
  194 + * fix regression in #11017 properly (f0a62c7)
  195 +
  196 +2012-05-10 - Jeff McCune <jeff@puppetlabs.com> - 2.3.3
  197 + * Fix spec tests using the new spec_helper (7d34333)
  198 +
  199 +2012-05-10 - Puppet Labs <support@puppetlabs.com> - 2.3.2
  200 + * Make file_line default to ensure => present (1373e70)
  201 + * Memoize file_line spec instance variables (20aacc5)
  202 + * Fix spec tests using the new spec_helper (1ebfa5d)
  203 + * (#13595) initialize_everything_for_tests couples modules Puppet ver (3222f35)
  204 + * (#13439) Fix MRI 1.9 issue with spec_helper (15c5fd1)
  205 + * (#13439) Fix test failures with Puppet 2.6.x (665610b)
  206 + * (#13439) refactor spec helper for compatibility with both puppet 2.7 and master (82194ca)
  207 + * (#13494) Specify the behavior of zero padded strings (61891bb)
  208 +
  209 +2012-03-29 Puppet Labs <support@puppetlabs.com> - 2.1.3
  210 +* (#11607) Add Rakefile to enable spec testing
  211 +* (#12377) Avoid infinite loop when retrying require json
  212 +
  213 +2012-03-13 Puppet Labs <support@puppetlabs.com> - 2.3.1
  214 +* (#13091) Fix LoadError bug with puppet apply and puppet_vardir fact
  215 +
  216 +2012-03-12 Puppet Labs <support@puppetlabs.com> - 2.3.0
  217 +* Add a large number of new Puppet functions
  218 +* Backwards compatibility preserved with 2.2.x
  219 +
  220 +2011-12-30 Puppet Labs <support@puppetlabs.com> - 2.2.1
  221 +* Documentation only release for the Forge
  222 +
  223 +2011-12-30 Puppet Labs <support@puppetlabs.com> - 2.1.2
  224 +* Documentation only release for PE 2.0.x
  225 +
  226 +2011-11-08 Puppet Labs <support@puppetlabs.com> - 2.2.0
  227 +* #10285 - Refactor json to use pson instead.
  228 +* Maint - Add watchr autotest script
  229 +* Maint - Make rspec tests work with Puppet 2.6.4
  230 +* #9859 - Add root_home fact and tests
  231 +
  232 +2011-08-18 Puppet Labs <support@puppetlabs.com> - 2.1.1
  233 +* Change facts.d paths to match Facter 2.0 paths.
  234 +* /etc/facter/facts.d
  235 +* /etc/puppetlabs/facter/facts.d
  236 +
  237 +2011-08-17 Puppet Labs <support@puppetlabs.com> - 2.1.0
  238 +* Add R.I. Pienaar's facts.d custom facter fact
  239 +* facts defined in /etc/facts.d and /etc/puppetlabs/facts.d are
  240 + automatically loaded now.
  241 +
  242 +2011-08-04 Puppet Labs <support@puppetlabs.com> - 2.0.0
  243 +* Rename whole_line to file_line
  244 +* This is an API change and as such motivating a 2.0.0 release according to semver.org.
  245 +
  246 +2011-08-04 Puppet Labs <support@puppetlabs.com> - 1.1.0
  247 +* Rename append_line to whole_line
  248 +* This is an API change and as such motivating a 1.1.0 release.
  249 +
  250 +2011-08-04 Puppet Labs <support@puppetlabs.com> - 1.0.0
  251 +* Initial stable release
  252 +* Add validate_array and validate_string functions
  253 +* Make merge() function work with Ruby 1.8.5
  254 +* Add hash merging function
  255 +* Add has_key function
  256 +* Add loadyaml() function
  257 +* Add append_line native
  258 +
  259 +2011-06-21 Jeff McCune <jeff@puppetlabs.com> - 0.1.7
  260 +* Add validate_hash() and getvar() functions
  261 +
  262 +2011-06-15 Jeff McCune <jeff@puppetlabs.com> - 0.1.6
  263 +* Add anchor resource type to provide containment for composite classes
  264 +
  265 +2011-06-03 Jeff McCune <jeff@puppetlabs.com> - 0.1.5
  266 +* Add validate_bool() function to stdlib
  267 +
  268 +0.1.4 2011-05-26 Jeff McCune <jeff@puppetlabs.com>
  269 +* Move most stages after main
  270 +
  271 +0.1.3 2011-05-25 Jeff McCune <jeff@puppetlabs.com>
  272 +* Add validate_re() function
  273 +
  274 +0.1.2 2011-05-24 Jeff McCune <jeff@puppetlabs.com>
  275 +* Update to add annotated tag
  276 +
  277 +0.1.1 2011-05-24 Jeff McCune <jeff@puppetlabs.com>
  278 +* Add stdlib::stages class with a standard set of stages
... ...
puppet/modules/stdlib/CONTRIBUTING.md 0 → 100644
... ... @@ -0,0 +1,65 @@
  1 +# How to contribute
  2 +
  3 +Third-party patches are essential for keeping stdlib great. We simply can't
  4 +access the huge number of platforms and myriad configurations for running
  5 +stdlib. We want to keep it as easy as possible to contribute changes that
  6 +get things working in your environment. There are a few guidelines that we
  7 +need contributors to follow so that we can have a chance of keeping on
  8 +top of things.
  9 +
  10 +## Getting Started
  11 +
  12 +* Make sure you have a [Redmine account](http://projects.puppetlabs.com)
  13 +* Make sure you have a [GitHub account](https://github.com/signup/free)
  14 +* Submit a ticket for your issue, assuming one does not already exist.
  15 + * Clearly describe the issue including steps to reproduce when it is a bug.
  16 + * Make sure you fill in the earliest version that you know has the issue.
  17 +* Fork the repository on GitHub
  18 +
  19 +## Making Changes
  20 +
  21 +* Create a topic branch from where you want to base your work.
  22 + * This is usually the master branch.
  23 + * Only target release branches if you are certain your fix must be on that
  24 + branch.
  25 + * To quickly create a topic branch based on master; `git branch
  26 + fix/master/my_contribution master` then checkout the new branch with `git
  27 + checkout fix/master/my_contribution`. Please avoid working directly on the
  28 + `master` branch.
  29 +* Make commits of logical units.
  30 +* Check for unnecessary whitespace with `git diff --check` before committing.
  31 +* Make sure your commit messages are in the proper format.
  32 +
  33 +````
  34 + (#99999) Make the example in CONTRIBUTING imperative and concrete
  35 +
  36 + Without this patch applied the example commit message in the CONTRIBUTING
  37 + document is not a concrete example. This is a problem because the
  38 + contributor is left to imagine what the commit message should look like
  39 + based on a description rather than an example. This patch fixes the
  40 + problem by making the example concrete and imperative.
  41 +
  42 + The first line is a real life imperative statement with a ticket number
  43 + from our issue tracker. The body describes the behavior without the patch,
  44 + why this is a problem, and how the patch fixes the problem when applied.
  45 +````
  46 +
  47 +* Make sure you have added the necessary tests for your changes.
  48 +* Run _all_ the tests to assure nothing else was accidentally broken.
  49 +
  50 +## Submitting Changes
  51 +
  52 +* Sign the [Contributor License Agreement](http://links.puppetlabs.com/cla).
  53 +* Push your changes to a topic branch in your fork of the repository.
  54 +* Submit a pull request to the repository in the puppetlabs organization.
  55 +* Update your Redmine ticket to mark that you have submitted code and are ready for it to be reviewed.
  56 + * Include a link to the pull request in the ticket
  57 +
  58 +# Additional Resources
  59 +
  60 +* [More information on contributing](http://links.puppetlabs.com/contribute-to-puppet)
  61 +* [Bug tracker (Redmine)](http://projects.puppetlabs.com)
  62 +* [Contributor License Agreement](http://links.puppetlabs.com/cla)
  63 +* [General GitHub documentation](http://help.github.com/)
  64 +* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
  65 +* #puppet-dev IRC channel on freenode.org
... ...
puppet/modules/stdlib/Gemfile 0 → 100644
... ... @@ -0,0 +1,42 @@
  1 +source "https://rubygems.org"
  2 +
  3 +def location_for(place, fake_version = nil)
  4 + mdata = /^(git:[^#]*)#(.*)/.match(place)
  5 + if mdata
  6 + [fake_version, { :git => mdata[1], :branch => mdata[2], :require => false }].compact
  7 + elsif place =~ /^file:\/\/(.*)/
  8 + ['>= 0', { :path => File.expand_path(mdata[1]), :require => false }]
  9 + else
  10 + [place, { :require => false }]
  11 + end
  12 +end
  13 +
  14 +group :development do
  15 + gem 'watchr'
  16 +end
  17 +
  18 +group :development, :test do
  19 + gem 'rake'
  20 + gem 'puppetmodule-stdlib', ">= 1.0.0", :path => File.expand_path("..", __FILE__)
  21 + gem 'rspec', "~> 2.11.0", :require => false
  22 + gem 'mocha', "~> 0.10.5", :require => false
  23 + gem 'puppetlabs_spec_helper', :require => false
  24 + gem 'rspec-puppet', :require => false
  25 +end
  26 +
  27 +facterversion = ENV['GEM_FACTER_VERSION']
  28 +if facterversion
  29 + gem 'facter', *location_for(facterversion)
  30 +else
  31 + gem 'facter', :require => false
  32 +end
  33 +
  34 +ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION']
  35 +puppetversion = ENV['GEM_PUPPET_VERSION']
  36 +if puppetversion
  37 + gem 'puppet', *location_for(puppetversion)
  38 +else
  39 + gem 'puppet', :require => false
  40 +end
  41 +
  42 +# vim:ft=ruby
... ...
puppet/modules/stdlib/LICENSE 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +Copyright (C) 2011 Puppet Labs Inc
  2 +
  3 +and some parts:
  4 +
  5 +Copyright (C) 2011 Krzysztof Wilczynski
  6 +
  7 +Puppet Labs can be contacted at: info@puppetlabs.com
  8 +
  9 +Licensed under the Apache License, Version 2.0 (the "License");
  10 +you may not use this file except in compliance with the License.
  11 +You may obtain a copy of the License at
  12 +
  13 + http://www.apache.org/licenses/LICENSE-2.0
  14 +
  15 +Unless required by applicable law or agreed to in writing, software
  16 +distributed under the License is distributed on an "AS IS" BASIS,
  17 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18 +See the License for the specific language governing permissions and
  19 +limitations under the License.
... ...
puppet/modules/stdlib/Modulefile 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +name 'puppetlabs-stdlib'
  2 +version '4.1.0'
  3 +source 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
  4 +author 'puppetlabs'
  5 +license 'Apache 2.0'
  6 +summary 'Puppet Module Standard Library'
  7 +description 'Standard Library for Puppet Modules'
  8 +project_page 'https://github.com/puppetlabs/puppetlabs-stdlib'
  9 +
  10 +## Add dependencies, if any:
  11 +# dependency 'username/name', '>= 1.2.0'
... ...
puppet/modules/stdlib/README.markdown 0 → 100644
... ... @@ -0,0 +1,1194 @@
  1 +# Puppet Labs Standard Library #
  2 +
  3 +[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-stdlib.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-stdlib)
  4 +
  5 +This module provides a "standard library" of resources for developing Puppet
  6 +Modules. This modules will include the following additions to Puppet
  7 +
  8 + * Stages
  9 + * Facts
  10 + * Functions
  11 + * Defined resource types
  12 + * Types
  13 + * Providers
  14 +
  15 +This module is officially curated and provided by Puppet Labs. The modules
  16 +Puppet Labs writes and distributes will make heavy use of this standard
  17 +library.
  18 +
  19 +To report or research a bug with any part of this module, please go to
  20 +[http://projects.puppetlabs.com/projects/stdlib](http://projects.puppetlabs.com/projects/stdlib)
  21 +
  22 +# Versions #
  23 +
  24 +This module follows semver.org (v1.0.0) versioning guidelines. The standard
  25 +library module is released as part of [Puppet
  26 +Enterprise](http://puppetlabs.com/puppet/puppet-enterprise/) and as a result
  27 +older versions of Puppet Enterprise that Puppet Labs still supports will have
  28 +bugfix maintenance branches periodically "merged up" into master. The current
  29 +list of integration branches are:
  30 +
  31 + * v2.1.x (v2.1.1 released in PE 1)
  32 + * v2.2.x (Never released as part of PE, only to the Forge)
  33 + * v2.3.x (Released in PE 2)
  34 + * v3.0.x (Never released as part of PE, only to the Forge)
  35 + * v4.0.x (Drops support for Puppet 2.7)
  36 + * master (mainline development branch)
  37 +
  38 +The first Puppet Enterprise version including the stdlib module is Puppet
  39 +Enterprise 1.2.
  40 +
  41 +# Compatibility #
  42 +
  43 +Puppet Versions | < 2.6 | 2.6 | 2.7 | 3.x |
  44 +:---------------|:-----:|:---:|:---:|:----:
  45 +**stdlib 2.x** | no | **yes** | **yes** | no
  46 +**stdlib 3.x** | no | no | **yes** | **yes**
  47 +**stdlib 4.x** | no | no | no | **yes**
  48 +
  49 +The stdlib module does not work with Puppet versions released prior to Puppet
  50 +2.6.0.
  51 +
  52 +## stdlib 2.x ##
  53 +
  54 +All stdlib releases in the 2.0 major version support Puppet 2.6 and Puppet 2.7.
  55 +
  56 +## stdlib 3.x ##
  57 +
  58 +The 3.0 major release of stdlib drops support for Puppet 2.6. Stdlib 3.x
  59 +supports Puppet 2 and Puppet 3.
  60 +
  61 +## stdlib 4.x ##
  62 +
  63 +The 4.0 major release of stdlib drops support for Puppet 2.7. Stdlib 4.x
  64 +supports Puppet 3. Notably, ruby 1.8.5 is no longer supported though ruby
  65 +1.8.7, 1.9.3, and 2.0.0 are fully supported.
  66 +
  67 +# Functions #
  68 +
  69 +abs
  70 +---
  71 +Returns the absolute value of a number, for example -34.56 becomes
  72 +34.56. Takes a single integer and float value as an argument.
  73 +
  74 +
  75 +- *Type*: rvalue
  76 +
  77 +any2array
  78 +---------
  79 +This converts any object to an array containing that object. Empty argument
  80 +lists are converted to an empty array. Arrays are left untouched. Hashes are
  81 +converted to arrays of alternating keys and values.
  82 +
  83 +
  84 +- *Type*: rvalue
  85 +
  86 +bool2num
  87 +--------
  88 +Converts a boolean to a number. Converts the values:
  89 +false, f, 0, n, and no to 0
  90 +true, t, 1, y, and yes to 1
  91 + Requires a single boolean or string as an input.
  92 +
  93 +
  94 +- *Type*: rvalue
  95 +
  96 +capitalize
  97 +----------
  98 +Capitalizes the first letter of a string or array of strings.
  99 +Requires either a single string or an array as an input.
  100 +
  101 +
  102 +- *Type*: rvalue
  103 +
  104 +chomp
  105 +-----
  106 +Removes the record separator from the end of a string or an array of
  107 +strings, for example `hello\n` becomes `hello`.
  108 +Requires a single string or array as an input.
  109 +
  110 +
  111 +- *Type*: rvalue
  112 +
  113 +chop
  114 +----
  115 +Returns a new string with the last character removed. If the string ends
  116 +with `\r\n`, both characters are removed. Applying chop to an empty
  117 +string returns an empty string. If you wish to merely remove record
  118 +separators then you should use the `chomp` function.
  119 +Requires a string or array of strings as input.
  120 +
  121 +
  122 +- *Type*: rvalue
  123 +
  124 +concat
  125 +------
  126 +Appends the contents of array 2 onto array 1.
  127 +
  128 +*Example:*
  129 +
  130 + concat(['1','2','3'],['4','5','6'])
  131 +
  132 +Would result in:
  133 +
  134 + ['1','2','3','4','5','6']
  135 +
  136 +
  137 +- *Type*: rvalue
  138 +
  139 +count
  140 +-----
  141 +Takes an array as first argument and an optional second argument.
  142 +Count the number of elements in array that matches second argument.
  143 +If called with only an array it counts the number of elements that are not nil/undef.
  144 +
  145 +
  146 +- *Type*: rvalue
  147 +
  148 +defined_with_params
  149 +-------------------
  150 +Takes a resource reference and an optional hash of attributes.
  151 +
  152 +Returns true if a resource with the specified attributes has already been added
  153 +to the catalog, and false otherwise.
  154 +
  155 + user { 'dan':
  156 + ensure => present,
  157 + }
  158 +
  159 + if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
  160 + user { 'dan': ensure => present, }
  161 + }
  162 +
  163 +
  164 +- *Type*: rvalue
  165 +
  166 +delete
  167 +------
  168 +Deletes all instances of a given element from an array, substring from a
  169 +string, or key from a hash.
  170 +
  171 +*Examples:*
  172 +
  173 + delete(['a','b','c','b'], 'b')
  174 + Would return: ['a','c']
  175 +
  176 + delete({'a'=>1,'b'=>2,'c'=>3}, 'b')
  177 + Would return: {'a'=>1,'c'=>3}
  178 +
  179 + delete('abracadabra', 'bra')
  180 + Would return: 'acada'
  181 +
  182 +
  183 +- *Type*: rvalue
  184 +
  185 +delete_at
  186 +---------
  187 +Deletes a determined indexed value from an array.
  188 +
  189 +*Examples:*
  190 +
  191 + delete_at(['a','b','c'], 1)
  192 +
  193 +Would return: ['a','c']
  194 +
  195 +
  196 +- *Type*: rvalue
  197 +
  198 +dirname
  199 +-------
  200 +Returns the `dirname` of a path.
  201 +
  202 +*Examples:*
  203 +
  204 + dirname('/path/to/a/file.ext')
  205 +
  206 +Would return: '/path/to/a'
  207 +
  208 +downcase
  209 +--------
  210 +Converts the case of a string or all strings in an array to lower case.
  211 +
  212 +
  213 +- *Type*: rvalue
  214 +
  215 +empty
  216 +-----
  217 +Returns true if the variable is empty.
  218 +
  219 +
  220 +- *Type*: rvalue
  221 +
  222 +ensure_packages
  223 +---------------
  224 +Takes a list of packages and only installs them if they don't already exist.
  225 +
  226 +
  227 +- *Type*: statement
  228 +
  229 +ensure_resource
  230 +---------------
  231 +Takes a resource type, title, and a list of attributes that describe a
  232 +resource.
  233 +
  234 + user { 'dan':
  235 + ensure => present,
  236 + }
  237 +
  238 +This example only creates the resource if it does not already exist:
  239 +
  240 + ensure_resource('user, 'dan', {'ensure' => 'present' })
  241 +
  242 +If the resource already exists but does not match the specified parameters,
  243 +this function will attempt to recreate the resource leading to a duplicate
  244 +resource definition error.
  245 +
  246 +An array of resources can also be passed in and each will be created with
  247 +the type and parameters specified if it doesn't already exist.
  248 +
  249 + ensure_resource('user', ['dan','alex'], {'ensure' => 'present'})
  250 +
  251 +
  252 +
  253 +- *Type*: statement
  254 +
  255 +flatten
  256 +-------
  257 +This function flattens any deeply nested arrays and returns a single flat array
  258 +as a result.
  259 +
  260 +*Examples:*
  261 +
  262 + flatten(['a', ['b', ['c']]])
  263 +
  264 +Would return: ['a','b','c']
  265 +
  266 +
  267 +- *Type*: rvalue
  268 +
  269 +floor
  270 +-----
  271 +Returns the largest integer less or equal to the argument.
  272 +Takes a single numeric value as an argument.
  273 +
  274 +
  275 +- *Type*: rvalue
  276 +
  277 +fqdn_rotate
  278 +-----------
  279 +Rotates an array a random number of times based on a nodes fqdn.
  280 +
  281 +
  282 +- *Type*: rvalue
  283 +
  284 +get_module_path
  285 +---------------
  286 +Returns the absolute path of the specified module for the current
  287 +environment.
  288 +
  289 +Example:
  290 + $module_path = get_module_path('stdlib')
  291 +
  292 +
  293 +- *Type*: rvalue
  294 +
  295 +getparam
  296 +--------
  297 +Takes a resource reference and name of the parameter and
  298 +returns value of resource's parameter.
  299 +
  300 +*Examples:*
  301 +
  302 + define example_resource($param) {
  303 + }
  304 +
  305 + example_resource { "example_resource_instance":
  306 + param => "param_value"
  307 + }
  308 +
  309 + getparam(Example_resource["example_resource_instance"], "param")
  310 +
  311 +Would return: param_value
  312 +
  313 +
  314 +- *Type*: rvalue
  315 +
  316 +getvar
  317 +------
  318 +Lookup a variable in a remote namespace.
  319 +
  320 +For example:
  321 +
  322 + $foo = getvar('site::data::foo')
  323 + # Equivalent to $foo = $site::data::foo
  324 +
  325 +This is useful if the namespace itself is stored in a string:
  326 +
  327 + $datalocation = 'site::data'
  328 + $bar = getvar("${datalocation}::bar")
  329 + # Equivalent to $bar = $site::data::bar
  330 +
  331 +
  332 +- *Type*: rvalue
  333 +
  334 +grep
  335 +----
  336 +This function searches through an array and returns any elements that match
  337 +the provided regular expression.
  338 +
  339 +*Examples:*
  340 +
  341 + grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
  342 +
  343 +Would return:
  344 +
  345 + ['aaa','aaaddd']
  346 +
  347 +
  348 +- *Type*: rvalue
  349 +
  350 +has_interface_with
  351 +------------------
  352 +Returns boolean based on kind and value:
  353 +* macaddress
  354 +* netmask
  355 +* ipaddress
  356 +* network
  357 +
  358 +has_interface_with("macaddress", "x:x:x:x:x:x")
  359 +has_interface_with("ipaddress", "127.0.0.1") => true
  360 +etc.
  361 +
  362 +If no "kind" is given, then the presence of the interface is checked:
  363 +has_interface_with("lo") => true
  364 +
  365 +
  366 +- *Type*: rvalue
  367 +
  368 +has_ip_address
  369 +--------------
  370 +Returns true if the client has the requested IP address on some interface.
  371 +
  372 +This function iterates through the 'interfaces' fact and checks the
  373 +'ipaddress_IFACE' facts, performing a simple string comparison.
  374 +
  375 +
  376 +- *Type*: rvalue
  377 +
  378 +has_ip_network
  379 +--------------
  380 +Returns true if the client has an IP address within the requested network.
  381 +
  382 +This function iterates through the 'interfaces' fact and checks the
  383 +'network_IFACE' facts, performing a simple string comparision.
  384 +
  385 +
  386 +- *Type*: rvalue
  387 +
  388 +has_key
  389 +-------
  390 +Determine if a hash has a certain key value.
  391 +
  392 +Example:
  393 +
  394 + $my_hash = {'key_one' => 'value_one'}
  395 + if has_key($my_hash, 'key_two') {
  396 + notice('we will not reach here')
  397 + }
  398 + if has_key($my_hash, 'key_one') {
  399 + notice('this will be printed')
  400 + }
  401 +
  402 +
  403 +
  404 +- *Type*: rvalue
  405 +
  406 +hash
  407 +----
  408 +This function converts an array into a hash.
  409 +
  410 +*Examples:*
  411 +
  412 + hash(['a',1,'b',2,'c',3])
  413 +
  414 +Would return: {'a'=>1,'b'=>2,'c'=>3}
  415 +
  416 +
  417 +- *Type*: rvalue
  418 +
  419 +is_array
  420 +--------
  421 +Returns true if the variable passed to this function is an array.
  422 +
  423 +- *Type*: rvalue
  424 +
  425 +is_domain_name
  426 +--------------
  427 +Returns true if the string passed to this function is a syntactically correct domain name.
  428 +
  429 +- *Type*: rvalue
  430 +
  431 +is_float
  432 +--------
  433 +Returns true if the variable passed to this function is a float.
  434 +
  435 +- *Type*: rvalue
  436 +
  437 +is_function_available
  438 +---------------------
  439 +This function accepts a string as an argument, determines whether the
  440 +Puppet runtime has access to a function by that name. It returns a
  441 +true if the function exists, false if not.
  442 +
  443 +- *Type*: rvalue
  444 +
  445 +is_hash
  446 +-------
  447 +Returns true if the variable passed to this function is a hash.
  448 +
  449 +- *Type*: rvalue
  450 +
  451 +is_integer
  452 +----------
  453 +Returns true if the variable returned to this string is an integer.
  454 +
  455 +- *Type*: rvalue
  456 +
  457 +is_ip_address
  458 +-------------
  459 +Returns true if the string passed to this function is a valid IP address.
  460 +
  461 +- *Type*: rvalue
  462 +
  463 +is_mac_address
  464 +--------------
  465 +Returns true if the string passed to this function is a valid mac address.
  466 +
  467 +- *Type*: rvalue
  468 +
  469 +is_numeric
  470 +----------
  471 +Returns true if the variable passed to this function is a number.
  472 +
  473 +- *Type*: rvalue
  474 +
  475 +is_string
  476 +---------
  477 +Returns true if the variable passed to this function is a string.
  478 +
  479 +- *Type*: rvalue
  480 +
  481 +join
  482 +----
  483 +This function joins an array into a string using a seperator.
  484 +
  485 +*Examples:*
  486 +
  487 + join(['a','b','c'], ",")
  488 +
  489 +Would result in: "a,b,c"
  490 +
  491 +- *Type*: rvalue
  492 +
  493 +join_keys_to_values
  494 +-------------------
  495 +This function joins each key of a hash to that key's corresponding value with a
  496 +separator. Keys and values are cast to strings. The return value is an array in
  497 +which each element is one joined key/value pair.
  498 +
  499 +*Examples:*
  500 +
  501 + join_keys_to_values({'a'=>1,'b'=>2}, " is ")
  502 +
  503 +Would result in: ["a is 1","b is 2"]
  504 +
  505 +- *Type*: rvalue
  506 +
  507 +keys
  508 +----
  509 +Returns the keys of a hash as an array.
  510 +
  511 +- *Type*: rvalue
  512 +
  513 +loadyaml
  514 +--------
  515 +Load a YAML file containing an array, string, or hash, and return the data
  516 +in the corresponding native data type.
  517 +
  518 +For example:
  519 +
  520 + $myhash = loadyaml('/etc/puppet/data/myhash.yaml')
  521 +
  522 +
  523 +- *Type*: rvalue
  524 +
  525 +lstrip
  526 +------
  527 +Strips leading spaces to the left of a string.
  528 +
  529 +- *Type*: rvalue
  530 +
  531 +max
  532 +---
  533 +Returns the highest value of all arguments.
  534 +Requires at least one argument.
  535 +
  536 +- *Type*: rvalue
  537 +
  538 +member
  539 +------
  540 +This function determines if a variable is a member of an array.
  541 +
  542 +*Examples:*
  543 +
  544 + member(['a','b'], 'b')
  545 +
  546 +Would return: true
  547 +
  548 + member(['a','b'], 'c')
  549 +
  550 +Would return: false
  551 +
  552 +- *Type*: rvalue
  553 +
  554 +merge
  555 +-----
  556 +Merges two or more hashes together and returns the resulting hash.
  557 +
  558 +For example:
  559 +
  560 + $hash1 = {'one' => 1, 'two', => 2}
  561 + $hash2 = {'two' => 'dos', 'three', => 'tres'}
  562 + $merged_hash = merge($hash1, $hash2)
  563 + # The resulting hash is equivalent to:
  564 + # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'}
  565 +
  566 +When there is a duplicate key, the key in the rightmost hash will "win."
  567 +
  568 +- *Type*: rvalue
  569 +
  570 +min
  571 +---
  572 +Returns the lowest value of all arguments.
  573 +Requires at least one argument.
  574 +
  575 +- *Type*: rvalue
  576 +
  577 +num2bool
  578 +--------
  579 +This function converts a number or a string representation of a number into a
  580 +true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0
  581 +become true.
  582 +
  583 +- *Type*: rvalue
  584 +
  585 +parsejson
  586 +---------
  587 +This function accepts JSON as a string and converts into the correct Puppet
  588 +structure.
  589 +
  590 +- *Type*: rvalue
  591 +
  592 +parseyaml
  593 +---------
  594 +This function accepts YAML as a string and converts it into the correct
  595 +Puppet structure.
  596 +
  597 +- *Type*: rvalue
  598 +
  599 +pick
  600 +----
  601 +This function is similar to a coalesce function in SQL in that it will return
  602 +the first value in a list of values that is not undefined or an empty string
  603 +(two things in Puppet that will return a boolean false value). Typically,
  604 +this function is used to check for a value in the Puppet Dashboard/Enterprise
  605 +Console, and failover to a default value like the following:
  606 +
  607 + $real_jenkins_version = pick($::jenkins_version, '1.449')
  608 +
  609 +The value of $real_jenkins_version will first look for a top-scope variable
  610 +called 'jenkins_version' (note that parameters set in the Puppet Dashboard/
  611 +Enterprise Console are brought into Puppet as top-scope variables), and,
  612 +failing that, will use a default value of 1.449.
  613 +
  614 +- *Type*: rvalue
  615 +
  616 +prefix
  617 +------
  618 +This function applies a prefix to all elements in an array.
  619 +
  620 +*Examples:*
  621 +
  622 + prefix(['a','b','c'], 'p')
  623 +
  624 +Will return: ['pa','pb','pc']
  625 +
  626 +- *Type*: rvalue
  627 +
  628 +range
  629 +-----
  630 +When given range in the form of (start, stop) it will extrapolate a range as
  631 +an array.
  632 +
  633 +*Examples:*
  634 +
  635 + range("0", "9")
  636 +
  637 +Will return: [0,1,2,3,4,5,6,7,8,9]
  638 +
  639 + range("00", "09")
  640 +
  641 +Will return: [0,1,2,3,4,5,6,7,8,9] (Zero padded strings are converted to
  642 +integers automatically)
  643 +
  644 + range("a", "c")
  645 +
  646 +Will return: ["a","b","c"]
  647 +
  648 + range("host01", "host10")
  649 +
  650 +Will return: ["host01", "host02", ..., "host09", "host10"]
  651 +
  652 +- *Type*: rvalue
  653 +
  654 +reject
  655 +------
  656 +This function searches through an array and rejects all elements that match
  657 +the provided regular expression.
  658 +
  659 +*Examples:*
  660 +
  661 + reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
  662 +
  663 +Would return:
  664 +
  665 + ['bbb','ccc']
  666 +
  667 +
  668 +- *Type*: rvalue
  669 +
  670 +reverse
  671 +-------
  672 +Reverses the order of a string or array.
  673 +
  674 +- *Type*: rvalue
  675 +
  676 +rstrip
  677 +------
  678 +Strips leading spaces to the right of the string.
  679 +
  680 +- *Type*: rvalue
  681 +
  682 +shuffle
  683 +-------
  684 +Randomizes the order of a string or array elements.
  685 +
  686 +- *Type*: rvalue
  687 +
  688 +size
  689 +----
  690 +Returns the number of elements in a string or array.
  691 +
  692 +- *Type*: rvalue
  693 +
  694 +sort
  695 +----
  696 +Sorts strings and arrays lexically.
  697 +
  698 +- *Type*: rvalue
  699 +
  700 +squeeze
  701 +-------
  702 +Returns a new string where runs of the same character that occur in this set
  703 +are replaced by a single character.
  704 +
  705 +- *Type*: rvalue
  706 +
  707 +str2bool
  708 +--------
  709 +This converts a string to a boolean. This attempt to convert strings that
  710 +contain things like: y, 1, t, true to 'true' and strings that contain things
  711 +like: 0, f, n, false, no to 'false'.
  712 +
  713 +
  714 +- *Type*: rvalue
  715 +
  716 +str2saltedsha512
  717 +----------------
  718 +This converts a string to a salted-SHA512 password hash (which is used for
  719 +OS X versions >= 10.7). Given any simple string, you will get a hex version
  720 +of a salted-SHA512 password hash that can be inserted into your Puppet
  721 +manifests as a valid password attribute.
  722 +
  723 +
  724 +- *Type*: rvalue
  725 +
  726 +strftime
  727 +--------
  728 +This function returns formatted time.
  729 +
  730 +*Examples:*
  731 +
  732 +To return the time since epoch:
  733 +
  734 + strftime("%s")
  735 +
  736 +To return the date:
  737 +
  738 + strftime("%Y-%m-%d")
  739 +
  740 +*Format meaning:*
  741 +
  742 + %a - The abbreviated weekday name (``Sun'')
  743 + %A - The full weekday name (``Sunday'')
  744 + %b - The abbreviated month name (``Jan'')
  745 + %B - The full month name (``January'')
  746 + %c - The preferred local date and time representation
  747 + %C - Century (20 in 2009)
  748 + %d - Day of the month (01..31)
  749 + %D - Date (%m/%d/%y)
  750 + %e - Day of the month, blank-padded ( 1..31)
  751 + %F - Equivalent to %Y-%m-%d (the ISO 8601 date format)
  752 + %h - Equivalent to %b
  753 + %H - Hour of the day, 24-hour clock (00..23)
  754 + %I - Hour of the day, 12-hour clock (01..12)
  755 + %j - Day of the year (001..366)
  756 + %k - hour, 24-hour clock, blank-padded ( 0..23)
  757 + %l - hour, 12-hour clock, blank-padded ( 0..12)
  758 + %L - Millisecond of the second (000..999)
  759 + %m - Month of the year (01..12)
  760 + %M - Minute of the hour (00..59)
  761 + %n - Newline (
  762 +)
  763 + %N - Fractional seconds digits, default is 9 digits (nanosecond)
  764 + %3N millisecond (3 digits)
  765 + %6N microsecond (6 digits)
  766 + %9N nanosecond (9 digits)
  767 + %p - Meridian indicator (``AM'' or ``PM'')
  768 + %P - Meridian indicator (``am'' or ``pm'')
  769 + %r - time, 12-hour (same as %I:%M:%S %p)
  770 + %R - time, 24-hour (%H:%M)
  771 + %s - Number of seconds since 1970-01-01 00:00:00 UTC.
  772 + %S - Second of the minute (00..60)
  773 + %t - Tab character ( )
  774 + %T - time, 24-hour (%H:%M:%S)
  775 + %u - Day of the week as a decimal, Monday being 1. (1..7)
  776 + %U - Week number of the current year,
  777 + starting with the first Sunday as the first
  778 + day of the first week (00..53)
  779 + %v - VMS date (%e-%b-%Y)
  780 + %V - Week number of year according to ISO 8601 (01..53)
  781 + %W - Week number of the current year,
  782 + starting with the first Monday as the first
  783 + day of the first week (00..53)
  784 + %w - Day of the week (Sunday is 0, 0..6)
  785 + %x - Preferred representation for the date alone, no time
  786 + %X - Preferred representation for the time alone, no date
  787 + %y - Year without a century (00..99)
  788 + %Y - Year with century
  789 + %z - Time zone as hour offset from UTC (e.g. +0900)
  790 + %Z - Time zone name
  791 + %% - Literal ``%'' character
  792 +
  793 +
  794 +- *Type*: rvalue
  795 +
  796 +strip
  797 +-----
  798 +This function removes leading and trailing whitespace from a string or from
  799 +every string inside an array.
  800 +
  801 +*Examples:*
  802 +
  803 + strip(" aaa ")
  804 +
  805 +Would result in: "aaa"
  806 +
  807 +
  808 +- *Type*: rvalue
  809 +
  810 +suffix
  811 +------
  812 +This function applies a suffix to all elements in an array.
  813 +
  814 +*Examples:*
  815 +
  816 + suffix(['a','b','c'], 'p')
  817 +
  818 +Will return: ['ap','bp','cp']
  819 +
  820 +
  821 +- *Type*: rvalue
  822 +
  823 +swapcase
  824 +--------
  825 +This function will swap the existing case of a string.
  826 +
  827 +*Examples:*
  828 +
  829 + swapcase("aBcD")
  830 +
  831 +Would result in: "AbCd"
  832 +
  833 +
  834 +- *Type*: rvalue
  835 +
  836 +time
  837 +----
  838 +This function will return the current time since epoch as an integer.
  839 +
  840 +*Examples:*
  841 +
  842 + time()
  843 +
  844 +Will return something like: 1311972653
  845 +
  846 +
  847 +- *Type*: rvalue
  848 +
  849 +to_bytes
  850 +--------
  851 +Converts the argument into bytes, for example 4 kB becomes 4096.
  852 +Takes a single string value as an argument.
  853 +
  854 +
  855 +- *Type*: rvalue
  856 +
  857 +type
  858 +----
  859 +Returns the type when passed a variable. Type can be one of:
  860 +
  861 +* string
  862 +* array
  863 +* hash
  864 +* float
  865 +* integer
  866 +* boolean
  867 +
  868 +
  869 +- *Type*: rvalue
  870 +
  871 +unique
  872 +------
  873 +This function will remove duplicates from strings and arrays.
  874 +
  875 +*Examples:*
  876 +
  877 + unique("aabbcc")
  878 +
  879 +Will return:
  880 +
  881 + abc
  882 +
  883 +You can also use this with arrays:
  884 +
  885 + unique(["a","a","b","b","c","c"])
  886 +
  887 +This returns:
  888 +
  889 + ["a","b","c"]
  890 +
  891 +
  892 +- *Type*: rvalue
  893 +
  894 +upcase
  895 +------
  896 +Converts a string or an array of strings to uppercase.
  897 +
  898 +*Examples:*
  899 +
  900 + upcase("abcd")
  901 +
  902 +Will return:
  903 +
  904 + ASDF
  905 +
  906 +
  907 +- *Type*: rvalue
  908 +
  909 +uriescape
  910 +---------
  911 +Urlencodes a string or array of strings.
  912 +Requires either a single string or an array as an input.
  913 +
  914 +
  915 +- *Type*: rvalue
  916 +
  917 +validate_absolute_path
  918 +----------------------
  919 +Validate the string represents an absolute path in the filesystem. This function works
  920 +for windows and unix style paths.
  921 +
  922 +The following values will pass:
  923 +
  924 + $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet"
  925 + validate_absolute_path($my_path)
  926 + $my_path2 = "/var/lib/puppet"
  927 + validate_absolute_path($my_path2)
  928 +
  929 +
  930 +The following values will fail, causing compilation to abort:
  931 +
  932 + validate_absolute_path(true)
  933 + validate_absolute_path([ 'var/lib/puppet', '/var/foo' ])
  934 + validate_absolute_path([ '/var/lib/puppet', 'var/foo' ])
  935 + $undefined = undef
  936 + validate_absolute_path($undefined)
  937 +
  938 +
  939 +
  940 +- *Type*: statement
  941 +
  942 +validate_array
  943 +--------------
  944 +Validate that all passed values are array data structures. Abort catalog
  945 +compilation if any value fails this check.
  946 +
  947 +The following values will pass:
  948 +
  949 + $my_array = [ 'one', 'two' ]
  950 + validate_array($my_array)
  951 +
  952 +The following values will fail, causing compilation to abort:
  953 +
  954 + validate_array(true)
  955 + validate_array('some_string')
  956 + $undefined = undef
  957 + validate_array($undefined)
  958 +
  959 +
  960 +
  961 +- *Type*: statement
  962 +
  963 +validate_augeas
  964 +---------------
  965 +Perform validation of a string using an Augeas lens
  966 +The first argument of this function should be a string to
  967 +test, and the second argument should be the name of the Augeas lens to use.
  968 +If Augeas fails to parse the string with the lens, the compilation will
  969 +abort with a parse error.
  970 +
  971 +A third argument can be specified, listing paths which should
  972 +not be found in the file. The `$file` variable points to the location
  973 +of the temporary file being tested in the Augeas tree.
  974 +
  975 +For example, if you want to make sure your passwd content never contains
  976 +a user `foo`, you could write:
  977 +
  978 + validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo'])
  979 +
  980 +Or if you wanted to ensure that no users used the '/bin/barsh' shell,
  981 +you could use:
  982 +
  983 + validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]']
  984 +
  985 +If a fourth argument is specified, this will be the error message raised and
  986 +seen by the user.
  987 +
  988 +A helpful error message can be returned like this:
  989 +
  990 + validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas')
  991 +
  992 +
  993 +
  994 +- *Type*: statement
  995 +
  996 +validate_bool
  997 +-------------
  998 +Validate that all passed values are either true or false. Abort catalog
  999 +compilation if any value fails this check.
  1000 +
  1001 +The following values will pass:
  1002 +
  1003 + $iamtrue = true
  1004 + validate_bool(true)
  1005 + validate_bool(true, true, false, $iamtrue)
  1006 +
  1007 +The following values will fail, causing compilation to abort:
  1008 +
  1009 + $some_array = [ true ]
  1010 + validate_bool("false")
  1011 + validate_bool("true")
  1012 + validate_bool($some_array)
  1013 +
  1014 +
  1015 +
  1016 +- *Type*: statement
  1017 +
  1018 +validate_cmd
  1019 +------------
  1020 +Perform validation of a string with an external command.
  1021 +The first argument of this function should be a string to
  1022 +test, and the second argument should be a path to a test command
  1023 +taking a file as last argument. If the command, launched against
  1024 +a tempfile containing the passed string, returns a non-null value,
  1025 +compilation will abort with a parse error.
  1026 +
  1027 +If a third argument is specified, this will be the error message raised and
  1028 +seen by the user.
  1029 +
  1030 +A helpful error message can be returned like this:
  1031 +
  1032 +Example:
  1033 +
  1034 + validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content')
  1035 +
  1036 +
  1037 +
  1038 +- *Type*: statement
  1039 +
  1040 +validate_hash
  1041 +-------------
  1042 +Validate that all passed values are hash data structures. Abort catalog
  1043 +compilation if any value fails this check.
  1044 +
  1045 +The following values will pass:
  1046 +
  1047 + $my_hash = { 'one' => 'two' }
  1048 + validate_hash($my_hash)
  1049 +
  1050 +The following values will fail, causing compilation to abort:
  1051 +
  1052 + validate_hash(true)
  1053 + validate_hash('some_string')
  1054 + $undefined = undef
  1055 + validate_hash($undefined)
  1056 +
  1057 +
  1058 +
  1059 +- *Type*: statement
  1060 +
  1061 +validate_re
  1062 +-----------
  1063 +Perform simple validation of a string against one or more regular
  1064 +expressions. The first argument of this function should be a string to
  1065 +test, and the second argument should be a stringified regular expression
  1066 +(without the // delimiters) or an array of regular expressions. If none
  1067 +of the regular expressions match the string passed in, compilation will
  1068 +abort with a parse error.
  1069 +
  1070 +If a third argument is specified, this will be the error message raised and
  1071 +seen by the user.
  1072 +
  1073 +The following strings will validate against the regular expressions:
  1074 +
  1075 + validate_re('one', '^one$')
  1076 + validate_re('one', [ '^one', '^two' ])
  1077 +
  1078 +The following strings will fail to validate, causing compilation to abort:
  1079 +
  1080 + validate_re('one', [ '^two', '^three' ])
  1081 +
  1082 +A helpful error message can be returned like this:
  1083 +
  1084 + validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7')
  1085 +
  1086 +
  1087 +
  1088 +- *Type*: statement
  1089 +
  1090 +validate_slength
  1091 +----------------
  1092 +Validate that the first argument is a string (or an array of strings), and
  1093 +less/equal to than the length of the second argument. It fails if the first
  1094 +argument is not a string or array of strings, and if arg 2 is not convertable
  1095 +to a number.
  1096 +
  1097 +The following values will pass:
  1098 +
  1099 + validate_slength("discombobulate",17)
  1100 + validate_slength(["discombobulate","moo"],17)
  1101 +
  1102 +The following valueis will not:
  1103 +
  1104 + validate_slength("discombobulate",1)
  1105 + validate_slength(["discombobulate","thermometer"],5)
  1106 +
  1107 +
  1108 +
  1109 +- *Type*: statement
  1110 +
  1111 +validate_string
  1112 +---------------
  1113 +Validate that all passed values are string data structures. Abort catalog
  1114 +compilation if any value fails this check.
  1115 +
  1116 +The following values will pass:
  1117 +
  1118 + $my_string = "one two"
  1119 + validate_string($my_string, 'three')
  1120 +
  1121 +The following values will fail, causing compilation to abort:
  1122 +
  1123 + validate_string(true)
  1124 + validate_string([ 'some', 'array' ])
  1125 + $undefined = undef
  1126 + validate_string($undefined)
  1127 +
  1128 +
  1129 +- *Type*: statement
  1130 +
  1131 +values
  1132 +------
  1133 +When given a hash this function will return the values of that hash.
  1134 +
  1135 +*Examples:*
  1136 +
  1137 + $hash = {
  1138 + 'a' => 1,
  1139 + 'b' => 2,
  1140 + 'c' => 3,
  1141 + }
  1142 + values($hash)
  1143 +
  1144 +This example would return:
  1145 +
  1146 + [1,2,3]
  1147 +
  1148 +
  1149 +- *Type*: rvalue
  1150 +
  1151 +values_at
  1152 +---------
  1153 +Finds value inside an array based on location.
  1154 +
  1155 +The first argument is the array you want to analyze, and the second element can
  1156 +be a combination of:
  1157 +
  1158 +* A single numeric index
  1159 +* A range in the form of 'start-stop' (eg. 4-9)
  1160 +* An array combining the above
  1161 +
  1162 +*Examples*:
  1163 +
  1164 + values_at(['a','b','c'], 2)
  1165 +
  1166 +Would return ['c'].
  1167 +
  1168 + values_at(['a','b','c'], ["0-1"])
  1169 +
  1170 +Would return ['a','b'].
  1171 +
  1172 + values_at(['a','b','c','d','e'], [0, "2-3"])
  1173 +
  1174 +Would return ['a','c','d'].
  1175 +
  1176 +
  1177 +- *Type*: rvalue
  1178 +
  1179 +zip
  1180 +---
  1181 +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.
  1182 +
  1183 +*Example:*
  1184 +
  1185 + zip(['1','2','3'],['4','5','6'])
  1186 +
  1187 +Would result in:
  1188 +
  1189 + ["1", "4"], ["2", "5"], ["3", "6"]
  1190 +
  1191 +
  1192 +- *Type*: rvalue
  1193 +
  1194 +*This page autogenerated on 2013-04-11 13:54:25 -0700*
... ...
puppet/modules/stdlib/README_DEVELOPER.markdown 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +Puppet Specific Facts
  2 +=====================
  3 +
  4 +Facter is meant to stand alone and apart from Puppet. However, Facter often
  5 +runs inside Puppet and all custom facts included in the stdlib module will
  6 +almost always be evaluated in the context of Puppet and Facter working
  7 +together.
  8 +
  9 +Still, we don't want to write custom facts that blow up in the users face if
  10 +Puppet is not loaded in memory. This is often the case if the user runs
  11 +`facter` without also supplying the `--puppet` flag.
  12 +
  13 +Ah! But Jeff, the custom fact won't be in the `$LOAD_PATH` unless the user
  14 +supplies `--facter`! You might say...
  15 +
  16 +Not (always) true I say! If the user happens to have a CWD of
  17 +`<modulepath>/stdlib/lib` then the facts will automatically be evaluated and
  18 +blow up.
  19 +
  20 +In any event, it's pretty easy to write a fact that has no value if Puppet is
  21 +not loaded. Simply do it like this:
  22 +
  23 + Facter.add(:node_vardir) do
  24 + setcode do
  25 + # This will be nil if Puppet is not available.
  26 + Facter::Util::PuppetSettings.with_puppet do
  27 + Puppet[:vardir]
  28 + end
  29 + end
  30 + end
  31 +
  32 +The `Facter::Util::PuppetSettings.with_puppet` method accepts a block and
  33 +yields to it only if the Puppet library is loaded. If the Puppet library is
  34 +not loaded, then the method silently returns `nil` which Facter interprets as
  35 +an undefined fact value. The net effect is that the fact won't be set.
... ...
puppet/modules/stdlib/README_SPECS.markdown 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +NOTE
  2 +====
  3 +
  4 +This project's specs depend on puppet core, and thus they require the
  5 +`puppetlabs_spec_helper` project. For more information please see the README
  6 +in that project, which can be found here: [puppetlabs spec
  7 +helper](https://github.com/puppetlabs/puppetlabs_spec_helper)
... ...
puppet/modules/stdlib/RELEASE_PROCESS.markdown 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +# Contributing to this module #
  2 +
  3 + * Work in a topic branch
  4 + * Submit a github pull request
  5 + * Address any comments / feeback
  6 + * Merge into master using --no-ff
  7 +
  8 +# Releasing this module #
  9 +
  10 + * This module adheres to http://semver.org/
  11 + * Look for API breaking changes using git diff vX.Y.Z..master
  12 + * If no API breaking changes, the minor version may be bumped.
  13 + * If there are API breaking changes, the major version must be bumped.
  14 + * If there are only small minor changes, the patch version may be bumped.
  15 + * Update the CHANGELOG
  16 + * Update the Modulefile
  17 + * Commit these changes with a message along the lines of "Update CHANGELOG and
  18 + Modulefile for release"
  19 + * Create an annotated tag with git tag -a vX.Y.Z -m 'version X.Y.Z' (NOTE the
  20 + leading v as per semver.org)
  21 + * Push the tag with git push origin --tags
  22 + * Build a new package with puppet-module or the rake build task if it exists
  23 + * Publish the new package to the forge
  24 + * Bonus points for an announcement to puppet-users.
... ...
puppet/modules/stdlib/Rakefile 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +require 'rubygems'
  2 +require 'puppetlabs_spec_helper/rake_tasks'
... ...
puppet/modules/stdlib/lib/facter/facter_dot_d.rb 0 → 100644
... ... @@ -0,0 +1,202 @@
  1 +# A Facter plugin that loads facts from /etc/facter/facts.d
  2 +# and /etc/puppetlabs/facter/facts.d.
  3 +#
  4 +# Facts can be in the form of JSON, YAML or Text files
  5 +# and any executable that returns key=value pairs.
  6 +#
  7 +# In the case of scripts you can also create a file that
  8 +# contains a cache TTL. For foo.sh store the ttl as just
  9 +# a number in foo.sh.ttl
  10 +#
  11 +# The cache is stored in /tmp/facts_cache.yaml as a mode
  12 +# 600 file and will have the end result of not calling your
  13 +# fact scripts more often than is needed
  14 +
  15 +class Facter::Util::DotD
  16 + require 'yaml'
  17 +
  18 + def initialize(dir="/etc/facts.d", cache_file="/tmp/facts_cache.yml")
  19 + @dir = dir
  20 + @cache_file = cache_file
  21 + @cache = nil
  22 + @types = {".txt" => :txt, ".json" => :json, ".yaml" => :yaml}
  23 + end
  24 +
  25 + def entries
  26 + Dir.entries(@dir).reject{|f| f =~ /^\.|\.ttl$/}.sort.map {|f| File.join(@dir, f) }
  27 + rescue
  28 + []
  29 + end
  30 +
  31 + def fact_type(file)
  32 + extension = File.extname(file)
  33 +
  34 + type = @types[extension] || :unknown
  35 +
  36 + type = :script if type == :unknown && File.executable?(file)
  37 +
  38 + return type
  39 + end
  40 +
  41 + def txt_parser(file)
  42 + File.readlines(file).each do |line|
  43 + if line =~ /^(.+)=(.+)$/
  44 + var = $1; val = $2
  45 +
  46 + Facter.add(var) do
  47 + setcode { val }
  48 + end
  49 + end
  50 + end
  51 + rescue Exception => e
  52 + Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
  53 + end
  54 +
  55 + def json_parser(file)
  56 + begin
  57 + require 'json'
  58 + rescue LoadError
  59 + retry if require 'rubygems'
  60 + raise
  61 + end
  62 +
  63 + JSON.load(File.read(file)).each_pair do |f, v|
  64 + Facter.add(f) do
  65 + setcode { v }
  66 + end
  67 + end
  68 + rescue Exception => e
  69 + Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}")
  70 + end
  71 +
  72 + def yaml_parser(file)
  73 + require 'yaml'
  74 +
  75 + YAML.load_file(file).each_pair do |f, v|
  76 + Facter.add(f) do
  77 + setcode { v }
  78 + end
  79 + end
  80 + rescue Exception => e
  81 + Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}")
  82 + end
  83 +
  84 + def script_parser(file)
  85 + result = cache_lookup(file)
  86 + ttl = cache_time(file)
  87 +
  88 + unless result
  89 + result = Facter::Util::Resolution.exec(file)
  90 +
  91 + if ttl > 0
  92 + Facter.debug("Updating cache for #{file}")
  93 + cache_store(file, result)
  94 + cache_save!
  95 + end
  96 + else
  97 + Facter.debug("Using cached data for #{file}")
  98 + end
  99 +
  100 + result.split("\n").each do |line|
  101 + if line =~ /^(.+)=(.+)$/
  102 + var = $1; val = $2
  103 +
  104 + Facter.add(var) do
  105 + setcode { val }
  106 + end
  107 + end
  108 + end
  109 + rescue Exception => e
  110 + Facter.warn("Failed to handle #{file} as script facts: #{e.class}: #{e}")
  111 + Facter.debug(e.backtrace.join("\n\t"))
  112 + end
  113 +
  114 + def cache_save!
  115 + cache = load_cache
  116 + File.open(@cache_file, "w", 0600) {|f| f.write(YAML.dump(cache)) }
  117 + rescue
  118 + end
  119 +
  120 + def cache_store(file, data)
  121 + load_cache
  122 +
  123 + @cache[file] = {:data => data, :stored => Time.now.to_i}
  124 + rescue
  125 + end
  126 +
  127 + def cache_lookup(file)
  128 + cache = load_cache
  129 +
  130 + return nil if cache.empty?
  131 +
  132 + ttl = cache_time(file)
  133 +
  134 + if cache[file]
  135 + now = Time.now.to_i
  136 +
  137 + return cache[file][:data] if ttl == -1
  138 + return cache[file][:data] if (now - cache[file][:stored]) <= ttl
  139 + return nil
  140 + else
  141 + return nil
  142 + end
  143 + rescue
  144 + return nil
  145 + end
  146 +
  147 + def cache_time(file)
  148 + meta = file + ".ttl"
  149 +
  150 + return File.read(meta).chomp.to_i
  151 + rescue
  152 + return 0
  153 + end
  154 +
  155 + def load_cache
  156 + unless @cache
  157 + if File.exist?(@cache_file)
  158 + @cache = YAML.load_file(@cache_file)
  159 + else
  160 + @cache = {}
  161 + end
  162 + end
  163 +
  164 + return @cache
  165 + rescue
  166 + @cache = {}
  167 + return @cache
  168 + end
  169 +
  170 + def create
  171 + entries.each do |fact|
  172 + type = fact_type(fact)
  173 + parser = "#{type}_parser"
  174 +
  175 + if respond_to?("#{type}_parser")
  176 + Facter.debug("Parsing #{fact} using #{parser}")
  177 +
  178 + send(parser, fact)
  179 + end
  180 + end
  181 + end
  182 +end
  183 +
  184 +
  185 +mdata = Facter.version.match(/(\d+)\.(\d+)\.(\d+)/)
  186 +if mdata
  187 + (major, minor, patch) = mdata.captures.map { |v| v.to_i }
  188 + if major < 2
  189 + # Facter 1.7 introduced external facts support directly
  190 + unless major == 1 and minor > 6
  191 + Facter::Util::DotD.new("/etc/facter/facts.d").create
  192 + Facter::Util::DotD.new("/etc/puppetlabs/facter/facts.d").create
  193 +
  194 + # Windows has a different configuration directory that defaults to a vendor
  195 + # specific sub directory of the %COMMON_APPDATA% directory.
  196 + if Dir.const_defined? 'COMMON_APPDATA' then
  197 + windows_facts_dot_d = File.join(Dir::COMMON_APPDATA, 'PuppetLabs', 'facter', 'facts.d')
  198 + Facter::Util::DotD.new(windows_facts_dot_d).create
  199 + end
  200 + end
  201 + end
  202 +end
... ...
puppet/modules/stdlib/lib/facter/pe_version.rb 0 → 100644
... ... @@ -0,0 +1,53 @@
  1 +# Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version
  2 +#
  3 +# Purpose: Return various facts about the PE state of the system
  4 +#
  5 +# Resolution: Uses a regex match against puppetversion to determine whether the
  6 +# machine has Puppet Enterprise installed, and what version (overall, major,
  7 +# minor, patch) is installed.
  8 +#
  9 +# Caveats:
  10 +#
  11 +Facter.add("pe_version") do
  12 + setcode do
  13 + pe_ver = Facter.value("puppetversion").match(/Puppet Enterprise (\d+\.\d+\.\d+)/)
  14 + pe_ver[1] if pe_ver
  15 + end
  16 +end
  17 +
  18 +Facter.add("is_pe") do
  19 + setcode do
  20 + if Facter.value(:pe_version).to_s.empty? then
  21 + false
  22 + else
  23 + true
  24 + end
  25 + end
  26 +end
  27 +
  28 +Facter.add("pe_major_version") do
  29 + confine :is_pe => true
  30 + setcode do
  31 + if pe_version = Facter.value(:pe_version)
  32 + pe_version.to_s.split('.')[0]
  33 + end
  34 + end
  35 +end
  36 +
  37 +Facter.add("pe_minor_version") do
  38 + confine :is_pe => true
  39 + setcode do
  40 + if pe_version = Facter.value(:pe_version)
  41 + pe_version.to_s.split('.')[1]
  42 + end
  43 + end
  44 +end
  45 +
  46 +Facter.add("pe_patch_version") do
  47 + confine :is_pe => true
  48 + setcode do
  49 + if pe_version = Facter.value(:pe_version)
  50 + pe_version.to_s.split('.')[2]
  51 + end
  52 + end
  53 +end
... ...
puppet/modules/stdlib/lib/facter/puppet_vardir.rb 0 → 100644
... ... @@ -0,0 +1,26 @@
  1 +# This facter fact returns the value of the Puppet vardir setting for the node
  2 +# running puppet or puppet agent. The intent is to enable Puppet modules to
  3 +# automatically have insight into a place where they can place variable data,
  4 +# regardless of the node's platform.
  5 +#
  6 +# The value should be directly usable in a File resource path attribute.
  7 +
  8 +
  9 +begin
  10 + require 'facter/util/puppet_settings'
  11 +rescue LoadError => e
  12 + # puppet apply does not add module lib directories to the $LOAD_PATH (See
  13 + # #4248). It should (in the future) but for the time being we need to be
  14 + # defensive which is what this rescue block is doing.
  15 + rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
  16 + load rb_file if File.exists?(rb_file) or raise e
  17 +end
  18 +
  19 +Facter.add(:puppet_vardir) do
  20 + setcode do
  21 + # This will be nil if Puppet is not available.
  22 + Facter::Util::PuppetSettings.with_puppet do
  23 + Puppet[:vardir]
  24 + end
  25 + end
  26 +end
... ...
puppet/modules/stdlib/lib/facter/root_home.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +# A facter fact to determine the root home directory.
  2 +# This varies on PE supported platforms and may be
  3 +# reconfigured by the end user.
  4 +
  5 +module Facter::Util::RootHome
  6 + class << self
  7 + def get_root_home
  8 + root_ent = Facter::Util::Resolution.exec("getent passwd root")
  9 + # The home directory is the sixth element in the passwd entry
  10 + # If the platform doesn't have getent, root_ent will be nil and we should
  11 + # return it straight away.
  12 + root_ent && root_ent.split(":")[5]
  13 + end
  14 + end
  15 +end
  16 +
  17 +Facter.add(:root_home) do
  18 + setcode { Facter::Util::RootHome.get_root_home }
  19 +end
... ...
puppet/modules/stdlib/lib/facter/util/puppet_settings.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +module Facter
  2 + module Util
  3 + module PuppetSettings
  4 + # This method is intended to provide a convenient way to evaluate a
  5 + # Facter code block only if Puppet is loaded. This is to account for the
  6 + # situation where the fact happens to be in the load path, but Puppet is
  7 + # not loaded for whatever reason. Perhaps the user is simply running
  8 + # facter without the --puppet flag and they happen to be working in a lib
  9 + # directory of a module.
  10 + def self.with_puppet
  11 + begin
  12 + Module.const_get("Puppet")
  13 + rescue NameError
  14 + nil
  15 + else
  16 + yield
  17 + end
  18 + end
  19 + end
  20 + end
  21 +end
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/abs.rb 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +#
  2 +# abs.rb
  3 +#
  4 +
  5 +module Puppet::Parser::Functions
  6 + newfunction(:abs, :type => :rvalue, :doc => <<-EOS
  7 + Returns the absolute value of a number, for example -34.56 becomes
  8 + 34.56. Takes a single integer and float value as an argument.
  9 + EOS
  10 + ) do |arguments|
  11 +
  12 + raise(Puppet::ParseError, "abs(): Wrong number of arguments " +
  13 + "given (#{arguments.size} for 1)") if arguments.size < 1
  14 +
  15 + value = arguments[0]
  16 +
  17 + # Numbers in Puppet are often string-encoded which is troublesome ...
  18 + if value.is_a?(String)
  19 + if value.match(/^-?(?:\d+)(?:\.\d+){1}$/)
  20 + value = value.to_f
  21 + elsif value.match(/^-?\d+$/)
  22 + value = value.to_i
  23 + else
  24 + raise(Puppet::ParseError, 'abs(): Requires float or ' +
  25 + 'integer to work with')
  26 + end
  27 + end
  28 +
  29 + # We have numeric value to handle ...
  30 + result = value.abs
  31 +
  32 + return result
  33 + end
  34 +end
  35 +
  36 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/any2array.rb 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +#
  2 +# any2array.rb
  3 +#
  4 +
  5 +module Puppet::Parser::Functions
  6 + newfunction(:any2array, :type => :rvalue, :doc => <<-EOS
  7 +This converts any object to an array containing that object. Empty argument
  8 +lists are converted to an empty array. Arrays are left untouched. Hashes are
  9 +converted to arrays of alternating keys and values.
  10 + EOS
  11 + ) do |arguments|
  12 +
  13 + if arguments.empty?
  14 + return []
  15 + end
  16 +
  17 + if arguments.length == 1
  18 + if arguments[0].kind_of?(Array)
  19 + return arguments[0]
  20 + elsif arguments[0].kind_of?(Hash)
  21 + result = []
  22 + arguments[0].each do |key, value|
  23 + result << key << value
  24 + end
  25 + return result
  26 + end
  27 + end
  28 +
  29 + return arguments
  30 + end
  31 +end
  32 +
  33 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/bool2num.rb 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +#
  2 +# bool2num.rb
  3 +#
  4 +
  5 +module Puppet::Parser::Functions
  6 + newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS
  7 + Converts a boolean to a number. Converts the values:
  8 + false, f, 0, n, and no to 0
  9 + true, t, 1, y, and yes to 1
  10 + Requires a single boolean or string as an input.
  11 + EOS
  12 + ) do |arguments|
  13 +
  14 + raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
  15 + "given (#{arguments.size} for 1)") if arguments.size < 1
  16 +
  17 + value = arguments[0]
  18 + klass = value.class
  19 +
  20 + # We can have either true or false, or string which resembles boolean ...
  21 + unless [FalseClass, TrueClass, String].include?(klass)
  22 + raise(Puppet::ParseError, 'bool2num(): Requires either ' +
  23 + 'boolean or string to work with')
  24 + end
  25 +
  26 + if value.is_a?(String)
  27 + # We consider all the yes, no, y, n and so on too ...
  28 + value = case value
  29 + #
  30 + # This is how undef looks like in Puppet ...
  31 + # We yield 0 (or false if you wish) in this case.
  32 + #
  33 + when /^$/, '' then false # Empty string will be false ...
  34 + when /^(1|t|y|true|yes)$/ then true
  35 + when /^(0|f|n|false|no)$/ then false
  36 + when /^(undef|undefined)$/ then false # This is not likely to happen ...
  37 + else
  38 + raise(Puppet::ParseError, 'bool2num(): Unknown type of boolean given')
  39 + end
  40 + end
  41 +
  42 + # We have real boolean values as well ...
  43 + result = value ? 1 : 0
  44 +
  45 + return result
  46 + end
  47 +end
  48 +
  49 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/capitalize.rb 0 → 100644
... ... @@ -0,0 +1,34 @@
  1 +#
  2 +# capitalize.rb
  3 +#
  4 +
  5 +module Puppet::Parser::Functions
  6 + newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS
  7 + Capitalizes the first letter of a string or array of strings.
  8 + Requires either a single string or an array as an input.
  9 + EOS
  10 + ) do |arguments|
  11 +
  12 + raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " +
  13 + "given (#{arguments.size} for 1)") if arguments.size < 1
  14 +
  15 + value = arguments[0]
  16 + klass = value.class
  17 +
  18 + unless [Array, String].include?(klass)
  19 + raise(Puppet::ParseError, 'capitalize(): Requires either ' +
  20 + 'array or string to work with')
  21 + end
  22 +
  23 + if value.is_a?(Array)
  24 + # Numbers in Puppet are often string-encoded which is troublesome ...
  25 + result = value.collect { |i| i.is_a?(String) ? i.capitalize : i }
  26 + else
  27 + result = value.capitalize
  28 + end
  29 +
  30 + return result
  31 + end
  32 +end
  33 +
  34 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/chomp.rb 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +#
  2 +# chomp.rb
  3 +#
  4 +
  5 +module Puppet::Parser::Functions
  6 + newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS'
  7 + Removes the record separator from the end of a string or an array of
  8 + strings, for example `hello\n` becomes `hello`.
  9 + Requires a single string or array as an input.
  10 + EOS
  11 + ) do |arguments|
  12 +
  13 + raise(Puppet::ParseError, "chomp(): Wrong number of arguments " +
  14 + "given (#{arguments.size} for 1)") if arguments.size < 1
  15 +
  16 + value = arguments[0]
  17 + klass = value.class
  18 +
  19 + unless [Array, String].include?(klass)
  20 + raise(Puppet::ParseError, 'chomp(): Requires either ' +
  21 + 'array or string to work with')
  22 + end
  23 +
  24 + if value.is_a?(Array)
  25 + # Numbers in Puppet are often string-encoded which is troublesome ...
  26 + result = value.collect { |i| i.is_a?(String) ? i.chomp : i }
  27 + else
  28 + result = value.chomp
  29 + end
  30 +
  31 + return result
  32 + end
  33 +end
  34 +
  35 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/chop.rb 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +#
  2 +# chop.rb
  3 +#
  4 +
  5 +module Puppet::Parser::Functions
  6 + newfunction(:chop, :type => :rvalue, :doc => <<-'EOS'
  7 + Returns a new string with the last character removed. If the string ends
  8 + with `\r\n`, both characters are removed. Applying chop to an empty
  9 + string returns an empty string. If you wish to merely remove record
  10 + separators then you should use the `chomp` function.
  11 + Requires a string or array of strings as input.
  12 + EOS
  13 + ) do |arguments|
  14 +
  15 + raise(Puppet::ParseError, "chop(): Wrong number of arguments " +
  16 + "given (#{arguments.size} for 1)") if arguments.size < 1
  17 +
  18 + value = arguments[0]
  19 + klass = value.class
  20 +
  21 + unless [Array, String].include?(klass)
  22 + raise(Puppet::ParseError, 'chop(): Requires either an ' +
  23 + 'array or string to work with')
  24 + end
  25 +
  26 + if value.is_a?(Array)
  27 + # Numbers in Puppet are often string-encoded which is troublesome ...
  28 + result = value.collect { |i| i.is_a?(String) ? i.chop : i }
  29 + else
  30 + result = value.chop
  31 + end
  32 +
  33 + return result
  34 + end
  35 +end
  36 +
  37 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/concat.rb 0 → 100644
... ... @@ -0,0 +1,37 @@
  1 +#
  2 +# concat.rb
  3 +#
  4 +
  5 +module Puppet::Parser::Functions
  6 + newfunction(:concat, :type => :rvalue, :doc => <<-EOS
  7 +Appends the contents of array 2 onto array 1.
  8 +
  9 +*Example:*
  10 +
  11 + concat(['1','2','3'],['4','5','6'])
  12 +
  13 +Would result in:
  14 +
  15 + ['1','2','3','4','5','6']
  16 + EOS
  17 + ) do |arguments|
  18 +
  19 + # Check that 2 arguments have been given ...
  20 + raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
  21 + "given (#{arguments.size} for 2)") if arguments.size != 2
  22 +
  23 + a = arguments[0]
  24 + b = arguments[1]
  25 +
  26 + # Check that both args are arrays.
  27 + unless a.is_a?(Array) and b.is_a?(Array)
  28 + raise(Puppet::ParseError, 'concat(): Requires array to work with')
  29 + end
  30 +
  31 + result = a.concat(b)
  32 +
  33 + return result
  34 + end
  35 +end
  36 +
  37 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/count.rb 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +module Puppet::Parser::Functions
  2 + newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-EOS
  3 +Takes an array as first argument and an optional second argument.
  4 +Count the number of elements in array that matches second argument.
  5 +If called with only an array it counts the number of elements that are not nil/undef.
  6 + EOS
  7 + ) do |args|
  8 +
  9 + if (args.size > 2) then
  10 + raise(ArgumentError, "count(): Wrong number of arguments "+
  11 + "given #{args.size} for 1 or 2.")
  12 + end
  13 +
  14 + collection, item = args
  15 +
  16 + if item then
  17 + collection.count item
  18 + else
  19 + collection.count { |obj| obj != nil && obj != :undef && obj != '' }
  20 + end
  21 + end
  22 +end
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +# Test whether a given class or definition is defined
  2 +require 'puppet/parser/functions'
  3 +
  4 +Puppet::Parser::Functions.newfunction(:defined_with_params,
  5 + :type => :rvalue,
  6 + :doc => <<-'ENDOFDOC'
  7 +Takes a resource reference and an optional hash of attributes.
  8 +
  9 +Returns true if a resource with the specified attributes has already been added
  10 +to the catalog, and false otherwise.
  11 +
  12 + user { 'dan':
  13 + ensure => present,
  14 + }
  15 +
  16 + if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
  17 + user { 'dan': ensure => present, }
  18 + }
  19 +ENDOFDOC
  20 +) do |vals|
  21 + reference, params = vals
  22 + raise(ArgumentError, 'Must specify a reference') unless reference
  23 + if (! params) || params == ''
  24 + params = {}
  25 + end
  26 + ret = false
  27 + if resource = findresource(reference.to_s)
  28 + matches = params.collect do |key, value|
  29 + resource[key] == value
  30 + end
  31 + ret = params.empty? || !matches.include?(false)
  32 + end
  33 + Puppet.debug("Resource #{reference} was not determined to be defined")
  34 + ret
  35 +end
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/delete.rb 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +#
  2 +# delete.rb
  3 +#
  4 +
  5 +# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
  6 +
  7 +module Puppet::Parser::Functions
  8 + newfunction(:delete, :type => :rvalue, :doc => <<-EOS
  9 +Deletes all instances of a given element from an array, substring from a
  10 +string, or key from a hash.
  11 +
  12 +*Examples:*
  13 +
  14 + delete(['a','b','c','b'], 'b')
  15 + Would return: ['a','c']
  16 +
  17 + delete({'a'=>1,'b'=>2,'c'=>3}, 'b')
  18 + Would return: {'a'=>1,'c'=>3}
  19 +
  20 + delete('abracadabra', 'bra')
  21 + Would return: 'acada'
  22 + EOS
  23 + ) do |arguments|
  24 +
  25 + if (arguments.size != 2) then
  26 + raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
  27 + "given #{arguments.size} for 2.")
  28 + end
  29 +
  30 + collection = arguments[0]
  31 + item = arguments[1]
  32 +
  33 + case collection
  34 + when Array, Hash
  35 + collection.delete item
  36 + when String
  37 + collection.gsub! item, ''
  38 + else
  39 + raise(TypeError, "delete(): First argument must be an Array, " +
  40 + "String, or Hash. Given an argument of class #{collection.class}.")
  41 + end
  42 + collection
  43 + end
  44 +end
  45 +
  46 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/delete_at.rb 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +#
  2 +# delete_at.rb
  3 +#
  4 +
  5 +module Puppet::Parser::Functions
  6 + newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
  7 +Deletes a determined indexed value from an array.
  8 +
  9 +*Examples:*
  10 +
  11 + delete_at(['a','b','c'], 1)
  12 +
  13 +Would return: ['a','c']
  14 + EOS
  15 + ) do |arguments|
  16 +
  17 + raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " +
  18 + "given (#{arguments.size} for 2)") if arguments.size < 2
  19 +
  20 + array = arguments[0]
  21 +
  22 + unless array.is_a?(Array)
  23 + raise(Puppet::ParseError, 'delete_at(): Requires array to work with')
  24 + end
  25 +
  26 + index = arguments[1]
  27 +
  28 + if index.is_a?(String) and not index.match(/^\d+$/)
  29 + raise(Puppet::ParseError, 'delete_at(): You must provide ' +
  30 + 'non-negative numeric index')
  31 + end
  32 +
  33 + result = array.clone
  34 +
  35 + # Numbers in Puppet are often string-encoded which is troublesome ...
  36 + index = index.to_i
  37 +
  38 + if index > result.size - 1 # First element is at index 0 is it not?
  39 + raise(Puppet::ParseError, 'delete_at(): Given index ' +
  40 + 'exceeds size of array given')
  41 + end
  42 +
  43 + result.delete_at(index) # We ignore the element that got deleted ...
  44 +
  45 + return result
  46 + end
  47 +end
  48 +
  49 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/dirname.rb 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +module Puppet::Parser::Functions
  2 + newfunction(:dirname, :type => :rvalue, :doc => <<-EOS
  3 + Returns the dirname of a path.
  4 + EOS
  5 + ) do |arguments|
  6 +
  7 + raise(Puppet::ParseError, "dirname(): Wrong number of arguments " +
  8 + "given (#{arguments.size} for 1)") if arguments.size < 1
  9 +
  10 + path = arguments[0]
  11 + return File.dirname(path)
  12 + end
  13 +end
  14 +
  15 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/downcase.rb 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +#
  2 +# downcase.rb
  3 +#
  4 +
  5 +module Puppet::Parser::Functions
  6 + newfunction(:downcase, :type => :rvalue, :doc => <<-EOS
  7 +Converts the case of a string or all strings in an array to lower case.
  8 + EOS
  9 + ) do |arguments|
  10 +
  11 + raise(Puppet::ParseError, "downcase(): Wrong number of arguments " +
  12 + "given (#{arguments.size} for 1)") if arguments.size < 1
  13 +
  14 + value = arguments[0]
  15 + klass = value.class
  16 +
  17 + unless [Array, String].include?(klass)
  18 + raise(Puppet::ParseError, 'downcase(): Requires either ' +
  19 + 'array or string to work with')
  20 + end
  21 +
  22 + if value.is_a?(Array)
  23 + # Numbers in Puppet are often string-encoded which is troublesome ...
  24 + result = value.collect { |i| i.is_a?(String) ? i.downcase : i }
  25 + else
  26 + result = value.downcase
  27 + end
  28 +
  29 + return result
  30 + end
  31 +end
  32 +
  33 +# vim: set ts=2 sw=2 et :
... ...
puppet/modules/stdlib/lib/puppet/parser/functions/empty.rb 0 → 100644
... ... @@ -0,0 +1,28 @@
  1 +#
  2 +# empty.rb
  3 +#
  4 +
  5 +module Puppet::Parser::Functions
  6 + newfunction(:empty, :type => :rvalue, :doc => <<-EOS
  7 +Returns true if the variable is empty.
  8 + EOS
  9 + ) do |arguments|
  10 +
  11 + raise(Puppet::ParseError, "empty(): Wrong number of arguments " +
  12 + "given (#{arguments.size} for 1)") if arguments.size < 1
  13 +
  14 + value = arguments[0]
  15 + klass = value.class
  16 +
  17 + unless [Array, Hash, String].include?(klass)
  18 + raise(Puppet::ParseError, 'empty(): Requires either ' +
  19 + 'array, hash or string to work with')
  20 + end
  21 +
  22 + result = value.empty?
  23 +
  24 + return result
  25 + end
  26 +end
  27 +
  28 +# vim: set ts=2 sw=2 et :
... ...