adding modules
This commit is contained in:
parent
2bcd6dffd0
commit
558fe1428f
18
deployment_scripts/puppet/modules/http_download/.project
Normal file
18
deployment_scripts/puppet/modules/http_download/.project
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>http_download</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.puppetlabs.geppetto.pp.dsl.ui.puppetNature</nature>
|
||||
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
62
deployment_scripts/puppet/modules/http_download/README.md
Normal file
62
deployment_scripts/puppet/modules/http_download/README.md
Normal file
@ -0,0 +1,62 @@
|
||||
# http_download
|
||||
|
||||
## Overview
|
||||
|
||||
This module contains a puppet type that allows http downloads directly via ruby. No additional executables are needed.
|
||||
It supports SSL and Basic authentication.
|
||||
|
||||
## Class: http_download
|
||||
|
||||
The class of that module just acts as test and example showing how to use the type.
|
||||
|
||||
### Sample Usage
|
||||
|
||||
```puppet
|
||||
download {'test file 1':
|
||||
uri => 'http://downloads.sourceforge.net/project/sevenzip/7-Zip/9.22/7z922.exe',
|
||||
dest => '/tmp/7z922.exe'
|
||||
}
|
||||
|
||||
download { 'my ssl and basic auth download':
|
||||
uri => 'https://www.example.com/download/example.txt',
|
||||
dest => '/tmp/example.txt',
|
||||
user => 'user',
|
||||
pass => 'pass'
|
||||
}
|
||||
|
||||
download {'download if not exists':
|
||||
uri => 'http://downloads.sourceforge.net/project/sevenzip/7-Zip/9.22/7z922.exe',
|
||||
force => false,
|
||||
dest => '/tmp/7z922.exe'
|
||||
}
|
||||
|
||||
download { 'download with basic auth and ssl, ssl forced':
|
||||
uri => 'http://host.com:8443/test.txt',
|
||||
use_ssl => true,
|
||||
dest => '/tmp/example.txt',
|
||||
user => 'user',
|
||||
pass => 'pass'
|
||||
}
|
||||
|
||||
download { 'download with proxy settings without auth':
|
||||
uri => 'http://host.com:8443/test.txt',
|
||||
dest => '/tmp/example.txt',
|
||||
proxy_host => '127.0.0.1',
|
||||
proxy_port => '3128'
|
||||
}
|
||||
|
||||
download { 'download with proxy setting with auth':
|
||||
uri => 'http://host.com:8443/test.txt',
|
||||
dest => '/tmp/example.txt',
|
||||
proxy_host => '127.0.0.1',
|
||||
proxy_port => '3128',
|
||||
proxy_user => 'my-proxy-user',
|
||||
proxy_pass => 'my-proxy-pass'
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Supported OSes
|
||||
|
||||
As it's written in plain ruby all OS that can run Puppet should be able to use it.
|
||||
I have tested it on different Windows versions and various Linux distributions (CentOS, Ubuntu, AmazonLinux) without issues.
|
2
deployment_scripts/puppet/modules/http_download/Rakefile
Normal file
2
deployment_scripts/puppet/modules/http_download/Rakefile
Normal file
@ -0,0 +1,2 @@
|
||||
require 'rubygems'
|
||||
require 'puppetlabs_spec_helper/rake_tasks'
|
@ -0,0 +1,103 @@
|
||||
# This type allows dowloads of files via plain ruby
|
||||
#
|
||||
require 'puppet'
|
||||
require 'net/http'
|
||||
require 'uri'
|
||||
|
||||
Puppet::Type.type(:download).provide(:ruby) do
|
||||
def fetch(uri_str, limit = 10)
|
||||
raise ArgumentError, 'Too many HTTP redirects' if limit == 0
|
||||
uri = URI(uri_str)
|
||||
|
||||
|
||||
if resource[:proxy_host] and resource[:proxy_port]
|
||||
if resource[:proxy_user] and resource[:proxy_pass]
|
||||
http = Net::HTTP.new(uri.host, uri.port, resource[:proxy_host], resource[:proxy_port], resource[:proxy_user], resource[:proxy_pass])
|
||||
else
|
||||
http = Net::HTTP.new(uri.host, uri.port, resource[:proxy_host], resource[:proxy_port])
|
||||
end
|
||||
else
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
end
|
||||
|
||||
begin
|
||||
if resource[:use_ssl] or uri_str.start_with? 'https'
|
||||
http.use_ssl = true
|
||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
end
|
||||
request = Net::HTTP::Get.new uri.request_uri
|
||||
if nil != resource[:user] and nil != resource[:pass]
|
||||
request.basic_auth(resource[:user], resource[:pass])
|
||||
end
|
||||
http.request request do |response|
|
||||
case response
|
||||
when Net::HTTPRedirection then
|
||||
location = response['location']
|
||||
Puppet.notice("redirected to #{location}")
|
||||
fetch(location, limit - 1)
|
||||
when Net::HTTPForbidden then
|
||||
raise SecurityError, 'Access denied'
|
||||
when Net::HTTPNotFound then
|
||||
raise ArgumentError, 'Not found'
|
||||
when Net::HTTPSuccess then
|
||||
open resource[:dest], 'wb' do |io|
|
||||
response.read_body do |chunk|
|
||||
io.write chunk
|
||||
end
|
||||
end
|
||||
else
|
||||
raise "Unexpected state => #{response.code} - #{response.message}"
|
||||
end
|
||||
end
|
||||
rescue Net::HTTPError => e
|
||||
if nil != http and http.started?
|
||||
http.finish()
|
||||
end
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
def download
|
||||
success = false
|
||||
for retries in 1..3
|
||||
begin
|
||||
fetch(resource[:uri])
|
||||
success = true
|
||||
break
|
||||
rescue SecurityError => s
|
||||
Puppet.crit("SecurityError -> \n#{s.inspect}")
|
||||
break
|
||||
rescue ArgumentError => a
|
||||
Puppet.crit("ArgumentError -> \n#{a.inspect}")
|
||||
break
|
||||
rescue IOError => eio
|
||||
Puppet.crit("IO Exception during http download -> \n#{eio.inspect}")
|
||||
rescue Net::HTTPError => ehttp
|
||||
Puppet.crit("HTTP Exception during http download -> \n#{ehttp.inspect}")
|
||||
rescue StandardError => e
|
||||
Puppet.crit("Exception during http download -> \n#{e.inspect}")
|
||||
end
|
||||
sleep(5)
|
||||
end
|
||||
return success
|
||||
end
|
||||
|
||||
def exists?
|
||||
(File.file?(resource[:dest]) and !resource[:force])
|
||||
end
|
||||
|
||||
def destroy
|
||||
if File.file?(resource[:dest])
|
||||
File.delete(resource[:dest])
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def create
|
||||
succ = download()
|
||||
if !succ
|
||||
Puppet.crit("HTTP download of '#{resource[:uri]}' failed!")
|
||||
end
|
||||
succ
|
||||
end
|
||||
end
|
@ -0,0 +1,107 @@
|
||||
# This type holds the code to upload the user attributes
|
||||
#
|
||||
#
|
||||
require 'puppet'
|
||||
require 'puppet/parameter/boolean'
|
||||
|
||||
Puppet::Type.newtype(:download) do
|
||||
desc <<-EOS
|
||||
This type allows to do downloads via ruby without the need for any localy provided executable.
|
||||
|
||||
Example usage:
|
||||
|
||||
Download a file:
|
||||
|
||||
download { 'my download':
|
||||
uri => 'http://www.example.com/download/example.txt',
|
||||
dest => '/tmp/example.txt'
|
||||
}
|
||||
|
||||
Download file only if no local file exists:
|
||||
|
||||
download { 'my download':
|
||||
uri => 'http://www.example.com/download/example.txt',
|
||||
dest => '/tmp/example.txt',
|
||||
force => false
|
||||
}
|
||||
|
||||
Download file using basic authentication:
|
||||
|
||||
download { 'my ssl and basic auth download':
|
||||
uri => 'https://www.example.com/download/example.txt',
|
||||
dest => '/tmp/example.txt',
|
||||
user => 'user',
|
||||
pass => 'pass'
|
||||
}
|
||||
|
||||
Download file using proxy settings:
|
||||
|
||||
download { 'my download behind a proxy':
|
||||
uri => 'https://www.example.com/download/example.txt',
|
||||
dest => '/tmp/example.txt',
|
||||
proxy_host => '127.0.0.1',
|
||||
proxy_port => '3128',
|
||||
proxy_user => 'user', # optionnal: only if proxy need authentication
|
||||
proxy_pass => 'pass' # optionnal: only if proxy need authentication
|
||||
}
|
||||
EOS
|
||||
|
||||
ensurable do
|
||||
defaultvalues
|
||||
defaultto :present
|
||||
end
|
||||
|
||||
newparam(:name, :namevar => true) do
|
||||
desc "The name for the download."
|
||||
end
|
||||
|
||||
newparam(:uri) do
|
||||
desc "The uri of the file to download."
|
||||
end
|
||||
|
||||
newparam(:dest) do
|
||||
desc "The destination file. Make sure the path to this file exists!"
|
||||
end
|
||||
|
||||
newparam(:force, :boolean => true, :parent => Puppet::Parameter::Boolean) do
|
||||
desc <<-EOS
|
||||
Per default a file download will be forced as there is no good way to check if the local file
|
||||
matches the download. If you only want to ensure that a file with that name exists locally you
|
||||
can set this to false.
|
||||
EOS
|
||||
defaultto :true
|
||||
newvalues(:true, :false)
|
||||
end
|
||||
|
||||
newparam(:use_ssl, :boolean => true, :parent => Puppet::Parameter::Boolean) do
|
||||
desc "Use SSL for the transfer? If the URL starts with https this is set automatically."
|
||||
defaultto :false
|
||||
newvalues(:true, :false)
|
||||
end
|
||||
|
||||
newparam(:user) do
|
||||
desc "A user to use for basic authentication."
|
||||
end
|
||||
|
||||
newparam(:pass) do
|
||||
desc "A pass to use for basic authentication."
|
||||
end
|
||||
|
||||
newparam(:proxy_host) do
|
||||
desc "The proxy hostname. Make sure the host exists!"
|
||||
end
|
||||
|
||||
newparam(:proxy_port) do
|
||||
desc "The proxy port. Make sure the port is open!"
|
||||
end
|
||||
|
||||
|
||||
newparam(:proxy_user) do
|
||||
desc "The proxy username. This is an optional parameter"
|
||||
end
|
||||
|
||||
newparam(:proxy_pass) do
|
||||
desc "The proxy password. This is an optional parameter"
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,33 @@
|
||||
# Class: http_download
|
||||
#
|
||||
class http_download {
|
||||
# this is just a test for the module
|
||||
if $::kernel == 'linux' {
|
||||
$target = '/tmp/'
|
||||
} else {
|
||||
$target = 'C:/'
|
||||
}
|
||||
|
||||
download { 'test file basic':
|
||||
uri => 'http://www.7-zip.org/a/7z920-x64.msi',
|
||||
dest => "${target}7z920-x64.msi",
|
||||
}
|
||||
|
||||
download { 'test https and large file':
|
||||
uri => 'https://downloads.mariadb.org/f/mariadb-10.1.10/source/mariadb-10.1.10.tar.gz?serve',
|
||||
dest => "${target}mariadb-10.1.10.tar.gz",
|
||||
}
|
||||
|
||||
download { 'test force false':
|
||||
uri => 'https://downloads.mariadb.org/f/mariadb-10.1.10/source/mariadb-10.1.10.tar.gz?serve',
|
||||
dest => "${target}mariadb-10.1.10.tar.gz",
|
||||
force => false
|
||||
}
|
||||
|
||||
download { 'test basic auth':
|
||||
uri => 'http://brunmayr.org/test/README.md',
|
||||
dest => "${target}README.md",
|
||||
user => 'test',
|
||||
pass => 'Basic_Auth1'
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
{
|
||||
"author": "Sledge Sulaweyo",
|
||||
"dependencies": [],
|
||||
"license": "Apache-2.0",
|
||||
"name": "sledge-http_download",
|
||||
"operatingsystem_support": [{
|
||||
"operatingsystem": "Windows"
|
||||
},{
|
||||
"operatingsystem": "RedHat"
|
||||
},{
|
||||
"operatingsystem": "Ubuntu"
|
||||
},{
|
||||
"operatingsystem": "Debian"
|
||||
},{
|
||||
"operatingsystem": "CentOS"
|
||||
}
|
||||
],
|
||||
"project_page": "https://github.com/sulaweyo/http_download",
|
||||
"requirements": [],
|
||||
"source": "https://github.com/sulaweyo/http_download",
|
||||
"summary": "Contains a type that allows simple http downloads via ruby.",
|
||||
"tags": [],
|
||||
"version": "0.1.7"
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
--format
|
||||
s
|
||||
--colour
|
||||
--loadby
|
||||
mtime
|
||||
--backtrace
|
@ -0,0 +1,2 @@
|
||||
require 'rubygems'
|
||||
require 'puppetlabs_spec_helper/module_spec_helper'
|
@ -0,0 +1 @@
|
||||
include http_download
|
@ -0,0 +1,3 @@
|
||||
fixtures:
|
||||
symlinks:
|
||||
stdlib: "#{source_dir}"
|
40
deployment_scripts/puppet/modules/puppetlabs-stdlib/.gemspec
Normal file
40
deployment_scripts/puppet/modules/puppetlabs-stdlib/.gemspec
Normal file
@ -0,0 +1,40 @@
|
||||
#
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "puppetmodule-stdlib"
|
||||
|
||||
s.version = "4.0.2"
|
||||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["Puppet Labs"]
|
||||
s.date = "2013-04-12"
|
||||
s.description = [ 'This Gem format of the stdlib module is intended to make',
|
||||
'it easier for _module authors_ to resolve dependencies',
|
||||
'using a Gemfile when running automated testing jobs like',
|
||||
'Travis or Jenkins. The recommended best practice for',
|
||||
'installation by end users is to use the `puppet module',
|
||||
'install` command to install stdlib from the [Puppet',
|
||||
'Forge](http://forge.puppetlabs.com/puppetlabs/stdlib).' ].join(' ')
|
||||
s.email = "puppet-dev@puppetlabs.com"
|
||||
s.executables = []
|
||||
s.files = [ 'CHANGELOG', 'CONTRIBUTING.md', 'Gemfile', 'LICENSE', 'Modulefile',
|
||||
'README.markdown', 'README_DEVELOPER.markdown', 'RELEASE_PROCESS.markdown',
|
||||
'Rakefile', 'spec/spec.opts' ]
|
||||
s.files += Dir['lib/**/*.rb'] + Dir['manifests/**/*.pp'] + Dir['tests/**/*.pp'] + Dir['spec/**/*.rb']
|
||||
s.homepage = "http://forge.puppetlabs.com/puppetlabs/stdlib"
|
||||
s.rdoc_options = ["--title", "Puppet Standard Library Development Gem", "--main", "README.markdown", "--line-numbers"]
|
||||
s.require_paths = ["lib"]
|
||||
s.rubyforge_project = "puppetmodule-stdlib"
|
||||
s.rubygems_version = "1.8.24"
|
||||
s.summary = "This gem provides a way to make the standard library available for other module spec testing tasks."
|
||||
|
||||
if s.respond_to? :specification_version then
|
||||
s.specification_version = 3
|
||||
|
||||
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
||||
else
|
||||
end
|
||||
else
|
||||
end
|
||||
end
|
14
deployment_scripts/puppet/modules/puppetlabs-stdlib/.gitignore
vendored
Normal file
14
deployment_scripts/puppet/modules/puppetlabs-stdlib/.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
#This file is generated by ModuleSync, do not edit.
|
||||
pkg/
|
||||
Gemfile.lock
|
||||
vendor/
|
||||
spec/fixtures/
|
||||
.vagrant/
|
||||
.bundle/
|
||||
coverage/
|
||||
log/
|
||||
.idea/
|
||||
*.iml
|
||||
!spec/fixtures/
|
||||
spec/fixtures/manifests/site.pp
|
||||
spec/fixtures/modules/*
|
23
deployment_scripts/puppet/modules/puppetlabs-stdlib/.project
Normal file
23
deployment_scripts/puppet/modules/puppetlabs-stdlib/.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>stdlib</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.cloudsmith.geppetto.pp.dsl.ui.modulefileBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.cloudsmith.geppetto.pp.dsl.ui.puppetNature</nature>
|
||||
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,2 @@
|
||||
--color
|
||||
--format documentation
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
.gitignore:
|
||||
paths:
|
||||
- '!spec/fixtures/'
|
||||
- 'spec/fixtures/manifests/site.pp'
|
||||
- 'spec/fixtures/modules/*'
|
||||
|
@ -0,0 +1,35 @@
|
||||
#This file is generated by ModuleSync, do not edit.
|
||||
---
|
||||
sudo: false
|
||||
language: ruby
|
||||
cache: bundler
|
||||
script: "bundle exec rake validate lint spec"
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- rvm: 2.1.6
|
||||
dist: trusty
|
||||
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_set=docker/ubuntu-14.04
|
||||
script: bundle exec rake beaker
|
||||
services: docker
|
||||
sudo: required
|
||||
- rvm: 2.1.6
|
||||
dist: trusty
|
||||
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_set=docker/centos-7
|
||||
script: bundle exec rake beaker
|
||||
services: docker
|
||||
sudo: required
|
||||
- rvm: 2.1.6
|
||||
bundler_args: --without system_tests
|
||||
env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes"
|
||||
- rvm: 2.1.5
|
||||
bundler_args: --without system_tests
|
||||
env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes"
|
||||
- rvm: 2.1.5
|
||||
bundler_args: --without system_tests
|
||||
env: PUPPET_GEM_VERSION="~> 3.0"
|
||||
- rvm: 1.9.3
|
||||
bundler_args: --without system_tests
|
||||
env: PUPPET_GEM_VERSION="~> 3.0"
|
||||
notifications:
|
||||
email: false
|
655
deployment_scripts/puppet/modules/puppetlabs-stdlib/CHANGELOG.md
Normal file
655
deployment_scripts/puppet/modules/puppetlabs-stdlib/CHANGELOG.md
Normal file
@ -0,0 +1,655 @@
|
||||
## Supported Release 4.12.0
|
||||
###Summary
|
||||
|
||||
This release provides several new functions, bugfixes, modulesync changes, and some documentation updates.
|
||||
|
||||
####Features
|
||||
- Adds `clamp`. This function keeps values within a specified range.
|
||||
- Adds `validate_x509_rsa_key_pair`. This function validates an x509 RSA certificate and key pair.
|
||||
- Adds `dig`. This function performs a deep lookup in nested hashes or arrays.
|
||||
- Extends the `base64` support to fit `rfc2045` and `rfc4648`.
|
||||
- Adds `is_ipv6_address` and `is_ipv4_address`. These functions validate the specified ipv4 or ipv6 addresses.
|
||||
- Adds `enclose_ipv6`. This function encloses IPv6 addresses in square brackets.
|
||||
- Adds `ensure_resources`. This function takes a list of resources and creates them if they do not exist.
|
||||
- Extends `suffix` to support applying a suffix to keys in a hash.
|
||||
- Apply modulesync changes.
|
||||
- Add validate_email_address function.
|
||||
|
||||
####Bugfixes
|
||||
- Fixes `fqdn_rand_string` tests, since Puppet 4.4.0 and later have a higher `fqdn_rand` ceiling.
|
||||
- (MODULES-3152) Adds a check to `package_provider` to prevent failures if Gem is not installed.
|
||||
- Fixes to README.md.
|
||||
- Fixes catch StandardError rather than the gratuitous Exception
|
||||
- Fixes file_line attribute validation.
|
||||
- Fixes concat with Hash arguments.
|
||||
|
||||
## Supported Release 4.11.0
|
||||
###Summary
|
||||
|
||||
Provides a validate_absolute_paths and Debian 8 support. There is a fix to the is_package_provider fact and a test improvement.
|
||||
|
||||
####Features
|
||||
- Adds new parser called is_absolute_path
|
||||
- Supports Debian 8
|
||||
|
||||
####Bugfixes
|
||||
- Allow package_provider fact to resolve on PE 3.x
|
||||
|
||||
####Improvements
|
||||
- ensures that the test passes independently of changes to rubygems for ensure_resource
|
||||
|
||||
##2015-12-15 - Supported Release 4.10.0
|
||||
###Summary
|
||||
|
||||
Includes the addition of several new functions and considerable improvements to the existing functions, tests and documentation. Includes some bug fixes which includes compatibility, test and fact issues.
|
||||
|
||||
####Features
|
||||
- Adds service_provider fact
|
||||
- Adds is_a() function
|
||||
- Adds package_provider fact
|
||||
- Adds validate_ip_address function
|
||||
- Adds seeded_rand function
|
||||
|
||||
####Bugfixes
|
||||
- Fix backwards compatibility from an improvement to the parseyaml function
|
||||
- Renaming of load_module_metadata test to include _spec.rb
|
||||
- Fix root_home fact on AIX 5.x, now '-c' rather than '-C'
|
||||
- Fixed Gemfile to work with ruby 1.8.7
|
||||
|
||||
####Improvements
|
||||
- (MODULES-2462) Improvement of parseyaml function
|
||||
- Improvement of str2bool function
|
||||
- Improvement to readme
|
||||
- Improvement of intersection function
|
||||
- Improvement of validate_re function
|
||||
- Improved speed on Facter resolution of service_provider
|
||||
- empty function now handles numeric values
|
||||
- Package_provider now prevents deprecation warning about the allow_virtual parameter
|
||||
- load_module_metadata now succeeds on empty file
|
||||
- Check added to ensure puppetversion value is not nil
|
||||
- Improvement to bool2str to return a string of choice using boolean
|
||||
- Improvement to naming convention in validate_ipv4_address function
|
||||
|
||||
## Supported Release 4.9.1
|
||||
###Summary
|
||||
|
||||
Small release for support of newer PE versions. This increments the version of PE in the metadata.json file.
|
||||
|
||||
##2015-09-08 - Supported Release 4.9.0
|
||||
###Summary
|
||||
|
||||
This release adds new features including the new functions dos2unix, unix2dos, try_get_value, convert_base as well as other features and improvements.
|
||||
|
||||
####Features
|
||||
- (MODULES-2370) allow `match` parameter to influence `ensure => absent` behavior
|
||||
- (MODULES-2410) Add new functions dos2unix and unix2dos
|
||||
- (MODULE-2456) Modify union to accept more than two arrays
|
||||
- Adds a convert_base function, which can convert numbers between bases
|
||||
- Add a new function "try_get_value"
|
||||
|
||||
####Bugfixes
|
||||
- n/a
|
||||
|
||||
####Improvements
|
||||
- (MODULES-2478) Support root_home fact on AIX through "lsuser" command
|
||||
- Acceptance test improvements
|
||||
- Unit test improvements
|
||||
- Readme improvements
|
||||
|
||||
## 2015-08-10 - Supported Release 4.8.0
|
||||
### Summary
|
||||
This release adds a function for reading metadata.json from any module, and expands file\_line's abilities.
|
||||
|
||||
#### Features
|
||||
- New parameter `replace` on `file_line`
|
||||
- New function `load_module_metadata()` to load metadata.json and return the content as a hash.
|
||||
- Added hash support to `size()`
|
||||
|
||||
#### Bugfixes
|
||||
- Fix various docs typos
|
||||
- Fix `file_line` resource on puppet < 3.3
|
||||
|
||||
##2015-06-22 - Supported Release 4.7.0
|
||||
###Summary
|
||||
|
||||
Adds Solaris 12 support along with improved Puppet 4 support. There are significant test improvements, and some minor fixes.
|
||||
|
||||
####Features
|
||||
- Add support for Solaris 12
|
||||
|
||||
####Bugfixes
|
||||
- Fix for AIO Puppet 4
|
||||
- Fix time for ruby 1.8.7
|
||||
- Specify rspec-puppet version
|
||||
- range() fix for typeerror and missing functionality
|
||||
- Fix pw_hash() on JRuby < 1.7.17
|
||||
- fqdn_rand_string: fix argument error message
|
||||
- catch and rescue from looking up non-existent facts
|
||||
- Use puppet_install_helper, for Puppet 4
|
||||
|
||||
####Improvements
|
||||
- Enforce support for Puppet 4 testing
|
||||
- fqdn_rotate/fqdn_rand_string acceptance tests and implementation
|
||||
- Simplify mac address regex
|
||||
- validate_integer, validate_numeric: explicitely reject hashes in arrays
|
||||
- Readme edits
|
||||
- Remove all the pops stuff for rspec-puppet
|
||||
- Sync via modulesync
|
||||
- Add validate_slength optional 3rd arg
|
||||
- Move tests directory to examples directory
|
||||
|
||||
##2015-04-14 - Supported Release 4.6.0
|
||||
###Summary
|
||||
|
||||
Adds functions and function argument abilities, and improves compatibility with the new puppet parser
|
||||
|
||||
####Features
|
||||
- MODULES-444: `concat()` can now take more than two arrays
|
||||
- `basename()` added to have Ruby File.basename functionality
|
||||
- `delete()` can now take an array of items to remove
|
||||
- `prefix()` can now take a hash
|
||||
- `upcase()` can now take a hash or array of upcaseable things
|
||||
- `validate_absolute_path()` can now take an array
|
||||
- `validate_cmd()` can now use % in the command to embed the validation file argument in the string
|
||||
- MODULES-1473: deprecate `type()` function in favor of `type3x()`
|
||||
- MODULES-1473: Add `type_of()` to give better type information on future parser
|
||||
- Deprecate `private()` for `assert_private()` due to future parser
|
||||
- Adds `ceiling()` to take the ceiling of a number
|
||||
- Adds `fqdn_rand_string()` to generate random string based on fqdn
|
||||
- Adds `pw_hash()` to generate password hashes
|
||||
- Adds `validate_integer()`
|
||||
- Adds `validate_numeric()` (like `validate_integer()` but also accepts floats)
|
||||
|
||||
####Bugfixes
|
||||
- Fix seeding of `fqdn_rotate()`
|
||||
- `ensure_resource()` is more verbose on debug mode
|
||||
- Stricter argument checking for `dirname()`
|
||||
- Fix `is_domain_name()` to better match RFC
|
||||
- Fix `uriescape()` when called with array
|
||||
- Fix `file_line` resource when using the `after` attribute with `match`
|
||||
|
||||
##2015-01-14 - Supported Release 4.5.1
|
||||
###Summary
|
||||
|
||||
This release changes the temporary facter_dot_d cache locations outside of the /tmp directory due to a possible security vunerability. CVE-2015-1029
|
||||
|
||||
####Bugfixes
|
||||
- Facter_dot_d cache will now be stored in puppet libdir instead of tmp
|
||||
|
||||
##2014-12-15 - Supported Release 4.5.0
|
||||
###Summary
|
||||
|
||||
This release improves functionality of the member function and adds improved future parser support.
|
||||
|
||||
####Features
|
||||
- MODULES-1329: Update member() to allow the variable to be an array.
|
||||
- Sync .travis.yml, Gemfile, Rakefile, and CONTRIBUTING.md via modulesync
|
||||
|
||||
####Bugfixes
|
||||
- Fix range() to work with numeric ranges with the future parser
|
||||
- Accurately express SLES support in metadata.json (was missing 10SP4 and 12)
|
||||
- Don't require `line` to match the `match` parameter
|
||||
|
||||
##2014-11-10 - Supported Release 4.4.0
|
||||
###Summary
|
||||
This release has an overhauled readme, new private manifest function, and fixes many future parser bugs.
|
||||
|
||||
####Features
|
||||
- All new shiny README
|
||||
- New `private()` function for making private manifests (yay!)
|
||||
|
||||
####Bugfixes
|
||||
- Code reuse in `bool2num()` and `zip()`
|
||||
- Fix many functions to handle `generate()` no longer returning a string on new puppets
|
||||
- `concat()` no longer modifies the first argument (whoops)
|
||||
- strict variable support for `getvar()`, `member()`, `values_at`, and `has_interface_with()`
|
||||
- `to_bytes()` handles PB and EB now
|
||||
- Fix `tempfile` ruby requirement for `validate_augeas()` and `validate_cmd()`
|
||||
- Fix `validate_cmd()` for windows
|
||||
- Correct `validate_string()` docs to reflect non-handling of `undef`
|
||||
- Fix `file_line` matching on older rubies
|
||||
|
||||
|
||||
##2014-07-15 - Supported Release 4.3.2
|
||||
###Summary
|
||||
|
||||
This release merely updates metadata.json so the module can be uninstalled and
|
||||
upgraded via the puppet module command.
|
||||
|
||||
##2014-07-14 - Supported Release 4.3.1
|
||||
### Summary
|
||||
This supported release updates the metadata.json to work around upgrade behavior of the PMT.
|
||||
|
||||
#### Bugfixes
|
||||
- Synchronize metadata.json with PMT-generated metadata to pass checksums
|
||||
|
||||
##2014-06-27 - Supported Release 4.3.0
|
||||
### Summary
|
||||
This release is the first supported release of the stdlib 4 series. It remains
|
||||
backwards-compatible with the stdlib 3 series. It adds two new functions, one bugfix, and many testing updates.
|
||||
|
||||
#### Features
|
||||
- New `bool2str()` function
|
||||
- New `camelcase()` function
|
||||
|
||||
#### Bugfixes
|
||||
- Fix `has_interface_with()` when interfaces fact is nil
|
||||
|
||||
##2014-06-04 - Release 4.2.2
|
||||
### Summary
|
||||
|
||||
This release adds PE3.3 support in the metadata and fixes a few tests.
|
||||
|
||||
## 2014-05-08 - Release - 4.2.1
|
||||
### Summary
|
||||
This release moves a stray symlink that can cause problems.
|
||||
|
||||
## 2014-05-08 - Release - 4.2.0
|
||||
### Summary
|
||||
This release adds many new functions and fixes, and continues to be backwards compatible with stdlib 3.x
|
||||
|
||||
#### Features
|
||||
- New `base64()` function
|
||||
- New `deep_merge()` function
|
||||
- New `delete_undef_values()` function
|
||||
- New `delete_values()` function
|
||||
- New `difference()` function
|
||||
- New `intersection()` function
|
||||
- New `is_bool()` function
|
||||
- New `pick_default()` function
|
||||
- New `union()` function
|
||||
- New `validate_ipv4_address` function
|
||||
- New `validate_ipv6_address` function
|
||||
- Update `ensure_packages()` to take an option hash as a second parameter.
|
||||
- Update `range()` to take an optional third argument for range step
|
||||
- Update `validate_slength()` to take an optional third argument for minimum length
|
||||
- Update `file_line` resource to take `after` and `multiple` attributes
|
||||
|
||||
#### Bugfixes
|
||||
- Correct `is_string`, `is_domain_name`, `is_array`, `is_float`, and `is_function_available` for parsing odd types such as bools and hashes.
|
||||
- Allow facts.d facts to contain `=` in the value
|
||||
- Fix `root_home` fact on darwin systems
|
||||
- Fix `concat()` to work with a second non-array argument
|
||||
- Fix `floor()` to work with integer strings
|
||||
- Fix `is_integer()` to return true if passed integer strings
|
||||
- Fix `is_numeric()` to return true if passed integer strings
|
||||
- Fix `merge()` to work with empty strings
|
||||
- Fix `pick()` to raise the correct error type
|
||||
- Fix `uriescape()` to use the default URI.escape list
|
||||
- Add/update unit & acceptance tests.
|
||||
|
||||
|
||||
##2014-03-04 - Supported Release - 3.2.1
|
||||
###Summary
|
||||
This is a supported release
|
||||
|
||||
####Bugfixes
|
||||
- Fixed `is_integer`/`is_float`/`is_numeric` for checking the value of arithmatic expressions.
|
||||
|
||||
####Known bugs
|
||||
* No known bugs
|
||||
|
||||
---
|
||||
|
||||
##### 2013-05-06 - Jeff McCune <jeff@puppetlabs.com> - 4.1.0
|
||||
|
||||
* (#20582) Restore facter\_dot\_d to stdlib for PE users (3b887c8)
|
||||
* (maint) Update Gemfile with GEM\_FACTER\_VERSION (f44d535)
|
||||
|
||||
##### 2013-05-06 - Alex Cline <acline@us.ibm.com> - 4.1.0
|
||||
|
||||
* Terser method of string to array conversion courtesy of ethooz. (d38bce0)
|
||||
|
||||
##### 2013-05-06 - Alex Cline <acline@us.ibm.com> 4.1.0
|
||||
|
||||
* Refactor ensure\_resource expectations (b33cc24)
|
||||
|
||||
##### 2013-05-06 - Alex Cline <acline@us.ibm.com> 4.1.0
|
||||
|
||||
* Changed str-to-array conversion and removed abbreviation. (de253db)
|
||||
|
||||
##### 2013-05-03 - Alex Cline <acline@us.ibm.com> 4.1.0
|
||||
|
||||
* (#20548) Allow an array of resource titles to be passed into the ensure\_resource function (e08734a)
|
||||
|
||||
##### 2013-05-02 - Raphaël Pinson <raphael.pinson@camptocamp.com> - 4.1.0
|
||||
|
||||
* Add a dirname function (2ba9e47)
|
||||
|
||||
##### 2013-04-29 - Mark Smith-Guerrero <msmithgu@gmail.com> - 4.1.0
|
||||
|
||||
* (maint) Fix a small typo in hash() description (928036a)
|
||||
|
||||
##### 2013-04-12 - Jeff McCune <jeff@puppetlabs.com> - 4.0.2
|
||||
|
||||
* Update user information in gemspec to make the intent of the Gem clear.
|
||||
|
||||
##### 2013-04-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.1
|
||||
|
||||
* Fix README function documentation (ab3e30c)
|
||||
|
||||
##### 2013-04-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
|
||||
|
||||
* stdlib 4.0 drops support with Puppet 2.7
|
||||
* stdlib 4.0 preserves support with Puppet 3
|
||||
|
||||
##### 2013-04-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
|
||||
|
||||
* Add ability to use puppet from git via bundler (9c5805f)
|
||||
|
||||
##### 2013-04-10 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
|
||||
|
||||
* (maint) Make stdlib usable as a Ruby GEM (e81a45e)
|
||||
|
||||
##### 2013-04-10 - Erik Dalén <dalen@spotify.com> - 4.0.0
|
||||
|
||||
* Add a count function (f28550e)
|
||||
|
||||
##### 2013-03-31 - Amos Shapira <ashapira@atlassian.com> - 4.0.0
|
||||
|
||||
* (#19998) Implement any2array (7a2fb80)
|
||||
|
||||
##### 2013-03-29 - Steve Huff <shuff@vecna.org> - 4.0.0
|
||||
|
||||
* (19864) num2bool match fix (8d217f0)
|
||||
|
||||
##### 2013-03-20 - Erik Dalén <dalen@spotify.com> - 4.0.0
|
||||
|
||||
* Allow comparisons of Numeric and number as String (ff5dd5d)
|
||||
|
||||
##### 2013-03-26 - Richard Soderberg <rsoderberg@mozilla.com> - 4.0.0
|
||||
|
||||
* add suffix function to accompany the prefix function (88a93ac)
|
||||
|
||||
##### 2013-03-19 - Kristof Willaert <kristof.willaert@gmail.com> - 4.0.0
|
||||
|
||||
* Add floor function implementation and unit tests (0527341)
|
||||
|
||||
##### 2012-04-03 - Eric Shamow <eric@puppetlabs.com> - 4.0.0
|
||||
|
||||
* (#13610) Add is\_function\_available to stdlib (961dcab)
|
||||
|
||||
##### 2012-12-17 - Justin Lambert <jlambert@eml.cc> - 4.0.0
|
||||
|
||||
* str2bool should return a boolean if called with a boolean (5d5a4d4)
|
||||
|
||||
##### 2012-10-23 - Uwe Stuehler <ustuehler@team.mobile.de> - 4.0.0
|
||||
|
||||
* Fix number of arguments check in flatten() (e80207b)
|
||||
|
||||
##### 2013-03-11 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
|
||||
|
||||
* Add contributing document (96e19d0)
|
||||
|
||||
##### 2013-03-04 - Raphaël Pinson <raphael.pinson@camptocamp.com> - 4.0.0
|
||||
|
||||
* Add missing documentation for validate\_augeas and validate\_cmd to README.markdown (a1510a1)
|
||||
|
||||
##### 2013-02-14 - Joshua Hoblitt <jhoblitt@cpan.org> - 4.0.0
|
||||
|
||||
* (#19272) Add has\_element() function (95cf3fe)
|
||||
|
||||
##### 2013-02-07 - Raphaël Pinson <raphael.pinson@camptocamp.com> - 4.0.0
|
||||
|
||||
* validate\_cmd(): Use Puppet::Util::Execution.execute when available (69248df)
|
||||
|
||||
##### 2012-12-06 - Raphaël Pinson <raphink@gmail.com> - 4.0.0
|
||||
|
||||
* Add validate\_augeas function (3a97c23)
|
||||
|
||||
##### 2012-12-06 - Raphaël Pinson <raphink@gmail.com> - 4.0.0
|
||||
|
||||
* Add validate\_cmd function (6902cc5)
|
||||
|
||||
##### 2013-01-14 - David Schmitt <david@dasz.at> - 4.0.0
|
||||
|
||||
* Add geppetto project definition (b3fc0a3)
|
||||
|
||||
##### 2013-01-02 - Jaka Hudoklin <jakahudoklin@gmail.com> - 4.0.0
|
||||
|
||||
* Add getparam function to get defined resource parameters (20e0e07)
|
||||
|
||||
##### 2013-01-05 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
|
||||
|
||||
* (maint) Add Travis CI Support (d082046)
|
||||
|
||||
##### 2012-12-04 - Jeff McCune <jeff@puppetlabs.com> - 4.0.0
|
||||
|
||||
* Clarify that stdlib 3 supports Puppet 3 (3a6085f)
|
||||
|
||||
##### 2012-11-30 - Erik Dalén <dalen@spotify.com> - 4.0.0
|
||||
|
||||
* maint: style guideline fixes (7742e5f)
|
||||
|
||||
##### 2012-11-09 - James Fryman <james@frymanet.com> - 4.0.0
|
||||
|
||||
* puppet-lint cleanup (88acc52)
|
||||
|
||||
##### 2012-11-06 - Joe Julian <me@joejulian.name> - 4.0.0
|
||||
|
||||
* Add function, uriescape, to URI.escape strings. Redmine #17459 (fd52b8d)
|
||||
|
||||
##### 2012-09-18 - Chad Metcalf <chad@wibidata.com> - 3.2.0
|
||||
|
||||
* Add an ensure\_packages function. (8a8c09e)
|
||||
|
||||
##### 2012-11-23 - Erik Dalén <dalen@spotify.com> - 3.2.0
|
||||
|
||||
* (#17797) min() and max() functions (9954133)
|
||||
|
||||
##### 2012-05-23 - Peter Meier <peter.meier@immerda.ch> - 3.2.0
|
||||
|
||||
* (#14670) autorequire a file\_line resource's path (dfcee63)
|
||||
|
||||
##### 2012-11-19 - Joshua Harlan Lifton <lifton@puppetlabs.com> - 3.2.0
|
||||
|
||||
* Add join\_keys\_to\_values function (ee0f2b3)
|
||||
|
||||
##### 2012-11-17 - Joshua Harlan Lifton <lifton@puppetlabs.com> - 3.2.0
|
||||
|
||||
* Extend delete function for strings and hashes (7322e4d)
|
||||
|
||||
##### 2012-08-03 - Gary Larizza <gary@puppetlabs.com> - 3.2.0
|
||||
|
||||
* Add the pick() function (ba6dd13)
|
||||
|
||||
##### 2012-03-20 - Wil Cooley <wcooley@pdx.edu> - 3.2.0
|
||||
|
||||
* (#13974) Add predicate functions for interface facts (f819417)
|
||||
|
||||
##### 2012-11-06 - Joe Julian <me@joejulian.name> - 3.2.0
|
||||
|
||||
* Add function, uriescape, to URI.escape strings. Redmine #17459 (70f4a0e)
|
||||
|
||||
##### 2012-10-25 - Jeff McCune <jeff@puppetlabs.com> - 3.1.1
|
||||
|
||||
* (maint) Fix spec failures resulting from Facter API changes (97f836f)
|
||||
|
||||
##### 2012-10-23 - Matthaus Owens <matthaus@puppetlabs.com> - 3.1.0
|
||||
|
||||
* Add PE facts to stdlib (cdf3b05)
|
||||
|
||||
##### 2012-08-16 - Jeff McCune <jeff@puppetlabs.com> - 3.0.1
|
||||
|
||||
* Fix accidental removal of facts\_dot\_d.rb in 3.0.0 release
|
||||
|
||||
##### 2012-08-16 - Jeff McCune <jeff@puppetlabs.com> - 3.0.0
|
||||
|
||||
* stdlib 3.0 drops support with Puppet 2.6
|
||||
* stdlib 3.0 preserves support with Puppet 2.7
|
||||
|
||||
##### 2012-08-07 - Dan Bode <dan@puppetlabs.com> - 3.0.0
|
||||
|
||||
* Add function ensure\_resource and defined\_with\_params (ba789de)
|
||||
|
||||
##### 2012-07-10 - Hailee Kenney <hailee@puppetlabs.com> - 3.0.0
|
||||
|
||||
* (#2157) Remove facter\_dot\_d for compatibility with external facts (f92574f)
|
||||
|
||||
##### 2012-04-10 - Chris Price <chris@puppetlabs.com> - 3.0.0
|
||||
|
||||
* (#13693) moving logic from local spec\_helper to puppetlabs\_spec\_helper (85f96df)
|
||||
|
||||
##### 2012-10-25 - Jeff McCune <jeff@puppetlabs.com> - 2.5.1
|
||||
|
||||
* (maint) Fix spec failures resulting from Facter API changes (97f836f)
|
||||
|
||||
##### 2012-10-23 - Matthaus Owens <matthaus@puppetlabs.com> - 2.5.0
|
||||
|
||||
* Add PE facts to stdlib (cdf3b05)
|
||||
|
||||
##### 2012-08-15 - Dan Bode <dan@puppetlabs.com> - 2.5.0
|
||||
|
||||
* Explicitly load functions used by ensure\_resource (9fc3063)
|
||||
|
||||
##### 2012-08-13 - Dan Bode <dan@puppetlabs.com> - 2.5.0
|
||||
|
||||
* Add better docs about duplicate resource failures (97d327a)
|
||||
|
||||
##### 2012-08-13 - Dan Bode <dan@puppetlabs.com> - 2.5.0
|
||||
|
||||
* Handle undef for parameter argument (4f8b133)
|
||||
|
||||
##### 2012-08-07 - Dan Bode <dan@puppetlabs.com> - 2.5.0
|
||||
|
||||
* Add function ensure\_resource and defined\_with\_params (a0cb8cd)
|
||||
|
||||
##### 2012-08-20 - Jeff McCune <jeff@puppetlabs.com> - 2.5.0
|
||||
|
||||
* Disable tests that fail on 2.6.x due to #15912 (c81496e)
|
||||
|
||||
##### 2012-08-20 - Jeff McCune <jeff@puppetlabs.com> - 2.5.0
|
||||
|
||||
* (Maint) Fix mis-use of rvalue functions as statements (4492913)
|
||||
|
||||
##### 2012-08-20 - Jeff McCune <jeff@puppetlabs.com> - 2.5.0
|
||||
|
||||
* Add .rspec file to repo root (88789e8)
|
||||
|
||||
##### 2012-06-07 - Chris Price <chris@puppetlabs.com> - 2.4.0
|
||||
|
||||
* Add support for a 'match' parameter to file\_line (a06c0d8)
|
||||
|
||||
##### 2012-08-07 - Erik Dalén <dalen@spotify.com> - 2.4.0
|
||||
|
||||
* (#15872) Add to\_bytes function (247b69c)
|
||||
|
||||
##### 2012-07-19 - Jeff McCune <jeff@puppetlabs.com> - 2.4.0
|
||||
|
||||
* (Maint) use PuppetlabsSpec::PuppetInternals.scope (master) (deafe88)
|
||||
|
||||
##### 2012-07-10 - Hailee Kenney <hailee@puppetlabs.com> - 2.4.0
|
||||
|
||||
* (#2157) Make facts\_dot\_d compatible with external facts (5fb0ddc)
|
||||
|
||||
##### 2012-03-16 - Steve Traylen <steve.traylen@cern.ch> - 2.4.0
|
||||
|
||||
* (#13205) Rotate array/string randomley based on fqdn, fqdn\_rotate() (fef247b)
|
||||
|
||||
##### 2012-05-22 - Peter Meier <peter.meier@immerda.ch> - 2.3.3
|
||||
|
||||
* fix regression in #11017 properly (f0a62c7)
|
||||
|
||||
##### 2012-05-10 - Jeff McCune <jeff@puppetlabs.com> - 2.3.3
|
||||
|
||||
* Fix spec tests using the new spec\_helper (7d34333)
|
||||
|
||||
##### 2012-05-10 - Puppet Labs <support@puppetlabs.com> - 2.3.2
|
||||
|
||||
* Make file\_line default to ensure => present (1373e70)
|
||||
* Memoize file\_line spec instance variables (20aacc5)
|
||||
* Fix spec tests using the new spec\_helper (1ebfa5d)
|
||||
* (#13595) initialize\_everything\_for\_tests couples modules Puppet ver (3222f35)
|
||||
* (#13439) Fix MRI 1.9 issue with spec\_helper (15c5fd1)
|
||||
* (#13439) Fix test failures with Puppet 2.6.x (665610b)
|
||||
* (#13439) refactor spec helper for compatibility with both puppet 2.7 and master (82194ca)
|
||||
* (#13494) Specify the behavior of zero padded strings (61891bb)
|
||||
|
||||
##### 2012-03-29 Puppet Labs <support@puppetlabs.com> - 2.1.3
|
||||
|
||||
* (#11607) Add Rakefile to enable spec testing
|
||||
* (#12377) Avoid infinite loop when retrying require json
|
||||
|
||||
##### 2012-03-13 Puppet Labs <support@puppetlabs.com> - 2.3.1
|
||||
|
||||
* (#13091) Fix LoadError bug with puppet apply and puppet\_vardir fact
|
||||
|
||||
##### 2012-03-12 Puppet Labs <support@puppetlabs.com> - 2.3.0
|
||||
|
||||
* Add a large number of new Puppet functions
|
||||
* Backwards compatibility preserved with 2.2.x
|
||||
|
||||
##### 2011-12-30 Puppet Labs <support@puppetlabs.com> - 2.2.1
|
||||
|
||||
* Documentation only release for the Forge
|
||||
|
||||
##### 2011-12-30 Puppet Labs <support@puppetlabs.com> - 2.1.2
|
||||
|
||||
* Documentation only release for PE 2.0.x
|
||||
|
||||
##### 2011-11-08 Puppet Labs <support@puppetlabs.com> - 2.2.0
|
||||
|
||||
* #10285 - Refactor json to use pson instead.
|
||||
* Maint - Add watchr autotest script
|
||||
* Maint - Make rspec tests work with Puppet 2.6.4
|
||||
* #9859 - Add root\_home fact and tests
|
||||
|
||||
##### 2011-08-18 Puppet Labs <support@puppetlabs.com> - 2.1.1
|
||||
|
||||
* Change facts.d paths to match Facter 2.0 paths.
|
||||
* /etc/facter/facts.d
|
||||
* /etc/puppetlabs/facter/facts.d
|
||||
|
||||
##### 2011-08-17 Puppet Labs <support@puppetlabs.com> - 2.1.0
|
||||
|
||||
* Add R.I. Pienaar's facts.d custom facter fact
|
||||
* facts defined in /etc/facts.d and /etc/puppetlabs/facts.d are
|
||||
automatically loaded now.
|
||||
|
||||
##### 2011-08-04 Puppet Labs <support@puppetlabs.com> - 2.0.0
|
||||
|
||||
* Rename whole\_line to file\_line
|
||||
* This is an API change and as such motivating a 2.0.0 release according to semver.org.
|
||||
|
||||
##### 2011-08-04 Puppet Labs <support@puppetlabs.com> - 1.1.0
|
||||
|
||||
* Rename append\_line to whole\_line
|
||||
* This is an API change and as such motivating a 1.1.0 release.
|
||||
|
||||
##### 2011-08-04 Puppet Labs <support@puppetlabs.com> - 1.0.0
|
||||
|
||||
* Initial stable release
|
||||
* Add validate\_array and validate\_string functions
|
||||
* Make merge() function work with Ruby 1.8.5
|
||||
* Add hash merging function
|
||||
* Add has\_key function
|
||||
* Add loadyaml() function
|
||||
* Add append\_line native
|
||||
|
||||
##### 2011-06-21 Jeff McCune <jeff@puppetlabs.com> - 0.1.7
|
||||
|
||||
* Add validate\_hash() and getvar() functions
|
||||
|
||||
##### 2011-06-15 Jeff McCune <jeff@puppetlabs.com> - 0.1.6
|
||||
|
||||
* Add anchor resource type to provide containment for composite classes
|
||||
|
||||
##### 2011-06-03 Jeff McCune <jeff@puppetlabs.com> - 0.1.5
|
||||
|
||||
* Add validate\_bool() function to stdlib
|
||||
|
||||
##### 0.1.4 2011-05-26 Jeff McCune <jeff@puppetlabs.com>
|
||||
|
||||
* Move most stages after main
|
||||
|
||||
##### 0.1.3 2011-05-25 Jeff McCune <jeff@puppetlabs.com>
|
||||
|
||||
* Add validate\_re() function
|
||||
|
||||
##### 0.1.2 2011-05-24 Jeff McCune <jeff@puppetlabs.com>
|
||||
|
||||
* Update to add annotated tag
|
||||
|
||||
##### 0.1.1 2011-05-24 Jeff McCune <jeff@puppetlabs.com>
|
||||
|
||||
* Add stdlib::stages class with a standard set of stages
|
@ -0,0 +1,218 @@
|
||||
Checklist (and a short version for the impatient)
|
||||
=================================================
|
||||
|
||||
* Commits:
|
||||
|
||||
- Make commits of logical units.
|
||||
|
||||
- Check for unnecessary whitespace with "git diff --check" before
|
||||
committing.
|
||||
|
||||
- Commit using Unix line endings (check the settings around "crlf" in
|
||||
git-config(1)).
|
||||
|
||||
- Do not check in commented out code or unneeded files.
|
||||
|
||||
- The first line of the commit message should be a short
|
||||
description (50 characters is the soft limit, excluding ticket
|
||||
number(s)), and should skip the full stop.
|
||||
|
||||
- Associate the issue in the message. The first line should include
|
||||
the issue number in the form "(#XXXX) Rest of message".
|
||||
|
||||
- The body should provide a meaningful commit message, which:
|
||||
|
||||
- uses the imperative, present tense: "change", not "changed" or
|
||||
"changes".
|
||||
|
||||
- includes motivation for the change, and contrasts its
|
||||
implementation with the previous behavior.
|
||||
|
||||
- Make sure that you have tests for the bug you are fixing, or
|
||||
feature you are adding.
|
||||
|
||||
- Make sure the test suites passes after your commit:
|
||||
`bundle exec rspec spec/acceptance` More information on [testing](#Testing) below
|
||||
|
||||
- When introducing a new feature, make sure it is properly
|
||||
documented in the README.md
|
||||
|
||||
* Submission:
|
||||
|
||||
* Pre-requisites:
|
||||
|
||||
- Make sure you have a [GitHub account](https://github.com/join)
|
||||
|
||||
- [Create a ticket](https://tickets.puppetlabs.com/secure/CreateIssue!default.jspa), or [watch the ticket](https://tickets.puppetlabs.com/browse/) you are patching for.
|
||||
|
||||
* Preferred method:
|
||||
|
||||
- Fork the repository on GitHub.
|
||||
|
||||
- Push your changes to a topic branch in your fork of the
|
||||
repository. (the format ticket/1234-short_description_of_change is
|
||||
usually preferred for this project).
|
||||
|
||||
- Submit a pull request to the repository in the puppetlabs
|
||||
organization.
|
||||
|
||||
The long version
|
||||
================
|
||||
|
||||
1. Make separate commits for logically separate changes.
|
||||
|
||||
Please break your commits down into logically consistent units
|
||||
which include new or changed tests relevant to the rest of the
|
||||
change. The goal of doing this is to make the diff easier to
|
||||
read for whoever is reviewing your code. In general, the easier
|
||||
your diff is to read, the more likely someone will be happy to
|
||||
review it and get it into the code base.
|
||||
|
||||
If you are going to refactor a piece of code, please do so as a
|
||||
separate commit from your feature or bug fix changes.
|
||||
|
||||
We also really appreciate changes that include tests to make
|
||||
sure the bug is not re-introduced, and that the feature is not
|
||||
accidentally broken.
|
||||
|
||||
Describe the technical detail of the change(s). If your
|
||||
description starts to get too long, that is a good sign that you
|
||||
probably need to split up your commit into more finely grained
|
||||
pieces.
|
||||
|
||||
Commits which plainly describe the things which help
|
||||
reviewers check the patch and future developers understand the
|
||||
code are much more likely to be merged in with a minimum of
|
||||
bike-shedding or requested changes. Ideally, the commit message
|
||||
would include information, and be in a form suitable for
|
||||
inclusion in the release notes for the version of Puppet that
|
||||
includes them.
|
||||
|
||||
Please also check that you are not introducing any trailing
|
||||
whitespace or other "whitespace errors". You can do this by
|
||||
running "git diff --check" on your changes before you commit.
|
||||
|
||||
2. Sending your patches
|
||||
|
||||
To submit your changes via a GitHub pull request, we _highly_
|
||||
recommend that you have them on a topic branch, instead of
|
||||
directly on "master".
|
||||
It makes things much easier to keep track of, especially if
|
||||
you decide to work on another thing before your first change
|
||||
is merged in.
|
||||
|
||||
GitHub has some pretty good
|
||||
[general documentation](http://help.github.com/) on using
|
||||
their site. They also have documentation on
|
||||
[creating pull requests](http://help.github.com/send-pull-requests/).
|
||||
|
||||
In general, after pushing your topic branch up to your
|
||||
repository on GitHub, you can switch to the branch in the
|
||||
GitHub UI and click "Pull Request" towards the top of the page
|
||||
in order to open a pull request.
|
||||
|
||||
|
||||
3. Update the related GitHub issue.
|
||||
|
||||
If there is a GitHub issue associated with the change you
|
||||
submitted, then you should update the ticket to include the
|
||||
location of your branch, along with any other commentary you
|
||||
may wish to make.
|
||||
|
||||
Testing
|
||||
=======
|
||||
|
||||
Getting Started
|
||||
---------------
|
||||
|
||||
Our puppet modules provide [`Gemfile`](./Gemfile)s which can tell a ruby
|
||||
package manager such as [bundler](http://bundler.io/) what Ruby packages,
|
||||
or Gems, are required to build, develop, and test this software.
|
||||
|
||||
Please make sure you have [bundler installed](http://bundler.io/#getting-started)
|
||||
on your system, then use it to install all dependencies needed for this project,
|
||||
by running
|
||||
|
||||
```shell
|
||||
% bundle install
|
||||
Fetching gem metadata from https://rubygems.org/........
|
||||
Fetching gem metadata from https://rubygems.org/..
|
||||
Using rake (10.1.0)
|
||||
Using builder (3.2.2)
|
||||
-- 8><-- many more --><8 --
|
||||
Using rspec-system-puppet (2.2.0)
|
||||
Using serverspec (0.6.3)
|
||||
Using rspec-system-serverspec (1.0.0)
|
||||
Using bundler (1.3.5)
|
||||
Your bundle is complete!
|
||||
Use `bundle show [gemname]` to see where a bundled gem is installed.
|
||||
```
|
||||
|
||||
NOTE some systems may require you to run this command with sudo.
|
||||
|
||||
If you already have those gems installed, make sure they are up-to-date:
|
||||
|
||||
```shell
|
||||
% bundle update
|
||||
```
|
||||
|
||||
With all dependencies in place and up-to-date we can now run the tests:
|
||||
|
||||
```shell
|
||||
% bundle exec rake spec
|
||||
```
|
||||
|
||||
This will execute all the [rspec tests](http://rspec-puppet.com/) tests
|
||||
under [spec/defines](./spec/defines), [spec/classes](./spec/classes),
|
||||
and so on. rspec tests may have the same kind of dependencies as the
|
||||
module they are testing. While the module defines in its [Modulefile](./Modulefile),
|
||||
rspec tests define them in [.fixtures.yml](./fixtures.yml).
|
||||
|
||||
Some puppet modules also come with [beaker](https://github.com/puppetlabs/beaker)
|
||||
tests. These tests spin up a virtual machine under
|
||||
[VirtualBox](https://www.virtualbox.org/)) with, controlling it with
|
||||
[Vagrant](http://www.vagrantup.com/) to actually simulate scripted test
|
||||
scenarios. In order to run these, you will need both of those tools
|
||||
installed on your system.
|
||||
|
||||
You can run them by issuing the following command
|
||||
|
||||
```shell
|
||||
% bundle exec rake spec_clean
|
||||
% bundle exec rspec spec/acceptance
|
||||
```
|
||||
|
||||
This will now download a pre-fabricated image configured in the [default node-set](./spec/acceptance/nodesets/default.yml),
|
||||
install puppet, copy this module and install its dependencies per [spec/spec_helper_acceptance.rb](./spec/spec_helper_acceptance.rb)
|
||||
and then run all the tests under [spec/acceptance](./spec/acceptance).
|
||||
|
||||
Writing Tests
|
||||
-------------
|
||||
|
||||
XXX getting started writing tests.
|
||||
|
||||
If you have commit access to the repository
|
||||
===========================================
|
||||
|
||||
Even if you have commit access to the repository, you will still need to
|
||||
go through the process above, and have someone else review and merge
|
||||
in your changes. The rule is that all changes must be reviewed by a
|
||||
developer on the project (that did not write the code) to ensure that
|
||||
all changes go through a code review process.
|
||||
|
||||
Having someone other than the author of the topic branch recorded as
|
||||
performing the merge is the record that they performed the code
|
||||
review.
|
||||
|
||||
|
||||
Additional Resources
|
||||
====================
|
||||
|
||||
* [Getting additional help](http://puppet.com/community/get-help)
|
||||
|
||||
* [Writing tests](https://docs.puppet.com/guides/module_guides/bgtm.html#step-three-module-testing)
|
||||
|
||||
* [General GitHub documentation](http://help.github.com/)
|
||||
|
||||
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
|
||||
|
40
deployment_scripts/puppet/modules/puppetlabs-stdlib/Gemfile
Normal file
40
deployment_scripts/puppet/modules/puppetlabs-stdlib/Gemfile
Normal file
@ -0,0 +1,40 @@
|
||||
#This file is generated by ModuleSync, do not edit.
|
||||
|
||||
source ENV['GEM_SOURCE'] || "https://rubygems.org"
|
||||
|
||||
def location_for(place, version = nil)
|
||||
if place =~ /^(git[:@][^#]*)#(.*)/
|
||||
[version, { :git => $1, :branch => $2, :require => false}].compact
|
||||
elsif place =~ /^file:\/\/(.*)/
|
||||
['>= 0', { :path => File.expand_path($1), :require => false}]
|
||||
else
|
||||
[place, version, { :require => false}].compact
|
||||
end
|
||||
end
|
||||
|
||||
group :development, :unit_tests do
|
||||
gem 'json', :require => false
|
||||
gem 'metadata-json-lint', :require => false
|
||||
gem 'puppet_facts', :require => false
|
||||
gem 'puppetlabs_spec_helper', :require => false
|
||||
gem 'rspec-puppet', '>= 2.3.2', :require => false
|
||||
gem 'simplecov', :require => false
|
||||
gem 'puppet-blacksmith', :require => false
|
||||
gem 'rest-client', '~> 1.8.0', :require => false
|
||||
end
|
||||
group :system_tests do
|
||||
gem 'beaker-rspec', *location_for(ENV['BEAKER_RSPEC_VERSION'] || '>= 3.4')
|
||||
gem 'beaker', *location_for(ENV['BEAKER_VERSION'])
|
||||
gem 'serverspec', :require => false
|
||||
gem 'beaker-puppet_install_helper', :require => false
|
||||
gem 'master_manipulator', :require => false
|
||||
gem 'beaker-hostgenerator', *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'])
|
||||
end
|
||||
|
||||
gem 'facter', *location_for(ENV['FACTER_GEM_VERSION'])
|
||||
gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])
|
||||
|
||||
|
||||
if File.exists? "#{__FILE__}.local"
|
||||
eval(File.read("#{__FILE__}.local"), binding)
|
||||
end
|
202
deployment_scripts/puppet/modules/puppetlabs-stdlib/LICENSE
Normal file
202
deployment_scripts/puppet/modules/puppetlabs-stdlib/LICENSE
Normal file
@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
23
deployment_scripts/puppet/modules/puppetlabs-stdlib/NOTICE
Normal file
23
deployment_scripts/puppet/modules/puppetlabs-stdlib/NOTICE
Normal file
@ -0,0 +1,23 @@
|
||||
stdlib puppet module
|
||||
|
||||
Copyright (C) 2011-2016 Puppet Labs, Inc.
|
||||
|
||||
and some parts:
|
||||
|
||||
Copyright (C) 2011 Krzysztof Wilczynski
|
||||
|
||||
|
||||
Puppet Labs can be contacted at: info@puppetlabs.com
|
||||
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
1514
deployment_scripts/puppet/modules/puppetlabs-stdlib/README.markdown
Normal file
1514
deployment_scripts/puppet/modules/puppetlabs-stdlib/README.markdown
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,35 @@
|
||||
Puppet Specific Facts
|
||||
=====================
|
||||
|
||||
Facter is meant to stand alone and apart from Puppet. However, Facter often
|
||||
runs inside Puppet and all custom facts included in the stdlib module will
|
||||
almost always be evaluated in the context of Puppet and Facter working
|
||||
together.
|
||||
|
||||
Still, we don't want to write custom facts that blow up in the users face if
|
||||
Puppet is not loaded in memory. This is often the case if the user runs
|
||||
`facter` without also supplying the `--puppet` flag.
|
||||
|
||||
Ah! But Jeff, the custom fact won't be in the `$LOAD_PATH` unless the user
|
||||
supplies `--facter`! You might say...
|
||||
|
||||
Not (always) true I say! If the user happens to have a CWD of
|
||||
`<modulepath>/stdlib/lib` then the facts will automatically be evaluated and
|
||||
blow up.
|
||||
|
||||
In any event, it's pretty easy to write a fact that has no value if Puppet is
|
||||
not loaded. Simply do it like this:
|
||||
|
||||
Facter.add(:node_vardir) do
|
||||
setcode do
|
||||
# This will be nil if Puppet is not available.
|
||||
Facter::Util::PuppetSettings.with_puppet do
|
||||
Puppet[:vardir]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
The `Facter::Util::PuppetSettings.with_puppet` method accepts a block and
|
||||
yields to it only if the Puppet library is loaded. If the Puppet library is
|
||||
not loaded, then the method silently returns `nil` which Facter interprets as
|
||||
an undefined fact value. The net effect is that the fact won't be set.
|
@ -0,0 +1,7 @@
|
||||
NOTE
|
||||
====
|
||||
|
||||
This project's specs depend on puppet core, and thus they require the
|
||||
`puppetlabs_spec_helper` project. For more information please see the README
|
||||
in that project, which can be found here: [puppetlabs spec
|
||||
helper](https://github.com/puppetlabs/puppetlabs_spec_helper)
|
@ -0,0 +1,24 @@
|
||||
# Contributing to this module #
|
||||
|
||||
* Work in a topic branch
|
||||
* Submit a github pull request
|
||||
* Address any comments / feeback
|
||||
* Merge into master using --no-ff
|
||||
|
||||
# Releasing this module #
|
||||
|
||||
* This module adheres to http://semver.org/
|
||||
* Look for API breaking changes using git diff vX.Y.Z..master
|
||||
* If no API breaking changes, the minor version may be bumped.
|
||||
* If there are API breaking changes, the major version must be bumped.
|
||||
* If there are only small minor changes, the patch version may be bumped.
|
||||
* Update the CHANGELOG
|
||||
* Update the Modulefile
|
||||
* Commit these changes with a message along the lines of "Update CHANGELOG and
|
||||
Modulefile for release"
|
||||
* Create an annotated tag with git tag -a vX.Y.Z -m 'version X.Y.Z' (NOTE the
|
||||
leading v as per semver.org)
|
||||
* Push the tag with git push origin --tags
|
||||
* Build a new package with puppet-module or the rake build task if it exists
|
||||
* Publish the new package to the forge
|
||||
* Bonus points for an announcement to puppet-users.
|
42
deployment_scripts/puppet/modules/puppetlabs-stdlib/Rakefile
Normal file
42
deployment_scripts/puppet/modules/puppetlabs-stdlib/Rakefile
Normal file
@ -0,0 +1,42 @@
|
||||
require 'puppet_blacksmith/rake_tasks'
|
||||
require 'puppet-lint/tasks/puppet-lint'
|
||||
require 'puppetlabs_spec_helper/rake_tasks'
|
||||
|
||||
PuppetLint.configuration.fail_on_warnings = true
|
||||
PuppetLint.configuration.send('relative')
|
||||
PuppetLint.configuration.send('disable_140chars')
|
||||
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
|
||||
PuppetLint.configuration.send('disable_documentation')
|
||||
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
|
||||
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp", "bundle/**/*", "vendor/**/*"]
|
||||
|
||||
desc 'Generate pooler nodesets'
|
||||
task :gen_nodeset do
|
||||
require 'beaker-hostgenerator'
|
||||
require 'securerandom'
|
||||
require 'fileutils'
|
||||
|
||||
agent_target = ENV['TEST_TARGET']
|
||||
if ! agent_target
|
||||
STDERR.puts 'TEST_TARGET environment variable is not set'
|
||||
STDERR.puts 'setting to default value of "redhat-64default."'
|
||||
agent_target = 'redhat-64default.'
|
||||
end
|
||||
|
||||
master_target = ENV['MASTER_TEST_TARGET']
|
||||
if ! master_target
|
||||
STDERR.puts 'MASTER_TEST_TARGET environment variable is not set'
|
||||
STDERR.puts 'setting to default value of "redhat7-64mdcl"'
|
||||
master_target = 'redhat7-64mdcl'
|
||||
end
|
||||
|
||||
targets = "#{master_target}-#{agent_target}"
|
||||
cli = BeakerHostGenerator::CLI.new([targets])
|
||||
nodeset_dir = "tmp/nodesets"
|
||||
nodeset = "#{nodeset_dir}/#{targets}-#{SecureRandom.uuid}.yaml"
|
||||
FileUtils.mkdir_p(nodeset_dir)
|
||||
File.open(nodeset, 'w') do |fh|
|
||||
fh.print(cli.execute)
|
||||
end
|
||||
puts nodeset
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
# This is a simple smoke test
|
||||
# of the file_line resource type.
|
||||
file { '/tmp/dansfile':
|
||||
ensure => file,
|
||||
} ->
|
||||
file_line { 'dans_line':
|
||||
line => 'dan is awesome',
|
||||
path => '/tmp/dansfile',
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
include ::stdlib
|
||||
info('has_interface_with(\'lo\'):', has_interface_with('lo'))
|
||||
info('has_interface_with(\'loX\'):', has_interface_with('loX'))
|
||||
info('has_interface_with(\'ipaddress\', \'127.0.0.1\'):', has_interface_with('ipaddress', '127.0.0.1'))
|
||||
info('has_interface_with(\'ipaddress\', \'127.0.0.100\'):', has_interface_with('ipaddress', '127.0.0.100'))
|
||||
info('has_interface_with(\'network\', \'127.0.0.0\'):', has_interface_with('network', '127.0.0.0'))
|
||||
info('has_interface_with(\'network\', \'128.0.0.0\'):', has_interface_with('network', '128.0.0.0'))
|
||||
info('has_interface_with(\'netmask\', \'255.0.0.0\'):', has_interface_with('netmask', '255.0.0.0'))
|
||||
info('has_interface_with(\'netmask\', \'256.0.0.0\'):', has_interface_with('netmask', '256.0.0.0'))
|
@ -0,0 +1,3 @@
|
||||
include ::stdlib
|
||||
info('has_ip_address(\'192.168.1.256\'):', has_ip_address('192.168.1.256'))
|
||||
info('has_ip_address(\'127.0.0.1\'):', has_ip_address('127.0.0.1'))
|
@ -0,0 +1,3 @@
|
||||
include ::stdlib
|
||||
info('has_ip_network(\'127.0.0.0\'):', has_ip_network('127.0.0.0'))
|
||||
info('has_ip_network(\'128.0.0.0\'):', has_ip_network('128.0.0.0'))
|
@ -0,0 +1 @@
|
||||
include ::stdlib
|
@ -0,0 +1,202 @@
|
||||
# A Facter plugin that loads facts from /etc/facter/facts.d
|
||||
# and /etc/puppetlabs/facter/facts.d.
|
||||
#
|
||||
# Facts can be in the form of JSON, YAML or Text files
|
||||
# and any executable that returns key=value pairs.
|
||||
#
|
||||
# In the case of scripts you can also create a file that
|
||||
# contains a cache TTL. For foo.sh store the ttl as just
|
||||
# a number in foo.sh.ttl
|
||||
#
|
||||
# The cache is stored in $libdir/facts_dot_d.cache as a mode
|
||||
# 600 file and will have the end result of not calling your
|
||||
# fact scripts more often than is needed
|
||||
|
||||
class Facter::Util::DotD
|
||||
require 'yaml'
|
||||
|
||||
def initialize(dir="/etc/facts.d", cache_file=File.join(Puppet[:libdir], "facts_dot_d.cache"))
|
||||
@dir = dir
|
||||
@cache_file = cache_file
|
||||
@cache = nil
|
||||
@types = {".txt" => :txt, ".json" => :json, ".yaml" => :yaml}
|
||||
end
|
||||
|
||||
def entries
|
||||
Dir.entries(@dir).reject { |f| f =~ /^\.|\.ttl$/ }.sort.map { |f| File.join(@dir, f) }
|
||||
rescue
|
||||
[]
|
||||
end
|
||||
|
||||
def fact_type(file)
|
||||
extension = File.extname(file)
|
||||
|
||||
type = @types[extension] || :unknown
|
||||
|
||||
type = :script if type == :unknown && File.executable?(file)
|
||||
|
||||
return type
|
||||
end
|
||||
|
||||
def txt_parser(file)
|
||||
File.readlines(file).each do |line|
|
||||
if line =~ /^([^=]+)=(.+)$/
|
||||
var = $1; val = $2
|
||||
|
||||
Facter.add(var) do
|
||||
setcode { val }
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue StandardError => e
|
||||
Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}")
|
||||
end
|
||||
|
||||
def json_parser(file)
|
||||
begin
|
||||
require 'json'
|
||||
rescue LoadError
|
||||
retry if require 'rubygems'
|
||||
raise
|
||||
end
|
||||
|
||||
JSON.load(File.read(file)).each_pair do |f, v|
|
||||
Facter.add(f) do
|
||||
setcode { v }
|
||||
end
|
||||
end
|
||||
rescue StandardError => e
|
||||
Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}")
|
||||
end
|
||||
|
||||
def yaml_parser(file)
|
||||
require 'yaml'
|
||||
|
||||
YAML.load_file(file).each_pair do |f, v|
|
||||
Facter.add(f) do
|
||||
setcode { v }
|
||||
end
|
||||
end
|
||||
rescue StandardError => e
|
||||
Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}")
|
||||
end
|
||||
|
||||
def script_parser(file)
|
||||
result = cache_lookup(file)
|
||||
ttl = cache_time(file)
|
||||
|
||||
unless result
|
||||
result = Facter::Util::Resolution.exec(file)
|
||||
|
||||
if ttl > 0
|
||||
Facter.debug("Updating cache for #{file}")
|
||||
cache_store(file, result)
|
||||
cache_save!
|
||||
end
|
||||
else
|
||||
Facter.debug("Using cached data for #{file}")
|
||||
end
|
||||
|
||||
result.split("\n").each do |line|
|
||||
if line =~ /^(.+)=(.+)$/
|
||||
var = $1; val = $2
|
||||
|
||||
Facter.add(var) do
|
||||
setcode { val }
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue StandardError => e
|
||||
Facter.warn("Failed to handle #{file} as script facts: #{e.class}: #{e}")
|
||||
Facter.debug(e.backtrace.join("\n\t"))
|
||||
end
|
||||
|
||||
def cache_save!
|
||||
cache = load_cache
|
||||
File.open(@cache_file, "w", 0600) { |f| f.write(YAML.dump(cache)) }
|
||||
rescue
|
||||
end
|
||||
|
||||
def cache_store(file, data)
|
||||
load_cache
|
||||
|
||||
@cache[file] = {:data => data, :stored => Time.now.to_i}
|
||||
rescue
|
||||
end
|
||||
|
||||
def cache_lookup(file)
|
||||
cache = load_cache
|
||||
|
||||
return nil if cache.empty?
|
||||
|
||||
ttl = cache_time(file)
|
||||
|
||||
if cache[file]
|
||||
now = Time.now.to_i
|
||||
|
||||
return cache[file][:data] if ttl == -1
|
||||
return cache[file][:data] if (now - cache[file][:stored]) <= ttl
|
||||
return nil
|
||||
else
|
||||
return nil
|
||||
end
|
||||
rescue
|
||||
return nil
|
||||
end
|
||||
|
||||
def cache_time(file)
|
||||
meta = file + ".ttl"
|
||||
|
||||
return File.read(meta).chomp.to_i
|
||||
rescue
|
||||
return 0
|
||||
end
|
||||
|
||||
def load_cache
|
||||
unless @cache
|
||||
if File.exist?(@cache_file)
|
||||
@cache = YAML.load_file(@cache_file)
|
||||
else
|
||||
@cache = {}
|
||||
end
|
||||
end
|
||||
|
||||
return @cache
|
||||
rescue
|
||||
@cache = {}
|
||||
return @cache
|
||||
end
|
||||
|
||||
def create
|
||||
entries.each do |fact|
|
||||
type = fact_type(fact)
|
||||
parser = "#{type}_parser"
|
||||
|
||||
if respond_to?("#{type}_parser")
|
||||
Facter.debug("Parsing #{fact} using #{parser}")
|
||||
|
||||
send(parser, fact)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
mdata = Facter.version.match(/(\d+)\.(\d+)\.(\d+)/)
|
||||
if mdata
|
||||
(major, minor, patch) = mdata.captures.map { |v| v.to_i }
|
||||
if major < 2
|
||||
# Facter 1.7 introduced external facts support directly
|
||||
unless major == 1 and minor > 6
|
||||
Facter::Util::DotD.new("/etc/facter/facts.d").create
|
||||
Facter::Util::DotD.new("/etc/puppetlabs/facter/facts.d").create
|
||||
|
||||
# Windows has a different configuration directory that defaults to a vendor
|
||||
# specific sub directory of the %COMMON_APPDATA% directory.
|
||||
if Dir.const_defined? 'COMMON_APPDATA' then
|
||||
windows_facts_dot_d = File.join(Dir::COMMON_APPDATA, 'PuppetLabs', 'facter', 'facts.d')
|
||||
Facter::Util::DotD.new(windows_facts_dot_d).create
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,21 @@
|
||||
# Fact: package_provider
|
||||
#
|
||||
# Purpose: Returns the default provider Puppet will choose to manage packages
|
||||
# on this system
|
||||
#
|
||||
# Resolution: Instantiates a dummy package resource and return the provider
|
||||
#
|
||||
# Caveats:
|
||||
#
|
||||
require 'puppet/type'
|
||||
require 'puppet/type/package'
|
||||
|
||||
Facter.add(:package_provider) do
|
||||
setcode do
|
||||
if defined? Gem and Gem::Version.new(Facter.value(:puppetversion).split(' ')[0]) >= Gem::Version.new('3.6')
|
||||
Puppet::Type.type(:package).newpackage(:name => 'dummy', :allow_virtual => 'true')[:provider].to_s
|
||||
else
|
||||
Puppet::Type.type(:package).newpackage(:name => 'dummy')[:provider].to_s
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,58 @@
|
||||
# Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version
|
||||
#
|
||||
# Purpose: Return various facts about the PE state of the system
|
||||
#
|
||||
# Resolution: Uses a regex match against puppetversion to determine whether the
|
||||
# machine has Puppet Enterprise installed, and what version (overall, major,
|
||||
# minor, patch) is installed.
|
||||
#
|
||||
# Caveats:
|
||||
#
|
||||
Facter.add("pe_version") do
|
||||
setcode do
|
||||
puppet_ver = Facter.value("puppetversion")
|
||||
if puppet_ver != nil
|
||||
pe_ver = puppet_ver.match(/Puppet Enterprise (\d+\.\d+\.\d+)/)
|
||||
pe_ver[1] if pe_ver
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Facter.add("is_pe") do
|
||||
setcode do
|
||||
if Facter.value(:pe_version).to_s.empty? then
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Facter.add("pe_major_version") do
|
||||
confine :is_pe => true
|
||||
setcode do
|
||||
if pe_version = Facter.value(:pe_version)
|
||||
pe_version.to_s.split('.')[0]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Facter.add("pe_minor_version") do
|
||||
confine :is_pe => true
|
||||
setcode do
|
||||
if pe_version = Facter.value(:pe_version)
|
||||
pe_version.to_s.split('.')[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Facter.add("pe_patch_version") do
|
||||
confine :is_pe => true
|
||||
setcode do
|
||||
if pe_version = Facter.value(:pe_version)
|
||||
pe_version.to_s.split('.')[2]
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,26 @@
|
||||
# This facter fact returns the value of the Puppet vardir setting for the node
|
||||
# running puppet or puppet agent. The intent is to enable Puppet modules to
|
||||
# automatically have insight into a place where they can place variable data,
|
||||
# regardless of the node's platform.
|
||||
#
|
||||
# The value should be directly usable in a File resource path attribute.
|
||||
|
||||
|
||||
begin
|
||||
require 'facter/util/puppet_settings'
|
||||
rescue LoadError => e
|
||||
# puppet apply does not add module lib directories to the $LOAD_PATH (See
|
||||
# #4248). It should (in the future) but for the time being we need to be
|
||||
# defensive which is what this rescue block is doing.
|
||||
rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
|
||||
load rb_file if File.exists?(rb_file) or raise e
|
||||
end
|
||||
|
||||
Facter.add(:puppet_vardir) do
|
||||
setcode do
|
||||
# This will be nil if Puppet is not available.
|
||||
Facter::Util::PuppetSettings.with_puppet do
|
||||
Puppet[:vardir]
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,45 @@
|
||||
# A facter fact to determine the root home directory.
|
||||
# This varies on PE supported platforms and may be
|
||||
# reconfigured by the end user.
|
||||
|
||||
module Facter::Util::RootHome
|
||||
class << self
|
||||
def get_root_home
|
||||
root_ent = Facter::Util::Resolution.exec("getent passwd root")
|
||||
# The home directory is the sixth element in the passwd entry
|
||||
# If the platform doesn't have getent, root_ent will be nil and we should
|
||||
# return it straight away.
|
||||
root_ent && root_ent.split(":")[5]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Facter.add(:root_home) do
|
||||
setcode { Facter::Util::RootHome.get_root_home }
|
||||
end
|
||||
|
||||
Facter.add(:root_home) do
|
||||
confine :kernel => :darwin
|
||||
setcode do
|
||||
str = Facter::Util::Resolution.exec("dscacheutil -q user -a name root")
|
||||
hash = {}
|
||||
str.split("\n").each do |pair|
|
||||
key,value = pair.split(/:/)
|
||||
hash[key] = value
|
||||
end
|
||||
hash['dir'].strip
|
||||
end
|
||||
end
|
||||
|
||||
Facter.add(:root_home) do
|
||||
confine :kernel => :aix
|
||||
root_home = nil
|
||||
setcode do
|
||||
str = Facter::Util::Resolution.exec("lsuser -c -a home root")
|
||||
str && str.split("\n").each do |line|
|
||||
next if line =~ /^#/
|
||||
root_home = line.split(/:/)[1]
|
||||
end
|
||||
root_home
|
||||
end
|
||||
end
|
@ -0,0 +1,17 @@
|
||||
# Fact: service_provider
|
||||
#
|
||||
# Purpose: Returns the default provider Puppet will choose to manage services
|
||||
# on this system
|
||||
#
|
||||
# Resolution: Instantiates a dummy service resource and return the provider
|
||||
#
|
||||
# Caveats:
|
||||
#
|
||||
require 'puppet/type'
|
||||
require 'puppet/type/service'
|
||||
|
||||
Facter.add(:service_provider) do
|
||||
setcode do
|
||||
Puppet::Type.type(:service).newservice(:name => 'dummy')[:provider].to_s
|
||||
end
|
||||
end
|
@ -0,0 +1,21 @@
|
||||
module Facter
|
||||
module Util
|
||||
module PuppetSettings
|
||||
# This method is intended to provide a convenient way to evaluate a
|
||||
# Facter code block only if Puppet is loaded. This is to account for the
|
||||
# situation where the fact happens to be in the load path, but Puppet is
|
||||
# not loaded for whatever reason. Perhaps the user is simply running
|
||||
# facter without the --puppet flag and they happen to be working in a lib
|
||||
# directory of a module.
|
||||
def self.with_puppet
|
||||
begin
|
||||
Module.const_get("Puppet")
|
||||
rescue NameError
|
||||
nil
|
||||
else
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,32 @@
|
||||
# Boolean check to determine whether a variable is of a given data type. This is equivalent to the `=~` type checks.
|
||||
#
|
||||
# @example how to check a data type
|
||||
# # check a data type
|
||||
# foo = 3
|
||||
# $bar = [1,2,3]
|
||||
# $baz = 'A string!'
|
||||
#
|
||||
# if $foo.is_a(Integer) {
|
||||
# notify { 'foo!': }
|
||||
# }
|
||||
# if $bar.is_a(Array) {
|
||||
# notify { 'bar!': }
|
||||
# }
|
||||
# if $baz.is_a(String) {
|
||||
# notify { 'baz!': }
|
||||
# }
|
||||
#
|
||||
# See the documentation for "The Puppet Type System" for more information about types.
|
||||
# See the `assert_type()` function for flexible ways to assert the type of a value.
|
||||
#
|
||||
Puppet::Functions.create_function(:is_a) do
|
||||
dispatch :is_a do
|
||||
param 'Any', :value
|
||||
param 'Type', :type
|
||||
end
|
||||
|
||||
def is_a(value, type)
|
||||
# See puppet's lib/puppet/pops/evaluator/evaluator_impl.rb eval_MatchExpression
|
||||
Puppet::Pops::Types::TypeCalculator.instance?(type, value)
|
||||
end
|
||||
end
|
@ -0,0 +1,17 @@
|
||||
# Returns the type when passed a value.
|
||||
#
|
||||
# @example how to compare values' types
|
||||
# # compare the types of two values
|
||||
# if type_of($first_value) != type_of($second_value) { fail("first_value and second_value are different types") }
|
||||
# @example how to compare against an abstract type
|
||||
# unless type_of($first_value) <= Numeric { fail("first_value must be Numeric") }
|
||||
# unless type_of{$first_value) <= Collection[1] { fail("first_value must be an Array or Hash, and contain at least one element") }
|
||||
#
|
||||
# See the documentation for "The Puppet Type System" for more information about types.
|
||||
# See the `assert_type()` function for flexible ways to assert the type of a value.
|
||||
#
|
||||
Puppet::Functions.create_function(:type_of) do
|
||||
def type_of(value)
|
||||
Puppet::Pops::Types::TypeCalculator.infer_set(value)
|
||||
end
|
||||
end
|
@ -0,0 +1,36 @@
|
||||
#
|
||||
# abs.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:abs, :type => :rvalue, :doc => <<-EOS
|
||||
Returns the absolute value of a number, for example -34.56 becomes
|
||||
34.56. Takes a single integer and float value as an argument.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "abs(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
value = arguments[0]
|
||||
|
||||
# Numbers in Puppet are often string-encoded which is troublesome ...
|
||||
if value.is_a?(String)
|
||||
if value.match(/^-?(?:\d+)(?:\.\d+){1}$/)
|
||||
value = value.to_f
|
||||
elsif value.match(/^-?\d+$/)
|
||||
value = value.to_i
|
||||
else
|
||||
raise(Puppet::ParseError, 'abs(): Requires float or ' +
|
||||
'integer to work with')
|
||||
end
|
||||
end
|
||||
|
||||
# We have numeric value to handle ...
|
||||
result = value.abs
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,33 @@
|
||||
#
|
||||
# any2array.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:any2array, :type => :rvalue, :doc => <<-EOS
|
||||
This converts any object to an array containing that object. Empty argument
|
||||
lists are converted to an empty array. Arrays are left untouched. Hashes are
|
||||
converted to arrays of alternating keys and values.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if arguments.empty?
|
||||
return []
|
||||
end
|
||||
|
||||
if arguments.length == 1
|
||||
if arguments[0].kind_of?(Array)
|
||||
return arguments[0]
|
||||
elsif arguments[0].kind_of?(Hash)
|
||||
result = []
|
||||
arguments[0].each do |key, value|
|
||||
result << key << value
|
||||
end
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
return arguments
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,55 @@
|
||||
#
|
||||
# any2bool.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:any2bool, :type => :rvalue, :doc => <<-EOS
|
||||
This converts 'anything' to a boolean. In practise it does the following:
|
||||
|
||||
* Strings such as Y,y,1,T,t,TRUE,yes,'true' will return true
|
||||
* Strings such as 0,F,f,N,n,FALSE,no,'false' will return false
|
||||
* Booleans will just return their original value
|
||||
* Number (or a string representation of a number) > 0 will return true, otherwise false
|
||||
* undef will return false
|
||||
* Anything else will return true
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "any2bool(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
# If argument is already Boolean, return it
|
||||
if !!arguments[0] == arguments[0]
|
||||
return arguments[0]
|
||||
end
|
||||
|
||||
arg = arguments[0]
|
||||
|
||||
if arg == nil
|
||||
return false
|
||||
end
|
||||
|
||||
if arg == :undef
|
||||
return false
|
||||
end
|
||||
|
||||
valid_float = !!Float(arg) rescue false
|
||||
|
||||
if arg.is_a?(Numeric)
|
||||
return function_num2bool( [ arguments[0] ] )
|
||||
end
|
||||
|
||||
if arg.is_a?(String)
|
||||
if valid_float
|
||||
return function_num2bool( [ arguments[0] ] )
|
||||
else
|
||||
return function_str2bool( [ arguments[0] ] )
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,29 @@
|
||||
#
|
||||
# assert_private.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:assert_private, :doc => <<-'EOS'
|
||||
Sets the current class or definition as private.
|
||||
Calling the class or definition from outside the current module will fail.
|
||||
EOS
|
||||
) do |args|
|
||||
|
||||
raise(Puppet::ParseError, "assert_private(): Wrong number of arguments "+
|
||||
"given (#{args.size}}) for 0 or 1)") if args.size > 1
|
||||
|
||||
scope = self
|
||||
if scope.lookupvar('module_name') != scope.lookupvar('caller_module_name')
|
||||
message = nil
|
||||
if args[0] and args[0].is_a? String
|
||||
message = args[0]
|
||||
else
|
||||
manifest_name = scope.source.name
|
||||
manifest_type = scope.source.type
|
||||
message = (manifest_type.to_s == 'hostclass') ? 'Class' : 'Definition'
|
||||
message += " #{manifest_name} is private"
|
||||
end
|
||||
raise(Puppet::ParseError, message)
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,68 @@
|
||||
module Puppet::Parser::Functions
|
||||
|
||||
newfunction(:base64, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
|
||||
|
||||
Base64 encode or decode a string based on the command and the string submitted
|
||||
|
||||
Usage:
|
||||
|
||||
$encodestring = base64('encode', 'thestring')
|
||||
$decodestring = base64('decode', 'dGhlc3RyaW5n')
|
||||
|
||||
# explicitly define encode/decode method: default, strict, urlsafe
|
||||
$method = 'default'
|
||||
$encodestring = base64('encode', 'thestring', $method)
|
||||
$decodestring = base64('decode', 'dGhlc3RyaW5n', $method)
|
||||
|
||||
ENDHEREDOC
|
||||
|
||||
require 'base64'
|
||||
|
||||
raise Puppet::ParseError, ("base64(): Wrong number of arguments (#{args.length}; must be >= 2)") unless args.length >= 2
|
||||
|
||||
actions = ['encode','decode']
|
||||
|
||||
unless actions.include?(args[0])
|
||||
raise Puppet::ParseError, ("base64(): the first argument must be one of 'encode' or 'decode'")
|
||||
end
|
||||
|
||||
unless args[1].is_a?(String)
|
||||
raise Puppet::ParseError, ("base64(): the second argument must be a string to base64")
|
||||
end
|
||||
|
||||
method = ['default','strict','urlsafe']
|
||||
|
||||
if args.length <= 2
|
||||
chosenMethod = 'default'
|
||||
else
|
||||
chosenMethod = args[2]
|
||||
end
|
||||
|
||||
unless method.include?(chosenMethod)
|
||||
raise Puppet::ParseError, ("base64(): the third argument must be one of 'default', 'strict', or 'urlsafe'")
|
||||
end
|
||||
|
||||
case args[0]
|
||||
when 'encode'
|
||||
case chosenMethod
|
||||
when 'default'
|
||||
result = Base64.encode64(args[1])
|
||||
when 'strict'
|
||||
result = Base64.strict_encode64(args[1])
|
||||
when 'urlsafe'
|
||||
result = Base64.urlsafe_encode64(args[1])
|
||||
end
|
||||
when 'decode'
|
||||
case chosenMethod
|
||||
when 'default'
|
||||
result = Base64.decode64(args[1])
|
||||
when 'strict'
|
||||
result = Base64.strict_decode64(args[1])
|
||||
when 'urlsafe'
|
||||
result = Base64.urlsafe_decode64(args[1])
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
@ -0,0 +1,34 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:basename, :type => :rvalue, :doc => <<-EOS
|
||||
Strips directory (and optional suffix) from a filename
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if arguments.size < 1 then
|
||||
raise(Puppet::ParseError, "basename(): No arguments given")
|
||||
elsif arguments.size > 2 then
|
||||
raise(Puppet::ParseError, "basename(): Too many arguments given (#{arguments.size})")
|
||||
else
|
||||
|
||||
unless arguments[0].is_a?(String)
|
||||
raise(Puppet::ParseError, 'basename(): Requires string as first argument')
|
||||
end
|
||||
|
||||
if arguments.size == 1 then
|
||||
rv = File.basename(arguments[0])
|
||||
elsif arguments.size == 2 then
|
||||
|
||||
unless arguments[1].is_a?(String)
|
||||
raise(Puppet::ParseError, 'basename(): Requires string as second argument')
|
||||
end
|
||||
|
||||
rv = File.basename(arguments[0], arguments[1])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return rv
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,26 @@
|
||||
#
|
||||
# bool2num.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS
|
||||
Converts a boolean to a number. Converts the values:
|
||||
false, f, 0, n, and no to 0
|
||||
true, t, 1, y, and yes to 1
|
||||
Requires a single boolean or string as an input.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
value = function_str2bool([arguments[0]])
|
||||
|
||||
# We have real boolean values as well ...
|
||||
result = value ? 1 : 0
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,45 @@
|
||||
#
|
||||
# bool2str.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:bool2str, :type => :rvalue, :doc => <<-EOS
|
||||
Converts a boolean to a string using optionally supplied arguments. The
|
||||
optional second and third arguments represent what true and false will be
|
||||
converted to respectively. If only one argument is given, it will be
|
||||
converted from a boolean to a string containing 'true' or 'false'.
|
||||
|
||||
*Examples:*
|
||||
|
||||
bool2str(true) => 'true'
|
||||
bool2str(true, 'yes', 'no') => 'yes'
|
||||
bool2str(false, 't', 'f') => 'f'
|
||||
|
||||
Requires a single boolean as an input.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
unless arguments.size == 1 or arguments.size == 3
|
||||
raise(Puppet::ParseError, "bool2str(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 3)")
|
||||
end
|
||||
|
||||
value = arguments[0]
|
||||
true_string = arguments[1] || 'true'
|
||||
false_string = arguments[2] || 'false'
|
||||
klass = value.class
|
||||
|
||||
# We can have either true or false, and nothing else
|
||||
unless [FalseClass, TrueClass].include?(klass)
|
||||
raise(Puppet::ParseError, 'bool2str(): Requires a boolean to work with')
|
||||
end
|
||||
|
||||
unless [true_string, false_string].all?{|x| x.kind_of?(String)}
|
||||
raise(Puppet::ParseError, "bool2str(): Requires strings to convert to" )
|
||||
end
|
||||
|
||||
return value ? true_string : false_string
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,33 @@
|
||||
#
|
||||
# camelcase.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:camelcase, :type => :rvalue, :doc => <<-EOS
|
||||
Converts the case of a string or all strings in an array to camel case.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "camelcase(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
value = arguments[0]
|
||||
klass = value.class
|
||||
|
||||
unless [Array, String].include?(klass)
|
||||
raise(Puppet::ParseError, 'camelcase(): Requires either ' +
|
||||
'array or string to work with')
|
||||
end
|
||||
|
||||
if value.is_a?(Array)
|
||||
# Numbers in Puppet are often string-encoded which is troublesome ...
|
||||
result = value.collect { |i| i.is_a?(String) ? i.split('_').map{|e| e.capitalize}.join : i }
|
||||
else
|
||||
result = value.split('_').map{|e| e.capitalize}.join
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,33 @@
|
||||
#
|
||||
# capitalize.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS
|
||||
Capitalizes the first letter of a string or array of strings.
|
||||
Requires either a single string or an array as an input.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
value = arguments[0]
|
||||
|
||||
unless value.is_a?(Array) || value.is_a?(String)
|
||||
raise(Puppet::ParseError, 'capitalize(): Requires either ' +
|
||||
'array or string to work with')
|
||||
end
|
||||
|
||||
if value.is_a?(Array)
|
||||
# Numbers in Puppet are often string-encoded which is troublesome ...
|
||||
result = value.collect { |i| i.is_a?(String) ? i.capitalize : i }
|
||||
else
|
||||
result = value.capitalize
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,25 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:ceiling, :type => :rvalue, :doc => <<-EOS
|
||||
Returns the smallest integer greater or equal to the argument.
|
||||
Takes a single numeric value as an argument.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "ceiling(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size != 1
|
||||
|
||||
begin
|
||||
arg = Float(arguments[0])
|
||||
rescue TypeError, ArgumentError => e
|
||||
raise(Puppet::ParseError, "ceiling(): Wrong argument type " +
|
||||
"given (#{arguments[0]} for Numeric)")
|
||||
end
|
||||
|
||||
raise(Puppet::ParseError, "ceiling(): Wrong argument type " +
|
||||
"given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
|
||||
|
||||
arg.ceil
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,34 @@
|
||||
#
|
||||
# chomp.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS'
|
||||
Removes the record separator from the end of a string or an array of
|
||||
strings, for example `hello\n` becomes `hello`.
|
||||
Requires a single string or array as an input.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "chomp(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
value = arguments[0]
|
||||
|
||||
unless value.is_a?(Array) || value.is_a?(String)
|
||||
raise(Puppet::ParseError, 'chomp(): Requires either ' +
|
||||
'array or string to work with')
|
||||
end
|
||||
|
||||
if value.is_a?(Array)
|
||||
# Numbers in Puppet are often string-encoded which is troublesome ...
|
||||
result = value.collect { |i| i.is_a?(String) ? i.chomp : i }
|
||||
else
|
||||
result = value.chomp
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,36 @@
|
||||
#
|
||||
# chop.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:chop, :type => :rvalue, :doc => <<-'EOS'
|
||||
Returns a new string with the last character removed. If the string ends
|
||||
with `\r\n`, both characters are removed. Applying chop to an empty
|
||||
string returns an empty string. If you wish to merely remove record
|
||||
separators then you should use the `chomp` function.
|
||||
Requires a string or array of strings as input.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "chop(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
value = arguments[0]
|
||||
|
||||
unless value.is_a?(Array) || value.is_a?(String)
|
||||
raise(Puppet::ParseError, 'chop(): Requires either an ' +
|
||||
'array or string to work with')
|
||||
end
|
||||
|
||||
if value.is_a?(Array)
|
||||
# Numbers in Puppet are often string-encoded which is troublesome ...
|
||||
result = value.collect { |i| i.is_a?(String) ? i.chop : i }
|
||||
else
|
||||
result = value.chop
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,30 @@
|
||||
#
|
||||
# clamp.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:clamp, :type => :rvalue, :arity => -2, :doc => <<-EOS
|
||||
Clamps value to a range.
|
||||
EOS
|
||||
) do |args|
|
||||
|
||||
args.flatten!
|
||||
|
||||
raise(Puppet::ParseError, 'clamp(): Wrong number of arguments, ' +
|
||||
'need three to clamp') if args.size != 3
|
||||
|
||||
# check values out
|
||||
args.each do |value|
|
||||
case [value.class]
|
||||
when [String]
|
||||
raise(Puppet::ParseError, "clamp(): Required explicit numeric (#{value}:String)") unless value =~ /^\d+$/
|
||||
when [Hash]
|
||||
raise(Puppet::ParseError, "clamp(): The Hash type is not allowed (#{value})")
|
||||
end
|
||||
end
|
||||
|
||||
# convert to numeric each element
|
||||
# then sort them and get a middle value
|
||||
args.map{ |n| n.to_i }.sort[1]
|
||||
end
|
||||
end
|
@ -0,0 +1,41 @@
|
||||
#
|
||||
# concat.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:concat, :type => :rvalue, :doc => <<-EOS
|
||||
Appends the contents of multiple arrays into array 1.
|
||||
|
||||
*Example:*
|
||||
|
||||
concat(['1','2','3'],['4','5','6'],['7','8','9'])
|
||||
|
||||
Would result in:
|
||||
|
||||
['1','2','3','4','5','6','7','8','9']
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
# Check that more than 2 arguments have been given ...
|
||||
raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for < 2)") if arguments.size < 2
|
||||
|
||||
a = arguments[0]
|
||||
|
||||
# Check that the first parameter is an array
|
||||
unless a.is_a?(Array)
|
||||
raise(Puppet::ParseError, 'concat(): Requires array to work with')
|
||||
end
|
||||
|
||||
result = a
|
||||
arguments.shift
|
||||
|
||||
arguments.each do |x|
|
||||
result = result + (x.is_a?(Array) ? x : [x])
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,35 @@
|
||||
module Puppet::Parser::Functions
|
||||
|
||||
newfunction(:convert_base, :type => :rvalue, :arity => 2, :doc => <<-'ENDHEREDOC') do |args|
|
||||
|
||||
Converts a given integer or base 10 string representing an integer to a specified base, as a string.
|
||||
|
||||
Usage:
|
||||
|
||||
$binary_repr = convert_base(5, 2) # $binary_repr is now set to "101"
|
||||
$hex_repr = convert_base("254", "16") # $hex_repr is now set to "fe"
|
||||
|
||||
ENDHEREDOC
|
||||
|
||||
raise Puppet::ParseError, ("convert_base(): First argument must be either a string or an integer") unless (args[0].is_a?(Integer) or args[0].is_a?(String))
|
||||
raise Puppet::ParseError, ("convert_base(): Second argument must be either a string or an integer") unless (args[1].is_a?(Integer) or args[1].is_a?(String))
|
||||
|
||||
if args[0].is_a?(String)
|
||||
raise Puppet::ParseError, ("convert_base(): First argument must be an integer or a string corresponding to an integer in base 10") unless args[0] =~ /^[0-9]+$/
|
||||
end
|
||||
|
||||
if args[1].is_a?(String)
|
||||
raise Puppet::ParseError, ("convert_base(): First argument must be an integer or a string corresponding to an integer in base 10") unless args[1] =~ /^[0-9]+$/
|
||||
end
|
||||
|
||||
number_to_convert = args[0]
|
||||
new_base = args[1]
|
||||
|
||||
number_to_convert = number_to_convert.to_i()
|
||||
new_base = new_base.to_i()
|
||||
|
||||
raise Puppet::ParseError, ("convert_base(): base must be at least 2 and must not be greater than 36") unless new_base >= 2 and new_base <= 36
|
||||
|
||||
return number_to_convert.to_s(new_base)
|
||||
end
|
||||
end
|
@ -0,0 +1,22 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-EOS
|
||||
Takes an array as first argument and an optional second argument.
|
||||
Count the number of elements in array that matches second argument.
|
||||
If called with only an array it counts the number of elements that are not nil/undef.
|
||||
EOS
|
||||
) do |args|
|
||||
|
||||
if (args.size > 2) then
|
||||
raise(ArgumentError, "count(): Wrong number of arguments "+
|
||||
"given #{args.size} for 1 or 2.")
|
||||
end
|
||||
|
||||
collection, item = args
|
||||
|
||||
if item then
|
||||
collection.count item
|
||||
else
|
||||
collection.count { |obj| obj != nil && obj != :undef && obj != '' }
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,44 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:deep_merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
|
||||
Recursively merges two or more hashes together and returns the resulting hash.
|
||||
|
||||
For example:
|
||||
|
||||
$hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }
|
||||
$hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } }
|
||||
$merged_hash = deep_merge($hash1, $hash2)
|
||||
# The resulting hash is equivalent to:
|
||||
# $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } }
|
||||
|
||||
When there is a duplicate key that is a hash, they are recursively merged.
|
||||
When there is a duplicate key that is not a hash, the key in the rightmost hash will "win."
|
||||
|
||||
ENDHEREDOC
|
||||
|
||||
if args.length < 2
|
||||
raise Puppet::ParseError, ("deep_merge(): wrong number of arguments (#{args.length}; must be at least 2)")
|
||||
end
|
||||
|
||||
deep_merge = Proc.new do |hash1,hash2|
|
||||
hash1.merge(hash2) do |key,old_value,new_value|
|
||||
if old_value.is_a?(Hash) && new_value.is_a?(Hash)
|
||||
deep_merge.call(old_value, new_value)
|
||||
else
|
||||
new_value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
result = Hash.new
|
||||
args.each do |arg|
|
||||
next if arg.is_a? String and arg.empty? # empty string is synonym for puppet's undef
|
||||
# If the argument was not a hash, skip it.
|
||||
unless arg.is_a?(Hash)
|
||||
raise Puppet::ParseError, "deep_merge: unexpected argument type #{arg.class}, only expects hash arguments"
|
||||
end
|
||||
|
||||
result = deep_merge.call(result, arg)
|
||||
end
|
||||
return( result )
|
||||
end
|
||||
end
|
@ -0,0 +1,38 @@
|
||||
# Test whether a given class or definition is defined
|
||||
require 'puppet/parser/functions'
|
||||
|
||||
Puppet::Parser::Functions.newfunction(:defined_with_params,
|
||||
:type => :rvalue,
|
||||
:doc => <<-'ENDOFDOC'
|
||||
Takes a resource reference and an optional hash of attributes.
|
||||
|
||||
Returns true if a resource with the specified attributes has already been added
|
||||
to the catalog, and false otherwise.
|
||||
|
||||
user { 'dan':
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
if ! defined_with_params(User[dan], {'ensure' => 'present' }) {
|
||||
user { 'dan': ensure => present, }
|
||||
}
|
||||
ENDOFDOC
|
||||
) do |vals|
|
||||
reference, params = vals
|
||||
raise(ArgumentError, 'Must specify a reference') unless reference
|
||||
if (! params) || params == ''
|
||||
params = {}
|
||||
end
|
||||
ret = false
|
||||
if resource = findresource(reference.to_s)
|
||||
matches = params.collect do |key, value|
|
||||
# eql? avoids bugs caused by monkeypatching in puppet
|
||||
resource_is_undef = resource[key].eql?(:undef) || resource[key].nil?
|
||||
value_is_undef = value.eql?(:undef) || value.nil?
|
||||
(resource_is_undef && value_is_undef) || (resource[key] == value)
|
||||
end
|
||||
ret = params.empty? || !matches.include?(false)
|
||||
end
|
||||
Puppet.debug("Resource #{reference} was not determined to be defined")
|
||||
ret
|
||||
end
|
@ -0,0 +1,45 @@
|
||||
#
|
||||
# delete.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
|
||||
Deletes all instances of a given element from an array, substring from a
|
||||
string, or key from a hash.
|
||||
|
||||
*Examples:*
|
||||
|
||||
delete(['a','b','c','b'], 'b')
|
||||
Would return: ['a','c']
|
||||
|
||||
delete({'a'=>1,'b'=>2,'c'=>3}, 'b')
|
||||
Would return: {'a'=>1,'c'=>3}
|
||||
|
||||
delete({'a'=>1,'b'=>2,'c'=>3}, ['b','c'])
|
||||
Would return: {'a'=>1}
|
||||
|
||||
delete('abracadabra', 'bra')
|
||||
Would return: 'acada'
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
|
||||
"given #{arguments.size} for 2") unless arguments.size == 2
|
||||
|
||||
collection = arguments[0].dup
|
||||
Array(arguments[1]).each do |item|
|
||||
case collection
|
||||
when Array, Hash
|
||||
collection.delete item
|
||||
when String
|
||||
collection.gsub! item, ''
|
||||
else
|
||||
raise(TypeError, "delete(): First argument must be an Array, " +
|
||||
"String, or Hash. Given an argument of class #{collection.class}.")
|
||||
end
|
||||
end
|
||||
collection
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,49 @@
|
||||
#
|
||||
# delete_at.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
|
||||
Deletes a determined indexed value from an array.
|
||||
|
||||
*Examples:*
|
||||
|
||||
delete_at(['a','b','c'], 1)
|
||||
|
||||
Would return: ['a','c']
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 2)") if arguments.size < 2
|
||||
|
||||
array = arguments[0]
|
||||
|
||||
unless array.is_a?(Array)
|
||||
raise(Puppet::ParseError, 'delete_at(): Requires array to work with')
|
||||
end
|
||||
|
||||
index = arguments[1]
|
||||
|
||||
if index.is_a?(String) and not index.match(/^\d+$/)
|
||||
raise(Puppet::ParseError, 'delete_at(): You must provide ' +
|
||||
'non-negative numeric index')
|
||||
end
|
||||
|
||||
result = array.clone
|
||||
|
||||
# Numbers in Puppet are often string-encoded which is troublesome ...
|
||||
index = index.to_i
|
||||
|
||||
if index > result.size - 1 # First element is at index 0 is it not?
|
||||
raise(Puppet::ParseError, 'delete_at(): Given index ' +
|
||||
'exceeds size of array given')
|
||||
end
|
||||
|
||||
result.delete_at(index) # We ignore the element that got deleted ...
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,45 @@
|
||||
#
|
||||
# delete_regex.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:delete_regex, :type => :rvalue, :doc => <<-EOS
|
||||
deletes all instances of a given element that match a regular expression
|
||||
from an array or key from a hash. Multiple regular expressions are assumed
|
||||
to be matched as an OR.
|
||||
|
||||
*Examples:*
|
||||
|
||||
delete_regex(['a','b','c','b'], 'b')
|
||||
Would return: ['a','c']
|
||||
|
||||
delete_regex(['a','b','c','b'], ['b', 'c'])
|
||||
Would return: ['a']
|
||||
|
||||
delete_regex({'a'=>1,'b'=>2,'c'=>3}, 'b')
|
||||
Would return: {'a'=>1,'c'=>3}
|
||||
|
||||
delete_regex({'a'=>1,'b'=>2,'c'=>3}, '^a$')
|
||||
Would return: {'b'=>2,'c'=>3}
|
||||
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "delete_regex(): Wrong number of arguments "+
|
||||
"given #{arguments.size} for 2") unless arguments.size == 2
|
||||
|
||||
collection = arguments[0].dup
|
||||
Array(arguments[1]).each do |item|
|
||||
case collection
|
||||
when Array, Hash, String
|
||||
collection.reject! { |coll_item| (coll_item =~ %r{\b#{item}\b}) }
|
||||
else
|
||||
raise(TypeError, "delete_regex(): First argument must be an Array, " +
|
||||
"Hash, or String. Given an argument of class #{collection.class}.")
|
||||
end
|
||||
end
|
||||
collection
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,34 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:delete_undef_values, :type => :rvalue, :doc => <<-EOS
|
||||
Returns a copy of input hash or array with all undefs deleted.
|
||||
|
||||
*Examples:*
|
||||
|
||||
$hash = delete_undef_values({a=>'A', b=>'', c=>undef, d => false})
|
||||
|
||||
Would return: {a => 'A', b => '', d => false}
|
||||
|
||||
$array = delete_undef_values(['A','',undef,false])
|
||||
|
||||
Would return: ['A','',false]
|
||||
|
||||
EOS
|
||||
) do |args|
|
||||
|
||||
raise(Puppet::ParseError,
|
||||
"delete_undef_values(): Wrong number of arguments given " +
|
||||
"(#{args.size})") if args.size < 1
|
||||
|
||||
unless args[0].is_a? Array or args[0].is_a? Hash
|
||||
raise(Puppet::ParseError,
|
||||
"delete_undef_values(): expected an array or hash, got #{args[0]} type #{args[0].class} ")
|
||||
end
|
||||
result = args[0].dup
|
||||
if result.is_a?(Hash)
|
||||
result.delete_if {|key, val| val.equal? :undef}
|
||||
elsif result.is_a?(Array)
|
||||
result.delete :undef
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
@ -0,0 +1,26 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:delete_values, :type => :rvalue, :doc => <<-EOS
|
||||
Deletes all instances of a given value from a hash.
|
||||
|
||||
*Examples:*
|
||||
|
||||
delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B')
|
||||
|
||||
Would return: {'a'=>'A','c'=>'C','B'=>'D'}
|
||||
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError,
|
||||
"delete_values(): Wrong number of arguments given " +
|
||||
"(#{arguments.size} of 2)") if arguments.size != 2
|
||||
|
||||
hash, item = arguments
|
||||
|
||||
if not hash.is_a?(Hash)
|
||||
raise(TypeError, "delete_values(): First argument must be a Hash. " + \
|
||||
"Given an argument of class #{hash.class}.")
|
||||
end
|
||||
hash.dup.delete_if { |key, val| item == val }
|
||||
end
|
||||
end
|
@ -0,0 +1,36 @@
|
||||
#
|
||||
# difference.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:difference, :type => :rvalue, :doc => <<-EOS
|
||||
This function returns the difference between two arrays.
|
||||
The returned array is a copy of the original array, removing any items that
|
||||
also appear in the second array.
|
||||
|
||||
*Examples:*
|
||||
|
||||
difference(["a","b","c"],["b","c","d"])
|
||||
|
||||
Would return: ["a"]
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
# Two arguments are required
|
||||
raise(Puppet::ParseError, "difference(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 2)") if arguments.size != 2
|
||||
|
||||
first = arguments[0]
|
||||
second = arguments[1]
|
||||
|
||||
unless first.is_a?(Array) && second.is_a?(Array)
|
||||
raise(Puppet::ParseError, 'difference(): Requires 2 arrays')
|
||||
end
|
||||
|
||||
result = first - second
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,16 @@
|
||||
#
|
||||
# dig.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:dig, :type => :rvalue, :doc => <<-EOS
|
||||
DEPRECATED: This function has been replaced in Puppet 4.5.0, please use dig44() for backwards compatibility or use the new version.
|
||||
EOS
|
||||
) do |arguments|
|
||||
warning("dig() DEPRECATED: This function has been replaced in Puppet 4.5.0, please use dig44() for backwards compatibility or use the new version.")
|
||||
if ! Puppet::Parser::Functions.autoloader.loaded?(:dig44)
|
||||
Puppet::Parser::Functions.autoloader.load(:dig44)
|
||||
end
|
||||
function_dig44(arguments)
|
||||
end
|
||||
end
|
@ -0,0 +1,56 @@
|
||||
#
|
||||
# dig44.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:dig44, :type => :rvalue, :doc => <<-EOS
|
||||
DEPRECATED: This function has been replaced in puppet 4.5.0.
|
||||
|
||||
Looks up into a complex structure of arrays and hashes and returns nil
|
||||
or the default value if nothing was found.
|
||||
|
||||
Path is an array of keys to be looked up in data argument. The function
|
||||
will go down the structure and try to extract the required value.
|
||||
|
||||
$data = {
|
||||
'a' => {
|
||||
'b' => [
|
||||
'b1',
|
||||
'b2',
|
||||
'b3' ]}}
|
||||
|
||||
$value = dig44($data, ['a', 'b', '2'], 'not_found')
|
||||
=> $value = 'b3'
|
||||
|
||||
a -> first hash key
|
||||
b -> second hash key
|
||||
2 -> array index starting with 0
|
||||
|
||||
not_found -> (optional) will be returned if there is no value or the path
|
||||
did not match. Defaults to nil.
|
||||
|
||||
In addition to the required "path" argument, "dig44" accepts default
|
||||
argument. It will be returned if no value was found or a path component is
|
||||
missing. And the fourth argument can set a variable path separator.
|
||||
EOS
|
||||
) do |arguments|
|
||||
# Two arguments are required
|
||||
raise(Puppet::ParseError, "dig44(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for at least 2)") if arguments.size < 2
|
||||
|
||||
data, path, default = *arguments
|
||||
|
||||
if !(data.is_a?(Hash) || data.is_a?(Array))
|
||||
raise(Puppet::ParseError, "dig44(): first argument must be a hash or an array, " <<
|
||||
"given #{data.class.name}")
|
||||
end
|
||||
|
||||
unless path.is_a? Array
|
||||
raise(Puppet::ParseError, "dig44(): second argument must be an array, " <<
|
||||
"given #{path.class.name}")
|
||||
end
|
||||
|
||||
value = path.reduce(data) { |h, k| (h.is_a?(Hash) || h.is_a?(Array)) ? h[k] : break }
|
||||
value.nil? ? default : value
|
||||
end
|
||||
end
|
@ -0,0 +1,21 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:dirname, :type => :rvalue, :doc => <<-EOS
|
||||
Returns the dirname of a path.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if arguments.size < 1 then
|
||||
raise(Puppet::ParseError, "dirname(): No arguments given")
|
||||
end
|
||||
if arguments.size > 1 then
|
||||
raise(Puppet::ParseError, "dirname(): Too many arguments given (#{arguments.size})")
|
||||
end
|
||||
unless arguments[0].is_a?(String)
|
||||
raise(Puppet::ParseError, 'dirname(): Requires string as argument')
|
||||
end
|
||||
|
||||
return File.dirname(arguments[0])
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,15 @@
|
||||
# Custom Puppet function to convert dos to unix format
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:dos2unix, :type => :rvalue, :arity => 1, :doc => <<-EOS
|
||||
Returns the Unix version of the given string.
|
||||
Takes a single string argument.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
unless arguments[0].is_a?(String)
|
||||
raise(Puppet::ParseError, 'dos2unix(): Requires string as argument')
|
||||
end
|
||||
|
||||
arguments[0].gsub(/\r\n/, "\n")
|
||||
end
|
||||
end
|
@ -0,0 +1,32 @@
|
||||
#
|
||||
# downcase.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:downcase, :type => :rvalue, :doc => <<-EOS
|
||||
Converts the case of a string or all strings in an array to lower case.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "downcase(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
value = arguments[0]
|
||||
|
||||
unless value.is_a?(Array) || value.is_a?(String)
|
||||
raise(Puppet::ParseError, 'downcase(): Requires either ' +
|
||||
'array or string to work with')
|
||||
end
|
||||
|
||||
if value.is_a?(Array)
|
||||
# Numbers in Puppet are often string-encoded which is troublesome ...
|
||||
result = value.collect { |i| i.is_a?(String) ? i.downcase : i }
|
||||
else
|
||||
result = value.downcase
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,31 @@
|
||||
#
|
||||
# empty.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:empty, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable is empty.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "empty(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
value = arguments[0]
|
||||
|
||||
unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String) || value.is_a?(Numeric)
|
||||
raise(Puppet::ParseError, 'empty(): Requires either ' +
|
||||
'array, hash, string or integer to work with')
|
||||
end
|
||||
|
||||
if value.is_a?(Numeric)
|
||||
return false
|
||||
else
|
||||
result = value.empty?
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,45 @@
|
||||
#
|
||||
# enclose_ipv6.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:enclose_ipv6, :type => :rvalue, :doc => <<-EOS
|
||||
Takes an array of ip addresses and encloses the ipv6 addresses with square brackets.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
require 'ipaddr'
|
||||
|
||||
rescuable_exceptions = [ ArgumentError ]
|
||||
if defined?(IPAddr::InvalidAddressError)
|
||||
rescuable_exceptions << IPAddr::InvalidAddressError
|
||||
end
|
||||
|
||||
if (arguments.size != 1) then
|
||||
raise(Puppet::ParseError, "enclose_ipv6(): Wrong number of arguments "+
|
||||
"given #{arguments.size} for 1")
|
||||
end
|
||||
unless arguments[0].is_a?(String) or arguments[0].is_a?(Array) then
|
||||
raise(Puppet::ParseError, "enclose_ipv6(): Wrong argument type "+
|
||||
"given #{arguments[0].class} expected String or Array")
|
||||
end
|
||||
|
||||
input = [arguments[0]].flatten.compact
|
||||
result = []
|
||||
|
||||
input.each do |val|
|
||||
unless val == '*'
|
||||
begin
|
||||
ip = IPAddr.new(val)
|
||||
rescue *rescuable_exceptions
|
||||
raise(Puppet::ParseError, "enclose_ipv6(): Wrong argument "+
|
||||
"given #{val} is not an ip address.")
|
||||
end
|
||||
val = "[#{ip.to_s}]" if ip.ipv6?
|
||||
end
|
||||
result << val
|
||||
end
|
||||
|
||||
return result.uniq
|
||||
end
|
||||
end
|
@ -0,0 +1,46 @@
|
||||
#
|
||||
# ensure_packages.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS
|
||||
Takes a list of packages and only installs them if they don't already exist.
|
||||
It optionally takes a hash as a second parameter that will be passed as the
|
||||
third argument to the ensure_resource() function.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if arguments.size > 2 or arguments.size == 0
|
||||
raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1 or 2)")
|
||||
elsif arguments.size == 2 and !arguments[1].is_a?(Hash)
|
||||
raise(Puppet::ParseError, 'ensure_packages(): Requires second argument to be a Hash')
|
||||
end
|
||||
|
||||
if arguments[0].is_a?(Hash)
|
||||
if arguments[1]
|
||||
defaults = { 'ensure' => 'present' }.merge(arguments[1])
|
||||
else
|
||||
defaults = { 'ensure' => 'present' }
|
||||
end
|
||||
|
||||
Puppet::Parser::Functions.function(:ensure_resources)
|
||||
function_ensure_resources(['package', Hash(arguments[0]), defaults ])
|
||||
else
|
||||
packages = Array(arguments[0])
|
||||
|
||||
if arguments[1]
|
||||
defaults = { 'ensure' => 'present' }.merge(arguments[1])
|
||||
else
|
||||
defaults = { 'ensure' => 'present' }
|
||||
end
|
||||
|
||||
Puppet::Parser::Functions.function(:ensure_resource)
|
||||
packages.each { |package_name|
|
||||
function_ensure_resource(['package', package_name, defaults ])
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,46 @@
|
||||
# Test whether a given class or definition is defined
|
||||
require 'puppet/parser/functions'
|
||||
|
||||
Puppet::Parser::Functions.newfunction(:ensure_resource,
|
||||
:type => :statement,
|
||||
:doc => <<-'ENDOFDOC'
|
||||
Takes a resource type, title, and a list of attributes that describe a
|
||||
resource.
|
||||
|
||||
user { 'dan':
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
This example only creates the resource if it does not already exist:
|
||||
|
||||
ensure_resource('user', 'dan', {'ensure' => 'present' })
|
||||
|
||||
If the resource already exists but does not match the specified parameters,
|
||||
this function will attempt to recreate the resource leading to a duplicate
|
||||
resource definition error.
|
||||
|
||||
An array of resources can also be passed in and each will be created with
|
||||
the type and parameters specified if it doesn't already exist.
|
||||
|
||||
ensure_resource('user', ['dan','alex'], {'ensure' => 'present'})
|
||||
|
||||
ENDOFDOC
|
||||
) do |vals|
|
||||
type, title, params = vals
|
||||
raise(ArgumentError, 'Must specify a type') unless type
|
||||
raise(ArgumentError, 'Must specify a title') unless title
|
||||
params ||= {}
|
||||
|
||||
items = [title].flatten
|
||||
|
||||
items.each do |item|
|
||||
Puppet::Parser::Functions.function(:defined_with_params)
|
||||
if function_defined_with_params(["#{type}[#{item}]", params])
|
||||
Puppet.debug("Resource #{type}[#{item}] with params #{params} not created because it already exists")
|
||||
else
|
||||
Puppet.debug("Create new resource #{type}[#{item}] with params #{params}")
|
||||
Puppet::Parser::Functions.function(:create_resources)
|
||||
function_create_resources([type.capitalize, { item => params }])
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,54 @@
|
||||
require 'puppet/parser/functions'
|
||||
|
||||
Puppet::Parser::Functions.newfunction(:ensure_resources,
|
||||
:type => :statement,
|
||||
:doc => <<-'ENDOFDOC'
|
||||
Takes a resource type, title (only hash), and a list of attributes that describe a
|
||||
resource.
|
||||
|
||||
user { 'dan':
|
||||
gid => 'mygroup',
|
||||
ensure => present,
|
||||
}
|
||||
|
||||
An hash of resources should be passed in and each will be created with
|
||||
the type and parameters specified if it doesn't already exist.
|
||||
|
||||
ensure_resources('user', {'dan' => { gid => 'mygroup', uid => '600' } , 'alex' => { gid => 'mygroup' }}, {'ensure' => 'present'})
|
||||
|
||||
From Hiera Backend:
|
||||
|
||||
userlist:
|
||||
dan:
|
||||
gid: 'mygroup'
|
||||
uid: '600'
|
||||
alex:
|
||||
gid: 'mygroup'
|
||||
|
||||
Call:
|
||||
ensure_resources('user', hiera_hash('userlist'), {'ensure' => 'present'})
|
||||
|
||||
ENDOFDOC
|
||||
) do |vals|
|
||||
type, title, params = vals
|
||||
raise(ArgumentError, 'Must specify a type') unless type
|
||||
raise(ArgumentError, 'Must specify a title') unless title
|
||||
params ||= {}
|
||||
|
||||
if title.is_a?(Hash)
|
||||
resource_hash = Hash(title)
|
||||
resources = resource_hash.keys
|
||||
|
||||
Puppet::Parser::Functions.function(:ensure_resource)
|
||||
resources.each { |resource_name|
|
||||
if resource_hash[resource_name]
|
||||
params_merged = params.merge(resource_hash[resource_name])
|
||||
else
|
||||
params_merged = params
|
||||
end
|
||||
function_ensure_resource([ type, resource_name, params_merged ])
|
||||
}
|
||||
else
|
||||
raise(Puppet::ParseError, 'ensure_resources(): Requires second argument to be a Hash')
|
||||
end
|
||||
end
|
@ -0,0 +1,33 @@
|
||||
#
|
||||
# flatten.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:flatten, :type => :rvalue, :doc => <<-EOS
|
||||
This function flattens any deeply nested arrays and returns a single flat array
|
||||
as a result.
|
||||
|
||||
*Examples:*
|
||||
|
||||
flatten(['a', ['b', ['c']]])
|
||||
|
||||
Would return: ['a','b','c']
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "flatten(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size != 1
|
||||
|
||||
array = arguments[0]
|
||||
|
||||
unless array.is_a?(Array)
|
||||
raise(Puppet::ParseError, 'flatten(): Requires array to work with')
|
||||
end
|
||||
|
||||
result = array.flatten
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,25 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:floor, :type => :rvalue, :doc => <<-EOS
|
||||
Returns the largest integer less or equal to the argument.
|
||||
Takes a single numeric value as an argument.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "floor(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size != 1
|
||||
|
||||
begin
|
||||
arg = Float(arguments[0])
|
||||
rescue TypeError, ArgumentError => e
|
||||
raise(Puppet::ParseError, "floor(): Wrong argument type " +
|
||||
"given (#{arguments[0]} for Numeric)")
|
||||
end
|
||||
|
||||
raise(Puppet::ParseError, "floor(): Wrong argument type " +
|
||||
"given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
|
||||
|
||||
arg.floor
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,34 @@
|
||||
Puppet::Parser::Functions::newfunction(
|
||||
:fqdn_rand_string,
|
||||
:arity => -2,
|
||||
:type => :rvalue,
|
||||
:doc => "Usage: `fqdn_rand_string(LENGTH, [CHARSET], [SEED])`. LENGTH is
|
||||
required and must be a positive integer. CHARSET is optional and may be
|
||||
`undef` or a string. SEED is optional and may be any number or string.
|
||||
|
||||
Generates a random string LENGTH characters long using the character set
|
||||
provided by CHARSET, combining the `$fqdn` fact and the value of SEED for
|
||||
repeatable randomness. (That is, each node will get a different random
|
||||
string from this function, but a given node's result will be the same every
|
||||
time unless its hostname changes.) Adding a SEED can be useful if you need
|
||||
more than one unrelated string. CHARSET will default to alphanumeric if
|
||||
`undef` or an empty string.") do |args|
|
||||
raise(ArgumentError, "fqdn_rand_string(): wrong number of arguments (0 for 1)") if args.size == 0
|
||||
Puppet::Parser::Functions.function('is_integer')
|
||||
raise(ArgumentError, "fqdn_rand_string(): first argument must be a positive integer") unless function_is_integer([args[0]]) and args[0].to_i > 0
|
||||
raise(ArgumentError, "fqdn_rand_string(): second argument must be undef or a string") unless args[1].nil? or args[1].is_a? String
|
||||
|
||||
Puppet::Parser::Functions.function('fqdn_rand')
|
||||
|
||||
length = args.shift.to_i
|
||||
charset = args.shift.to_s.chars.to_a
|
||||
|
||||
charset = (0..9).map { |i| i.to_s } + ('A'..'Z').to_a + ('a'..'z').to_a if charset.empty?
|
||||
|
||||
rand_string = ''
|
||||
for current in 1..length
|
||||
rand_string << charset[function_fqdn_rand([charset.size, (args + [current.to_s]).join(':')]).to_i]
|
||||
end
|
||||
|
||||
rand_string
|
||||
end
|
@ -0,0 +1,63 @@
|
||||
#
|
||||
# fqdn_rotate.rb
|
||||
#
|
||||
|
||||
Puppet::Parser::Functions.newfunction(
|
||||
:fqdn_rotate,
|
||||
:type => :rvalue,
|
||||
:doc => "Usage: `fqdn_rotate(VALUE, [SEED])`. VALUE is required and
|
||||
must be an array or a string. SEED is optional and may be any number
|
||||
or string.
|
||||
|
||||
Rotates VALUE a random number of times, combining the `$fqdn` fact and
|
||||
the value of SEED for repeatable randomness. (That is, each node will
|
||||
get a different random rotation from this function, but a given node's
|
||||
result will be the same every time unless its hostname changes.) Adding
|
||||
a SEED can be useful if you need more than one unrelated rotation.") do |args|
|
||||
|
||||
raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments " +
|
||||
"given (#{args.size} for 1)") if args.size < 1
|
||||
|
||||
value = args.shift
|
||||
require 'digest/md5'
|
||||
|
||||
unless value.is_a?(Array) || value.is_a?(String)
|
||||
raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' +
|
||||
'array or string to work with')
|
||||
end
|
||||
|
||||
result = value.clone
|
||||
|
||||
string = value.is_a?(String) ? true : false
|
||||
|
||||
# Check whether it makes sense to rotate ...
|
||||
return result if result.size <= 1
|
||||
|
||||
# We turn any string value into an array to be able to rotate ...
|
||||
result = string ? result.split('') : result
|
||||
|
||||
elements = result.size
|
||||
|
||||
seed = Digest::MD5.hexdigest([lookupvar('::fqdn'),args].join(':')).hex
|
||||
# deterministic_rand() was added in Puppet 3.2.0; reimplement if necessary
|
||||
if Puppet::Util.respond_to?(:deterministic_rand)
|
||||
offset = Puppet::Util.deterministic_rand(seed, elements).to_i
|
||||
else
|
||||
if defined?(Random) == 'constant' && Random.class == Class
|
||||
offset = Random.new(seed).rand(elements)
|
||||
else
|
||||
old_seed = srand(seed)
|
||||
offset = rand(elements)
|
||||
srand(old_seed)
|
||||
end
|
||||
end
|
||||
offset.times {
|
||||
result.push result.shift
|
||||
}
|
||||
|
||||
result = string ? result.join : result
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,17 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:get_module_path, :type =>:rvalue, :doc => <<-EOT
|
||||
Returns the absolute path of the specified module for the current
|
||||
environment.
|
||||
|
||||
Example:
|
||||
$module_path = get_module_path('stdlib')
|
||||
EOT
|
||||
) do |args|
|
||||
raise(Puppet::ParseError, "get_module_path(): Wrong number of arguments, expects one") unless args.size == 1
|
||||
if module_path = Puppet::Module.find(args[0], compiler.environment.to_s)
|
||||
module_path.path
|
||||
else
|
||||
raise(Puppet::ParseError, "Could not find module #{args[0]} in environment #{compiler.environment}")
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,35 @@
|
||||
# Test whether a given class or definition is defined
|
||||
require 'puppet/parser/functions'
|
||||
|
||||
Puppet::Parser::Functions.newfunction(:getparam,
|
||||
:type => :rvalue,
|
||||
:doc => <<-'ENDOFDOC'
|
||||
Takes a resource reference and name of the parameter and
|
||||
returns value of resource's parameter.
|
||||
|
||||
*Examples:*
|
||||
|
||||
define example_resource($param) {
|
||||
}
|
||||
|
||||
example_resource { "example_resource_instance":
|
||||
param => "param_value"
|
||||
}
|
||||
|
||||
getparam(Example_resource["example_resource_instance"], "param")
|
||||
|
||||
Would return: param_value
|
||||
ENDOFDOC
|
||||
) do |vals|
|
||||
reference, param = vals
|
||||
raise(ArgumentError, 'Must specify a reference') unless reference
|
||||
raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String
|
||||
|
||||
return '' if param.empty?
|
||||
|
||||
if resource = findresource(reference.to_s)
|
||||
return resource[param] if resource[param]
|
||||
end
|
||||
|
||||
return ''
|
||||
end
|
@ -0,0 +1,31 @@
|
||||
module Puppet::Parser::Functions
|
||||
|
||||
newfunction(:getvar, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
|
||||
Lookup a variable in a remote namespace.
|
||||
|
||||
For example:
|
||||
|
||||
$foo = getvar('site::data::foo')
|
||||
# Equivalent to $foo = $site::data::foo
|
||||
|
||||
This is useful if the namespace itself is stored in a string:
|
||||
|
||||
$datalocation = 'site::data'
|
||||
$bar = getvar("${datalocation}::bar")
|
||||
# Equivalent to $bar = $site::data::bar
|
||||
ENDHEREDOC
|
||||
|
||||
unless args.length == 1
|
||||
raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)")
|
||||
end
|
||||
|
||||
begin
|
||||
catch(:undefined_variable) do
|
||||
self.lookupvar("#{args[0]}")
|
||||
end
|
||||
rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,33 @@
|
||||
#
|
||||
# grep.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:grep, :type => :rvalue, :doc => <<-EOS
|
||||
This function searches through an array and returns any elements that match
|
||||
the provided regular expression.
|
||||
|
||||
*Examples:*
|
||||
|
||||
grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
|
||||
|
||||
Would return:
|
||||
|
||||
['aaa','aaaddd']
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if (arguments.size != 2) then
|
||||
raise(Puppet::ParseError, "grep(): Wrong number of arguments "+
|
||||
"given #{arguments.size} for 2")
|
||||
end
|
||||
|
||||
a = arguments[0]
|
||||
pattern = Regexp.new(arguments[1])
|
||||
|
||||
a.grep(pattern)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,71 @@
|
||||
#
|
||||
# has_interface_with
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:has_interface_with, :type => :rvalue, :doc => <<-EOS
|
||||
Returns boolean based on kind and value:
|
||||
* macaddress
|
||||
* netmask
|
||||
* ipaddress
|
||||
* network
|
||||
|
||||
has_interface_with("macaddress", "x:x:x:x:x:x")
|
||||
has_interface_with("ipaddress", "127.0.0.1") => true
|
||||
etc.
|
||||
|
||||
If no "kind" is given, then the presence of the interface is checked:
|
||||
has_interface_with("lo") => true
|
||||
EOS
|
||||
) do |args|
|
||||
|
||||
raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments " +
|
||||
"given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2
|
||||
|
||||
interfaces = lookupvar('interfaces')
|
||||
|
||||
# If we do not have any interfaces, then there are no requested attributes
|
||||
return false if (interfaces == :undefined || interfaces.nil?)
|
||||
|
||||
interfaces = interfaces.split(',')
|
||||
|
||||
if args.size == 1
|
||||
return interfaces.member?(args[0])
|
||||
end
|
||||
|
||||
kind, value = args
|
||||
|
||||
# Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable
|
||||
# https://tickets.puppetlabs.com/browse/PUP-3597
|
||||
factval = nil
|
||||
begin
|
||||
catch :undefined_variable do
|
||||
factval = lookupvar(kind)
|
||||
end
|
||||
rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
|
||||
end
|
||||
if factval == value
|
||||
return true
|
||||
end
|
||||
|
||||
result = false
|
||||
interfaces.each do |iface|
|
||||
iface.downcase!
|
||||
factval = nil
|
||||
begin
|
||||
# Bug with 3.7.1 - 3.7.3 when using future parser throws :undefined_variable
|
||||
# https://tickets.puppetlabs.com/browse/PUP-3597
|
||||
catch :undefined_variable do
|
||||
factval = lookupvar("#{kind}_#{iface}")
|
||||
end
|
||||
rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
|
||||
end
|
||||
if value == factval
|
||||
result = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
end
|
@ -0,0 +1,25 @@
|
||||
#
|
||||
# has_ip_address
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:has_ip_address, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the client has the requested IP address on some interface.
|
||||
|
||||
This function iterates through the 'interfaces' fact and checks the
|
||||
'ipaddress_IFACE' facts, performing a simple string comparison.
|
||||
EOS
|
||||
) do |args|
|
||||
|
||||
raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments " +
|
||||
"given (#{args.size} for 1)") if args.size != 1
|
||||
|
||||
Puppet::Parser::Functions.autoloader.load(:has_interface_with) \
|
||||
unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with)
|
||||
|
||||
function_has_interface_with(['ipaddress', args[0]])
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# vim:sts=2 sw=2
|
@ -0,0 +1,25 @@
|
||||
#
|
||||
# has_ip_network
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:has_ip_network, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the client has an IP address within the requested network.
|
||||
|
||||
This function iterates through the 'interfaces' fact and checks the
|
||||
'network_IFACE' facts, performing a simple string comparision.
|
||||
EOS
|
||||
) do |args|
|
||||
|
||||
raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments " +
|
||||
"given (#{args.size} for 1)") if args.size != 1
|
||||
|
||||
Puppet::Parser::Functions.autoloader.load(:has_interface_with) \
|
||||
unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with)
|
||||
|
||||
function_has_interface_with(['network', args[0]])
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# vim:sts=2 sw=2
|
@ -0,0 +1,28 @@
|
||||
module Puppet::Parser::Functions
|
||||
|
||||
newfunction(:has_key, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
|
||||
Determine if a hash has a certain key value.
|
||||
|
||||
Example:
|
||||
|
||||
$my_hash = {'key_one' => 'value_one'}
|
||||
if has_key($my_hash, 'key_two') {
|
||||
notice('we will not reach here')
|
||||
}
|
||||
if has_key($my_hash, 'key_one') {
|
||||
notice('this will be printed')
|
||||
}
|
||||
|
||||
ENDHEREDOC
|
||||
|
||||
unless args.length == 2
|
||||
raise Puppet::ParseError, ("has_key(): wrong number of arguments (#{args.length}; must be 2)")
|
||||
end
|
||||
unless args[0].is_a?(Hash)
|
||||
raise Puppet::ParseError, "has_key(): expects the first argument to be a hash, got #{args[0].inspect} which is of type #{args[0].class}"
|
||||
end
|
||||
args[0].has_key?(args[1])
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,41 @@
|
||||
#
|
||||
# hash.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:hash, :type => :rvalue, :doc => <<-EOS
|
||||
This function converts an array into a hash.
|
||||
|
||||
*Examples:*
|
||||
|
||||
hash(['a',1,'b',2,'c',3])
|
||||
|
||||
Would return: {'a'=>1,'b'=>2,'c'=>3}
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "hash(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
array = arguments[0]
|
||||
|
||||
unless array.is_a?(Array)
|
||||
raise(Puppet::ParseError, 'hash(): Requires array to work with')
|
||||
end
|
||||
|
||||
result = {}
|
||||
|
||||
begin
|
||||
# This is to make it compatible with older version of Ruby ...
|
||||
array = array.flatten
|
||||
result = Hash[*array]
|
||||
rescue StandardError
|
||||
raise(Puppet::ParseError, 'hash(): Unable to compute ' +
|
||||
'hash from array given')
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,34 @@
|
||||
#
|
||||
# intersection.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:intersection, :type => :rvalue, :doc => <<-EOS
|
||||
This function returns an array of the intersection of two.
|
||||
|
||||
*Examples:*
|
||||
|
||||
intersection(["a","b","c"],["b","c","d"]) # returns ["b","c"]
|
||||
intersection(["a","b","c"],[1,2,3,4]) # returns [] (true, when evaluated as a Boolean)
|
||||
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
# Two arguments are required
|
||||
raise(Puppet::ParseError, "intersection(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 2)") if arguments.size != 2
|
||||
|
||||
first = arguments[0]
|
||||
second = arguments[1]
|
||||
|
||||
unless first.is_a?(Array) && second.is_a?(Array)
|
||||
raise(Puppet::ParseError, 'intersection(): Requires 2 arrays')
|
||||
end
|
||||
|
||||
result = first & second
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,50 @@
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_absolute_path, :type => :rvalue, :arity => 1, :doc => <<-'ENDHEREDOC') do |args|
|
||||
Returns boolean true if the string represents an absolute path in the filesystem. This function works
|
||||
for windows and unix style paths.
|
||||
|
||||
The following values will return true:
|
||||
|
||||
$my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet'
|
||||
is_absolute_path($my_path)
|
||||
$my_path2 = '/var/lib/puppet'
|
||||
is_absolute_path($my_path2)
|
||||
$my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet']
|
||||
is_absolute_path($my_path3)
|
||||
$my_path4 = ['/var/lib/puppet']
|
||||
is_absolute_path($my_path4)
|
||||
|
||||
The following values will return false:
|
||||
|
||||
is_absolute_path(true)
|
||||
is_absolute_path('../var/lib/puppet')
|
||||
is_absolute_path('var/lib/puppet')
|
||||
$undefined = undef
|
||||
is_absolute_path($undefined)
|
||||
|
||||
ENDHEREDOC
|
||||
|
||||
require 'puppet/util'
|
||||
|
||||
path = args[0]
|
||||
# This logic was borrowed from
|
||||
# [lib/puppet/file_serving/base.rb](https://github.com/puppetlabs/puppet/blob/master/lib/puppet/file_serving/base.rb)
|
||||
# Puppet 2.7 and beyond will have Puppet::Util.absolute_path? Fall back to a back-ported implementation otherwise.
|
||||
if Puppet::Util.respond_to?(:absolute_path?) then
|
||||
value = (Puppet::Util.absolute_path?(path, :posix) or Puppet::Util.absolute_path?(path, :windows))
|
||||
else
|
||||
# This code back-ported from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path?
|
||||
# Determine in a platform-specific way whether a path is absolute. This
|
||||
# defaults to the local platform if none is specified.
|
||||
# Escape once for the string literal, and once for the regex.
|
||||
slash = '[\\\\/]'
|
||||
name = '[^\\\\/]+'
|
||||
regexes = {
|
||||
:windows => %r!^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))!i,
|
||||
:posix => %r!^/!
|
||||
}
|
||||
value = (!!(path =~ regexes[:posix])) || (!!(path =~ regexes[:windows]))
|
||||
end
|
||||
value
|
||||
end
|
||||
end
|
@ -0,0 +1,22 @@
|
||||
#
|
||||
# is_array.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_array, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable passed to this function is an array.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "is_array(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size < 1
|
||||
|
||||
type = arguments[0]
|
||||
|
||||
result = type.is_a?(Array)
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,22 @@
|
||||
#
|
||||
# is_bool.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_bool, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable passed to this function is a boolean.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "is_bool(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size != 1
|
||||
|
||||
type = arguments[0]
|
||||
|
||||
result = type.is_a?(TrueClass) || type.is_a?(FalseClass)
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,54 @@
|
||||
#
|
||||
# is_domain_name.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_domain_name, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the string passed to this function is a syntactically correct domain name.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if (arguments.size != 1) then
|
||||
raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments "+
|
||||
"given #{arguments.size} for 1")
|
||||
end
|
||||
|
||||
# Only allow string types
|
||||
return false unless arguments[0].is_a?(String)
|
||||
|
||||
domain = arguments[0].dup
|
||||
|
||||
# Limits (rfc1035, 3.1)
|
||||
domain_max_length=255
|
||||
label_min_length=1
|
||||
label_max_length=63
|
||||
|
||||
# Allow ".", it is the top level domain
|
||||
return true if domain == '.'
|
||||
|
||||
# Remove the final dot, if present.
|
||||
domain.chomp!('.')
|
||||
|
||||
# Check the whole domain
|
||||
return false if domain.empty?
|
||||
return false if domain.length > domain_max_length
|
||||
|
||||
# The top level domain must be alphabetic if there are multiple labels.
|
||||
# See rfc1123, 2.1
|
||||
return false if domain.include? '.' and not /\.[A-Za-z]+$/.match(domain)
|
||||
|
||||
# Check each label in the domain
|
||||
labels = domain.split('.')
|
||||
vlabels = labels.each do |label|
|
||||
break if label.length < label_min_length
|
||||
break if label.length > label_max_length
|
||||
break if label[-1..-1] == '-'
|
||||
break if label[0..0] == '-'
|
||||
break unless /^[a-z\d-]+$/i.match(label)
|
||||
end
|
||||
return vlabels == labels
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,21 @@
|
||||
#
|
||||
# is_email_address.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_email_address, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the string passed to this function is a valid email address.
|
||||
EOS
|
||||
) do |arguments|
|
||||
if arguments.size != 1
|
||||
raise(Puppet::ParseError, 'is_email_address(): Wrong number of arguments '\
|
||||
"given #{arguments.size} for 1")
|
||||
end
|
||||
|
||||
# Taken from http://emailregex.com/ (simpler regex)
|
||||
valid_email_regex = %r{\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z}
|
||||
return (arguments[0] =~ valid_email_regex) == 0
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,30 @@
|
||||
#
|
||||
# is_float.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_float, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable passed to this function is a float.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if (arguments.size != 1) then
|
||||
raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+
|
||||
"given #{arguments.size} for 1")
|
||||
end
|
||||
|
||||
value = arguments[0]
|
||||
|
||||
# Only allow Numeric or String types
|
||||
return false unless value.is_a?(Numeric) or value.is_a?(String)
|
||||
|
||||
if value != value.to_f.to_s and !value.is_a? Float then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,26 @@
|
||||
#
|
||||
# is_function_available.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_function_available, :type => :rvalue, :doc => <<-EOS
|
||||
This function accepts a string as an argument, determines whether the
|
||||
Puppet runtime has access to a function by that name. It returns a
|
||||
true if the function exists, false if not.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if (arguments.size != 1) then
|
||||
raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments "+
|
||||
"given #{arguments.size} for 1")
|
||||
end
|
||||
|
||||
# Only allow String types
|
||||
return false unless arguments[0].is_a?(String)
|
||||
|
||||
function = Puppet::Parser::Functions.function(arguments[0].to_sym)
|
||||
function.is_a?(String) and not function.empty?
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,22 @@
|
||||
#
|
||||
# is_hash.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_hash, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable passed to this function is a hash.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "is_hash(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size != 1
|
||||
|
||||
type = arguments[0]
|
||||
|
||||
result = type.is_a?(Hash)
|
||||
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,45 @@
|
||||
#
|
||||
# is_integer.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the variable passed to this function is an Integer or
|
||||
a decimal (base 10) integer in String form. The string may
|
||||
start with a '-' (minus). A value of '0' is allowed, but a leading '0' digit may not
|
||||
be followed by other digits as this indicates that the value is octal (base 8).
|
||||
|
||||
If given any other argument `false` is returned.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
if (arguments.size != 1) then
|
||||
raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+
|
||||
"given #{arguments.size} for 1")
|
||||
end
|
||||
|
||||
value = arguments[0]
|
||||
|
||||
# Regex is taken from the lexer of puppet
|
||||
# puppet/pops/parser/lexer.rb but modified to match also
|
||||
# negative values and disallow numbers prefixed with multiple
|
||||
# 0's
|
||||
#
|
||||
# TODO these parameter should be a constant but I'm not sure
|
||||
# if there is no risk to declare it inside of the module
|
||||
# Puppet::Parser::Functions
|
||||
|
||||
# Integer numbers like
|
||||
# -1234568981273
|
||||
# 47291
|
||||
numeric = %r{^-?(?:(?:[1-9]\d*)|0)$}
|
||||
|
||||
if value.is_a? Integer or (value.is_a? String and value.match numeric)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
@ -0,0 +1,32 @@
|
||||
#
|
||||
# is_ip_address.rb
|
||||
#
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:is_ip_address, :type => :rvalue, :doc => <<-EOS
|
||||
Returns true if the string passed to this function is a valid IP address.
|
||||
EOS
|
||||
) do |arguments|
|
||||
|
||||
require 'ipaddr'
|
||||
|
||||
if (arguments.size != 1) then
|
||||
raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
|
||||
"given #{arguments.size} for 1")
|
||||
end
|
||||
|
||||
begin
|
||||
ip = IPAddr.new(arguments[0])
|
||||
rescue ArgumentError
|
||||
return false
|
||||
end
|
||||
|
||||
if ip.ipv4? or ip.ipv6? then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# vim: set ts=2 sw=2 et :
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user