├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── Vagrantfile ├── conf ├── apt │ └── passenger.list ├── nginx │ └── nginx.conf └── puppet │ └── hiera.yaml ├── manifests └── vagrant.pp ├── modules ├── apt │ ├── CHANGELOG.md │ ├── Gemfile │ ├── LICENSE │ ├── Modulefile │ ├── README.md │ ├── Rakefile │ ├── manifests │ │ ├── backports.pp │ │ ├── builddep.pp │ │ ├── conf.pp │ │ ├── debian │ │ │ ├── testing.pp │ │ │ └── unstable.pp │ │ ├── force.pp │ │ ├── init.pp │ │ ├── key.pp │ │ ├── params.pp │ │ ├── pin.pp │ │ ├── ppa.pp │ │ ├── release.pp │ │ ├── source.pp │ │ ├── unattended_upgrades.pp │ │ └── update.pp │ ├── metadata.json │ ├── spec │ │ ├── acceptance │ │ │ ├── apt_builddep_spec.rb │ │ │ ├── apt_key_spec.rb │ │ │ ├── apt_ppa_spec.rb │ │ │ ├── apt_source_spec.rb │ │ │ ├── apt_spec.rb │ │ │ ├── backports_spec.rb │ │ │ ├── class_spec.rb │ │ │ ├── conf_spec.rb │ │ │ ├── force_spec.rb │ │ │ ├── nodesets │ │ │ │ ├── debian-70rc1-x64.yml │ │ │ │ ├── default.yml │ │ │ │ ├── ubuntu-server-10044-x64.yml │ │ │ │ └── ubuntu-server-12042-x64.yml │ │ │ ├── pin_spec.rb │ │ │ ├── release_spec.rb │ │ │ ├── unattended_upgrade_spec.rb │ │ │ └── unsupported_spec.rb │ │ ├── classes │ │ │ ├── apt_spec.rb │ │ │ ├── backports_spec.rb │ │ │ ├── debian_testing_spec.rb │ │ │ ├── debian_unstable_spec.rb │ │ │ ├── params_spec.rb │ │ │ ├── release_spec.rb │ │ │ └── unattended_upgrades_spec.rb │ │ ├── defines │ │ │ ├── builddep_spec.rb │ │ │ ├── conf_spec.rb │ │ │ ├── force_spec.rb │ │ │ ├── key_spec.rb │ │ │ ├── pin_spec.rb │ │ │ ├── ppa_spec.rb │ │ │ └── source_spec.rb │ │ ├── spec_helper.rb │ │ └── spec_helper_acceptance.rb │ ├── templates │ │ ├── 10periodic.erb │ │ ├── 50unattended-upgrades.erb │ │ ├── pin.pref.erb │ │ └── source.list.erb │ └── tests │ │ ├── builddep.pp │ │ ├── debian │ │ ├── testing.pp │ │ └── unstable.pp │ │ ├── force.pp │ │ ├── init.pp │ │ ├── key.pp │ │ ├── params.pp │ │ ├── pin.pp │ │ ├── ppa.pp │ │ ├── release.pp │ │ ├── source.pp │ │ └── unattended_upgrades.pp ├── docker │ ├── CONTRIBUTING.md │ ├── Gemfile │ ├── Gemfile.lock │ ├── LICENSE │ ├── Modulefile │ ├── README.md │ ├── Rakefile │ ├── manifests │ │ ├── config.pp │ │ ├── image.pp │ │ ├── init.pp │ │ ├── install.pp │ │ ├── params.pp │ │ ├── run.pp │ │ ├── run_instance.pp │ │ └── service.pp │ ├── metadata.json │ ├── spec │ │ ├── classes │ │ │ └── docker_spec.rb │ │ ├── defines │ │ │ ├── image_spec.rb │ │ │ └── run_spec.rb │ │ ├── spec_helper.rb │ │ ├── spec_helper_system.rb │ │ └── system │ │ │ └── docker_spec.rb │ ├── templates │ │ └── etc │ │ │ ├── init.d │ │ │ └── docker-run.erb │ │ │ ├── init │ │ │ ├── docker-run.conf.erb │ │ │ └── docker.conf.erb │ │ │ └── sysconfig │ │ │ └── docker.erb │ └── tests │ │ └── base.pp ├── epel │ ├── Gemfile │ ├── Gemfile.lock │ ├── Modulefile │ ├── README.md │ ├── Rakefile │ ├── files │ │ ├── RPM-GPG-KEY-EPEL-5 │ │ └── RPM-GPG-KEY-EPEL-6 │ ├── lib │ │ └── facter │ │ │ └── os_maj_version.rb │ ├── manifests │ │ ├── init.pp │ │ ├── params.pp │ │ └── rpm_gpg_key.pp │ ├── metadata.json │ ├── spec │ │ ├── classes │ │ │ ├── epel_spec.rb │ │ │ ├── shared_base.rb │ │ │ ├── shared_debuginfo.rb │ │ │ ├── shared_gpgkey.rb │ │ │ ├── shared_source.rb │ │ │ ├── shared_testing.rb │ │ │ ├── shared_testing_debuginfo.rb │ │ │ └── shared_testing_source.rb │ │ ├── defines │ │ │ └── rpm_gpg_key_spec.rb │ │ ├── spec_helper.rb │ │ ├── spec_helper_system.rb │ │ ├── system │ │ │ ├── basic_spec.rb │ │ │ └── usage_spec.rb │ │ └── unit │ │ │ └── facter │ │ │ └── os_maj_version_spec.rb │ └── tests │ │ └── init.pp └── stdlib │ ├── CHANGELOG │ ├── CONTRIBUTING.md │ ├── Gemfile │ ├── LICENSE │ ├── Modulefile │ ├── README.markdown │ ├── README_DEVELOPER.markdown │ ├── README_SPECS.markdown │ ├── RELEASE_PROCESS.markdown │ ├── Rakefile │ ├── lib │ ├── facter │ │ ├── facter_dot_d.rb │ │ ├── pe_version.rb │ │ ├── puppet_vardir.rb │ │ ├── root_home.rb │ │ └── util │ │ │ └── puppet_settings.rb │ └── puppet │ │ ├── parser │ │ └── functions │ │ │ ├── abs.rb │ │ │ ├── any2array.rb │ │ │ ├── bool2num.rb │ │ │ ├── capitalize.rb │ │ │ ├── chomp.rb │ │ │ ├── chop.rb │ │ │ ├── concat.rb │ │ │ ├── count.rb │ │ │ ├── defined_with_params.rb │ │ │ ├── delete.rb │ │ │ ├── delete_at.rb │ │ │ ├── dirname.rb │ │ │ ├── downcase.rb │ │ │ ├── empty.rb │ │ │ ├── ensure_packages.rb │ │ │ ├── ensure_resource.rb │ │ │ ├── flatten.rb │ │ │ ├── floor.rb │ │ │ ├── fqdn_rotate.rb │ │ │ ├── get_module_path.rb │ │ │ ├── getparam.rb │ │ │ ├── getvar.rb │ │ │ ├── grep.rb │ │ │ ├── has_interface_with.rb │ │ │ ├── has_ip_address.rb │ │ │ ├── has_ip_network.rb │ │ │ ├── has_key.rb │ │ │ ├── hash.rb │ │ │ ├── is_array.rb │ │ │ ├── is_domain_name.rb │ │ │ ├── is_float.rb │ │ │ ├── is_function_available.rb │ │ │ ├── is_hash.rb │ │ │ ├── is_integer.rb │ │ │ ├── is_ip_address.rb │ │ │ ├── is_mac_address.rb │ │ │ ├── is_numeric.rb │ │ │ ├── is_string.rb │ │ │ ├── join.rb │ │ │ ├── join_keys_to_values.rb │ │ │ ├── keys.rb │ │ │ ├── loadyaml.rb │ │ │ ├── lstrip.rb │ │ │ ├── max.rb │ │ │ ├── member.rb │ │ │ ├── merge.rb │ │ │ ├── min.rb │ │ │ ├── num2bool.rb │ │ │ ├── parsejson.rb │ │ │ ├── parseyaml.rb │ │ │ ├── pick.rb │ │ │ ├── prefix.rb │ │ │ ├── range.rb │ │ │ ├── reject.rb │ │ │ ├── reverse.rb │ │ │ ├── rstrip.rb │ │ │ ├── shuffle.rb │ │ │ ├── size.rb │ │ │ ├── sort.rb │ │ │ ├── squeeze.rb │ │ │ ├── str2bool.rb │ │ │ ├── str2saltedsha512.rb │ │ │ ├── strftime.rb │ │ │ ├── strip.rb │ │ │ ├── suffix.rb │ │ │ ├── swapcase.rb │ │ │ ├── time.rb │ │ │ ├── to_bytes.rb │ │ │ ├── type.rb │ │ │ ├── unique.rb │ │ │ ├── upcase.rb │ │ │ ├── uriescape.rb │ │ │ ├── validate_absolute_path.rb │ │ │ ├── validate_array.rb │ │ │ ├── validate_augeas.rb │ │ │ ├── validate_bool.rb │ │ │ ├── validate_cmd.rb │ │ │ ├── validate_hash.rb │ │ │ ├── validate_re.rb │ │ │ ├── validate_slength.rb │ │ │ ├── validate_string.rb │ │ │ ├── values.rb │ │ │ ├── values_at.rb │ │ │ └── zip.rb │ │ ├── provider │ │ └── file_line │ │ │ └── ruby.rb │ │ └── type │ │ ├── anchor.rb │ │ └── file_line.rb │ ├── manifests │ ├── init.pp │ └── stages.pp │ ├── metadata.json │ ├── spec │ ├── classes │ │ └── anchor_spec.rb │ ├── fixtures │ │ └── manifests │ │ │ └── site.pp │ ├── functions │ │ ├── defined_with_params_spec.rb │ │ ├── ensure_packages_spec.rb │ │ ├── ensure_resource_spec.rb │ │ └── getparam_spec.rb │ ├── monkey_patches │ │ ├── alias_should_to_must.rb │ │ └── publicize_methods.rb │ ├── spec.opts │ ├── spec_helper.rb │ ├── unit │ │ ├── facter │ │ │ ├── pe_required_facts_spec.rb │ │ │ ├── pe_version_spec.rb │ │ │ ├── root_home_spec.rb │ │ │ └── util │ │ │ │ └── puppet_settings_spec.rb │ │ └── puppet │ │ │ ├── parser │ │ │ └── functions │ │ │ │ ├── abs_spec.rb │ │ │ │ ├── any2array_spec.rb │ │ │ │ ├── bool2num_spec.rb │ │ │ │ ├── capitalize_spec.rb │ │ │ │ ├── chomp_spec.rb │ │ │ │ ├── chop_spec.rb │ │ │ │ ├── concat_spec.rb │ │ │ │ ├── count_spec.rb │ │ │ │ ├── delete_at_spec.rb │ │ │ │ ├── delete_spec.rb │ │ │ │ ├── dirname_spec.rb │ │ │ │ ├── downcase_spec.rb │ │ │ │ ├── empty_spec.rb │ │ │ │ ├── flatten_spec.rb │ │ │ │ ├── floor_spec.rb │ │ │ │ ├── fqdn_rotate_spec.rb │ │ │ │ ├── get_module_path_spec.rb │ │ │ │ ├── getvar_spec.rb │ │ │ │ ├── grep_spec.rb │ │ │ │ ├── has_interface_with_spec.rb │ │ │ │ ├── has_ip_address_spec.rb │ │ │ │ ├── has_ip_network_spec.rb │ │ │ │ ├── has_key_spec.rb │ │ │ │ ├── hash_spec.rb │ │ │ │ ├── is_array_spec.rb │ │ │ │ ├── is_domain_name_spec.rb │ │ │ │ ├── is_float_spec.rb │ │ │ │ ├── is_function_available.rb │ │ │ │ ├── is_hash_spec.rb │ │ │ │ ├── is_integer_spec.rb │ │ │ │ ├── is_ip_address_spec.rb │ │ │ │ ├── is_mac_address_spec.rb │ │ │ │ ├── is_numeric_spec.rb │ │ │ │ ├── is_string_spec.rb │ │ │ │ ├── join_keys_to_values_spec.rb │ │ │ │ ├── join_spec.rb │ │ │ │ ├── keys_spec.rb │ │ │ │ ├── lstrip_spec.rb │ │ │ │ ├── max_spec.rb │ │ │ │ ├── member_spec.rb │ │ │ │ ├── merge_spec.rb │ │ │ │ ├── min_spec.rb │ │ │ │ ├── num2bool_spec.rb │ │ │ │ ├── parsejson_spec.rb │ │ │ │ ├── parseyaml_spec.rb │ │ │ │ ├── pick_spec.rb │ │ │ │ ├── prefix_spec.rb │ │ │ │ ├── range_spec.rb │ │ │ │ ├── reject_spec.rb │ │ │ │ ├── reverse_spec.rb │ │ │ │ ├── rstrip_spec.rb │ │ │ │ ├── shuffle_spec.rb │ │ │ │ ├── size_spec.rb │ │ │ │ ├── sort_spec.rb │ │ │ │ ├── squeeze_spec.rb │ │ │ │ ├── str2bool_spec.rb │ │ │ │ ├── str2saltedsha512_spec.rb │ │ │ │ ├── strftime_spec.rb │ │ │ │ ├── strip_spec.rb │ │ │ │ ├── suffix_spec.rb │ │ │ │ ├── swapcase_spec.rb │ │ │ │ ├── time_spec.rb │ │ │ │ ├── to_bytes_spec.rb │ │ │ │ ├── type_spec.rb │ │ │ │ ├── unique_spec.rb │ │ │ │ ├── upcase_spec.rb │ │ │ │ ├── uriescape_spec.rb │ │ │ │ ├── validate_absolute_path_spec.rb │ │ │ │ ├── validate_array_spec.rb │ │ │ │ ├── validate_augeas_spec.rb │ │ │ │ ├── validate_bool_spec.rb │ │ │ │ ├── validate_cmd_spec.rb │ │ │ │ ├── validate_hash_spec.rb │ │ │ │ ├── validate_re_spec.rb │ │ │ │ ├── validate_slength_spec.rb │ │ │ │ ├── validate_string_spec.rb │ │ │ │ ├── values_at_spec.rb │ │ │ │ ├── values_spec.rb │ │ │ │ └── zip_spec.rb │ │ │ ├── provider │ │ │ └── file_line │ │ │ │ └── ruby_spec.rb │ │ │ └── type │ │ │ ├── anchor_spec.rb │ │ │ └── file_line_spec.rb │ └── watchr.rb │ └── tests │ ├── file_line.pp │ ├── has_interface_with.pp │ ├── has_ip_address.pp │ ├── has_ip_network.pp │ └── init.pp └── scripts ├── 10_generate_puppet_config.rb ├── 11_generate_nginx_site.rb ├── 12_generate_puppetmaster_keys.sh ├── 13_add_puppet_cron.sh ├── nginx-startup.sh └── run-puppet-agent.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 rfkrocktk 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | VAGRANTFILE_API_VERSION = "2" 6 | 7 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 8 | # Use Phusion's Ubuntu 12.04 box with support for Docker 9 | config.vm.box = "phusion-open-ubuntu-14.04-amd64" 10 | config.vm.box_url = "https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box" 11 | # Set hostname 12 | config.vm.hostname = "vagrant-trusty64" 13 | 14 | # Configure the VirtualBox Provider 15 | config.vm.provider :virtualbox do |vb| 16 | # Give the VM 1GB of RAM 17 | vb.customize ["modifyvm", :id, "--memory", "1024"] 18 | end 19 | 20 | # Provisioning with Puppet Standalone 21 | config.vm.provision :puppet do |puppet| 22 | puppet.hiera_config_path = "conf/puppet/hiera.yaml" 23 | puppet.manifests_path = "manifests" 24 | puppet.manifest_file = "vagrant.pp" 25 | puppet.module_path = "modules" 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /conf/apt/passenger.list: -------------------------------------------------------------------------------- 1 | # Repository for Phusion Passenger and NGINX 2 | deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main 3 | -------------------------------------------------------------------------------- /conf/puppet/hiera.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | :backends: yaml 3 | :yaml: 4 | :datadir: /var/lib/hiera 5 | :hierarchy: common 6 | :logger: console -------------------------------------------------------------------------------- /manifests/vagrant.pp: -------------------------------------------------------------------------------- 1 | # Puppet for Docker Vagrant Box 2 | node 'vagrant-trusty64' { 3 | # apt 4 | class { 'apt': } 5 | 6 | # docker 7 | apt::source { 'docker': 8 | location => "http://get.docker.io/ubuntu", 9 | key => "36A1D7869245C8950F966E92D8576A8BA88D21E9", 10 | release => "docker", 11 | repos => "main", 12 | include_src => false 13 | } 14 | 15 | package { 'lxc-docker': 16 | require => [Apt::Source["docker"]] 17 | } 18 | 19 | # tools 20 | package { 'lxc': } # lxc-attach 21 | package { 'tree': } 22 | 23 | # install puppet client in vagrant 24 | apt::source { 'puppetlabs': 25 | key => '4BD6EC30', 26 | location => 'http://apt.puppetlabs.com', 27 | repos => 'main dependencies' 28 | } 29 | 30 | package { 'puppet': 31 | ensure => latest, 32 | require => [Apt::Source["puppetlabs"]] 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /modules/apt/Gemfile: -------------------------------------------------------------------------------- 1 | source ENV['GEM_SOURCE'] || 'https://rubygems.org' 2 | 3 | group :development, :test do 4 | gem 'rake', :require => false 5 | gem 'pry', :require => false 6 | gem 'rspec-puppet', :require => false 7 | gem 'puppet-lint', :require => false 8 | gem 'puppetlabs_spec_helper', :require => false 9 | gem 'serverspec', :require => false 10 | gem 'beaker', :require => false 11 | gem 'beaker-rspec', :require => false 12 | end 13 | 14 | if puppetversion = ENV['PUPPET_GEM_VERSION'] 15 | gem 'puppet', puppetversion, :require => false 16 | else 17 | gem 'puppet', :require => false 18 | end 19 | -------------------------------------------------------------------------------- /modules/apt/Modulefile: -------------------------------------------------------------------------------- 1 | name 'puppetlabs-apt' 2 | version '1.4.2' 3 | source 'https://github.com/puppetlabs/puppetlabs-apt' 4 | author 'Evolving Web / Puppet Labs' 5 | license 'Apache License 2.0' 6 | summary 'Puppet Labs Apt Module' 7 | description 'APT Module for Puppet' 8 | project_page 'https://github.com/puppetlabs/puppetlabs-apt' 9 | 10 | ## Add dependencies, if any: 11 | #dependency 'puppetlabs/stdlib', '2.x' 12 | # The dependency should be written as above but librarian-puppet 13 | # does not support the expression as the PMT does. 14 | dependency 'puppetlabs/stdlib', '>= 2.2.1' 15 | -------------------------------------------------------------------------------- /modules/apt/Rakefile: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/rake_tasks' 2 | require 'puppet-lint/tasks/puppet-lint' 3 | 4 | PuppetLint.configuration.send('disable_single_quote_string_with_variables') 5 | -------------------------------------------------------------------------------- /modules/apt/manifests/backports.pp: -------------------------------------------------------------------------------- 1 | # This adds the necessary components to get backports for ubuntu and debian 2 | # 3 | # == Parameters 4 | # 5 | # [*release*] 6 | # The ubuntu/debian release name. Defaults to $lsbdistcodename. Setting this 7 | # manually can cause undefined behavior. (Read: universe exploding) 8 | # 9 | # == Examples 10 | # 11 | # include apt::backports 12 | # 13 | # class { 'apt::backports': 14 | # release => 'natty', 15 | # } 16 | # 17 | # == Authors 18 | # 19 | # Ben Hughes, I think. At least blame him if this goes wrong. 20 | # I just added puppet doc. 21 | # 22 | # == Copyright 23 | # 24 | # Copyright 2011 Puppet Labs Inc, unless otherwise noted. 25 | class apt::backports( 26 | $release = $::lsbdistcodename, 27 | $location = $apt::params::backports_location 28 | ) inherits apt::params { 29 | 30 | $release_real = downcase($release) 31 | $key = $::lsbdistid ? { 32 | 'debian' => '46925553', 33 | 'ubuntu' => '437D05B5', 34 | } 35 | $repos = $::lsbdistid ? { 36 | 'debian' => 'main contrib non-free', 37 | 'ubuntu' => 'main universe multiverse restricted', 38 | } 39 | 40 | apt::source { 'backports': 41 | location => $location, 42 | release => "${release_real}-backports", 43 | repos => $repos, 44 | key => $key, 45 | key_server => 'pgp.mit.edu', 46 | pin => '200', 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /modules/apt/manifests/builddep.pp: -------------------------------------------------------------------------------- 1 | # builddep.pp 2 | 3 | define apt::builddep() { 4 | include apt::update 5 | 6 | exec { "apt-builddep-${name}": 7 | command => "/usr/bin/apt-get -y --force-yes build-dep ${name}", 8 | logoutput => 'on_failure', 9 | notify => Exec['apt_update'], 10 | } 11 | 12 | # Need anchor to provide containment for dependencies. 13 | anchor { "apt::builddep::${name}": 14 | require => Class['apt::update'], 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /modules/apt/manifests/conf.pp: -------------------------------------------------------------------------------- 1 | define apt::conf ( 2 | $content, 3 | $ensure = present, 4 | $priority = '50' 5 | ) { 6 | 7 | include apt::params 8 | 9 | $apt_conf_d = $apt::params::apt_conf_d 10 | 11 | file { "${apt_conf_d}/${priority}${name}": 12 | ensure => $ensure, 13 | content => $content, 14 | owner => root, 15 | group => root, 16 | mode => '0644', 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /modules/apt/manifests/debian/testing.pp: -------------------------------------------------------------------------------- 1 | # testing.pp 2 | 3 | class apt::debian::testing { 4 | include apt 5 | 6 | # deb http://debian.mirror.iweb.ca/debian/ testing main contrib non-free 7 | # deb-src http://debian.mirror.iweb.ca/debian/ testing main contrib non-free 8 | # Key: 46925553 Server: subkeys.pgp.net 9 | # debian-keyring 10 | # debian-archive-keyring 11 | 12 | apt::source { 'debian_testing': 13 | location => 'http://debian.mirror.iweb.ca/debian/', 14 | release => 'testing', 15 | repos => 'main contrib non-free', 16 | required_packages => 'debian-keyring debian-archive-keyring', 17 | key => '46925553', 18 | key_server => 'subkeys.pgp.net', 19 | pin => '-10', 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /modules/apt/manifests/debian/unstable.pp: -------------------------------------------------------------------------------- 1 | # unstable.pp 2 | 3 | class apt::debian::unstable { 4 | include apt 5 | 6 | # deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free 7 | # deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free 8 | # Key: 46925553 Server: subkeys.pgp.net 9 | # debian-keyring 10 | # debian-archive-keyring 11 | 12 | apt::source { 'debian_unstable': 13 | location => 'http://debian.mirror.iweb.ca/debian/', 14 | release => 'unstable', 15 | repos => 'main contrib non-free', 16 | required_packages => 'debian-keyring debian-archive-keyring', 17 | key => '46925553', 18 | key_server => 'subkeys.pgp.net', 19 | pin => '-10', 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /modules/apt/manifests/force.pp: -------------------------------------------------------------------------------- 1 | # force.pp 2 | # force a package from a specific release 3 | 4 | define apt::force( 5 | $release = 'testing', 6 | $version = false, 7 | $timeout = 300 8 | ) { 9 | 10 | $provider = $apt::params::provider 11 | 12 | $version_string = $version ? { 13 | false => undef, 14 | default => "=${version}", 15 | } 16 | 17 | $release_string = $release ? { 18 | false => undef, 19 | default => "-t ${release}", 20 | } 21 | 22 | if $version == false { 23 | if $release == false { 24 | $install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'" 25 | } else { 26 | # If installed version and candidate version differ, this check returns 1 (false). 27 | $install_check = "/usr/bin/test \$(/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1" 28 | } 29 | } else { 30 | if $release == false { 31 | $install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'" 32 | } else { 33 | $install_check = "/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -q 'Installed: ${version}'" 34 | } 35 | } 36 | 37 | exec { "${provider} -y ${release_string} install ${name}${version_string}": 38 | unless => $install_check, 39 | logoutput => 'on_failure', 40 | timeout => $timeout, 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /modules/apt/manifests/params.pp: -------------------------------------------------------------------------------- 1 | class apt::params { 2 | $root = '/etc/apt' 3 | $provider = '/usr/bin/apt-get' 4 | $sources_list_d = "${root}/sources.list.d" 5 | $apt_conf_d = "${root}/apt.conf.d" 6 | $preferences_d = "${root}/preferences.d" 7 | 8 | case $::lsbdistid { 9 | 'debian': { 10 | case $::lsbdistcodename { 11 | 'squeeze': { 12 | $backports_location = 'http://backports.debian.org/debian-backports' 13 | } 14 | 'wheezy': { 15 | $backports_location = 'http://ftp.debian.org/debian/' 16 | } 17 | default: { 18 | $backports_location = 'http://http.debian.net/debian/' 19 | } 20 | } 21 | } 22 | 'ubuntu': { 23 | case $::lsbdistcodename { 24 | 'hardy','maverick','natty','oneiric','precise': { 25 | $backports_location = 'http://us.archive.ubuntu.com/ubuntu' 26 | $ppa_options = '-y' 27 | } 28 | 'lucid': { 29 | $backports_location = 'http://us.archive.ubuntu.com/ubuntu' 30 | $ppa_options = undef 31 | } 32 | default: { 33 | $backports_location = 'http://old-releases.ubuntu.com/ubuntu' 34 | $ppa_options = '-y' 35 | } 36 | } 37 | } 38 | default: { 39 | fail("Unsupported osfamily (${::osfamily}) or lsbdistid (${::lsbdistid})") 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /modules/apt/manifests/release.pp: -------------------------------------------------------------------------------- 1 | # release.pp 2 | 3 | class apt::release ( 4 | $release_id 5 | ) { 6 | 7 | include apt::params 8 | 9 | $root = $apt::params::root 10 | 11 | file { "${root}/apt.conf.d/01release": 12 | owner => root, 13 | group => root, 14 | mode => '0644', 15 | content => "APT::Default-Release \"${release_id}\";" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /modules/apt/manifests/update.pp: -------------------------------------------------------------------------------- 1 | class apt::update { 2 | include apt::params 3 | 4 | exec { 'apt_update': 5 | command => "${apt::params::provider} update", 6 | logoutput => 'on_failure', 7 | refreshonly => true, 8 | timeout => $apt::update_timeout, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /modules/apt/spec/acceptance/apt_builddep_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper_acceptance' 2 | 3 | describe 'apt::builddep', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do 4 | 5 | context 'reset' do 6 | it 'removes packages' do 7 | shell('apt-get -y remove znc') 8 | shell('apt-get -y remove g++') 9 | end 10 | end 11 | 12 | context 'apt::builddep' do 13 | it 'should work with no errors' do 14 | pp = <<-EOS 15 | include '::apt' 16 | apt::builddep { 'znc': } 17 | EOS 18 | 19 | apply_manifest(pp, :catch_failures => true) 20 | end 21 | 22 | describe 'should install g++ as a dependency' do 23 | describe package('g++') do 24 | it { should be_installed } 25 | end 26 | end 27 | end 28 | 29 | context 'reset' do 30 | it 'removes packages' do 31 | shell('apt-get -y remove znc') 32 | shell('apt-get -y remove g++') 33 | end 34 | end 35 | 36 | end 37 | -------------------------------------------------------------------------------- /modules/apt/spec/acceptance/class_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper_acceptance' 2 | 3 | describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do 4 | 5 | context 'default parameters' do 6 | # Using puppet_apply as a helper 7 | it 'should work with no errors' do 8 | pp = <<-EOS 9 | class { 'apt': } 10 | EOS 11 | 12 | # Run it twice and test for idempotency 13 | apply_manifest(pp, :catch_failures => true) 14 | apply_manifest(pp, :catch_failures => true) 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /modules/apt/spec/acceptance/nodesets/debian-70rc1-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | debian-70rc1-x64: 3 | roles: 4 | - master 5 | platform: debian-70rc1-x64 6 | box : debian-70rc1-x64-vbox4210-nocm 7 | box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box 8 | hypervisor : vagrant 9 | CONFIG: 10 | type: foss 11 | -------------------------------------------------------------------------------- /modules/apt/spec/acceptance/nodesets/default.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-server-12042-x64: 3 | roles: 4 | - master 5 | platform: ubuntu-server-12.04-amd64 6 | box : ubuntu-server-12042-x64-vbox4210-nocm 7 | box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box 8 | hypervisor : vagrant 9 | CONFIG: 10 | type: foss 11 | -------------------------------------------------------------------------------- /modules/apt/spec/acceptance/nodesets/ubuntu-server-10044-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-server-10044-x64: 3 | roles: 4 | - master 5 | platform: ubuntu-10.04-amd64 6 | box : ubuntu-server-10044-x64-vbox4210-nocm 7 | box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box 8 | hypervisor : vagrant 9 | CONFIG: 10 | log_level: debug 11 | type: git 12 | -------------------------------------------------------------------------------- /modules/apt/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-server-12042-x64: 3 | roles: 4 | - master 5 | platform: ubuntu-server-12.04-amd64 6 | box : ubuntu-server-12042-x64-vbox4210-nocm 7 | box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box 8 | hypervisor : vagrant 9 | CONFIG: 10 | type: foss 11 | -------------------------------------------------------------------------------- /modules/apt/spec/acceptance/release_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper_acceptance' 2 | 3 | describe 'apt::release class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do 4 | context 'release_id' do 5 | it 'should work with no errors' do 6 | pp = <<-EOS 7 | include apt 8 | class { 'apt::release': release_id => 'precise', } 9 | EOS 10 | 11 | apply_manifest(pp, :catch_failures => true) 12 | end 13 | 14 | describe file('/etc/apt/apt.conf.d/01release') do 15 | it { should be_file } 16 | it { should contain 'APT::Default-Release "precise";' } 17 | end 18 | end 19 | 20 | context 'reset' do 21 | it 'cleans up' do 22 | shell('rm -rf /etc/apt/apt.conf.d/01release') 23 | end 24 | end 25 | 26 | end 27 | -------------------------------------------------------------------------------- /modules/apt/spec/acceptance/unsupported_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper_acceptance' 2 | 3 | describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do 4 | it 'class apt fails' do 5 | pp = <<-EOS 6 | class { 'apt': } 7 | EOS 8 | expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/unsupported/i) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /modules/apt/spec/classes/debian_testing_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'apt::debian::testing', :type => :class do 3 | let(:facts) { { :lsbdistid => 'Debian' } } 4 | it { 5 | should contain_apt__source("debian_testing").with({ 6 | "location" => "http://debian.mirror.iweb.ca/debian/", 7 | "release" => "testing", 8 | "repos" => "main contrib non-free", 9 | "required_packages" => "debian-keyring debian-archive-keyring", 10 | "key" => "46925553", 11 | "key_server" => "subkeys.pgp.net", 12 | "pin" => "-10" 13 | }) 14 | } 15 | end 16 | -------------------------------------------------------------------------------- /modules/apt/spec/classes/debian_unstable_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'apt::debian::unstable', :type => :class do 3 | let(:facts) { { :lsbdistid => 'Debian' } } 4 | it { 5 | should contain_apt__source("debian_unstable").with({ 6 | "location" => "http://debian.mirror.iweb.ca/debian/", 7 | "release" => "unstable", 8 | "repos" => "main contrib non-free", 9 | "required_packages" => "debian-keyring debian-archive-keyring", 10 | "key" => "46925553", 11 | "key_server" => "subkeys.pgp.net", 12 | "pin" => "-10" 13 | }) 14 | } 15 | end 16 | -------------------------------------------------------------------------------- /modules/apt/spec/classes/params_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'apt::params', :type => :class do 3 | let(:facts) { { :lsbdistid => 'Debian' } } 4 | let (:title) { 'my_package' } 5 | 6 | it { should contain_apt__params } 7 | 8 | # There are 4 resources in this class currently 9 | # there should not be any more resources because it is a params class 10 | # The resources are class[apt::params], class[main], class[settings], stage[main] 11 | it "Should not contain any resources" do 12 | subject.resources.size.should == 4 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /modules/apt/spec/classes/release_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'apt::release', :type => :class do 3 | let(:facts) { { :lsbdistid => 'Debian' } } 4 | let (:title) { 'my_package' } 5 | 6 | let :param_set do 7 | { :release_id => 'precise' } 8 | end 9 | 10 | let (:params) { param_set } 11 | 12 | it { should contain_class("apt::params") } 13 | 14 | it { 15 | should contain_file("/etc/apt/apt.conf.d/01release").with({ 16 | "mode" => "0644", 17 | "owner" => "root", 18 | "group" => "root", 19 | "content" => "APT::Default-Release \"#{param_set[:release_id]}\";" 20 | }) 21 | } 22 | end 23 | 24 | -------------------------------------------------------------------------------- /modules/apt/spec/defines/builddep_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | describe 'apt::builddep', :type => :define do 3 | 4 | let(:facts) { { :lsbdistid => 'Debian' } } 5 | let(:title) { 'my_package' } 6 | 7 | describe "should require apt-get update" do 8 | it { should contain_exec("apt_update").with({ 9 | 'command' => "/usr/bin/apt-get update", 10 | 'refreshonly' => true 11 | }) 12 | } 13 | it { should contain_anchor("apt::builddep::my_package").with({ 14 | 'require' => 'Class[Apt::Update]', 15 | }) 16 | } 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /modules/apt/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/module_spec_helper' 2 | -------------------------------------------------------------------------------- /modules/apt/spec/spec_helper_acceptance.rb: -------------------------------------------------------------------------------- 1 | require 'beaker-rspec' 2 | 3 | # Install Puppet 4 | unless ENV['RS_PROVISION'] == 'no' 5 | hosts.each do |host| 6 | if host.is_pe? 7 | install_pe 8 | else 9 | install_puppet 10 | on host, "mkdir -p #{host['distmoduledir']}" 11 | end 12 | end 13 | end 14 | 15 | UNSUPPORTED_PLATFORMS = ['RedHat','Suse','windows','AIX','Solaris'] 16 | 17 | RSpec.configure do |c| 18 | # Project root 19 | proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) 20 | 21 | # Readable test descriptions 22 | c.formatter = :documentation 23 | 24 | # Configure all nodes in nodeset 25 | c.before :suite do 26 | # Install module and dependencies 27 | puppet_module_install(:source => proj_root, :module_name => 'apt') 28 | hosts.each do |host| 29 | shell('/bin/touch /etc/puppet/hiera.yaml') 30 | shell('puppet module install puppetlabs-stdlib --version 2.2.1', { :acceptable_exit_codes => [0,1] }) 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /modules/apt/templates/10periodic.erb: -------------------------------------------------------------------------------- 1 | APT::Periodic::Enable "<%= @enable %>"; 2 | APT::Periodic::BackUpArchiveInterval "<%= @backup_interval %>"; 3 | APT::Periodic::BackUpLevel "<%= @backup_level %>"; 4 | APT::Periodic::MaxAge "<%= @max_age %>"; 5 | APT::Periodic::MinAge "<%= @min_age %>"; 6 | APT::Periodic::MaxSize "<%= @max_size %>"; 7 | APT::Periodic::Update-Package-Lists "<%= @update %>"; 8 | APT::Periodic::Download-Upgradeable-Packages "<%= @download %>"; 9 | APT::Periodic::Download-Upgradeable-Packages-Debdelta "<%= @download_delta %>"; 10 | APT::Periodic::Unattended-Upgrade "<%= @upgrade %>"; 11 | APT::Periodic::AutocleanInterval "<%= @autoclean %>"; 12 | APT::Periodic::Verbose "<%= @verbose %>"; 13 | -------------------------------------------------------------------------------- /modules/apt/templates/pin.pref.erb: -------------------------------------------------------------------------------- 1 | <%- 2 | @pin = "release a=#{@name}" # default value 3 | if @pin_release.length > 0 4 | options = [] 5 | options.push("a=#{@release}") if @release.length > 0 6 | options.push("n=#{@codename}") if @codename.length > 0 7 | options.push("v=#{@release_version}") if @release_version.length > 0 8 | options.push("c=#{@component}") if @component.length > 0 9 | options.push("o=#{@originator}") if @originator.length > 0 10 | options.push("l=#{@label}") if @label.length > 0 11 | @pin = "release #{options.join(', ')}" 12 | elsif @version.length > 0 13 | @pin = "version #{@version}" 14 | elsif @origin.length > 0 15 | @pin = "origin #{@origin}" 16 | end 17 | -%> 18 | # <%= @name %> 19 | Explanation: <%= @explanation %> 20 | Package: <%= @packages %> 21 | Pin: <%= @pin %> 22 | Pin-Priority: <%= @priority %> 23 | -------------------------------------------------------------------------------- /modules/apt/templates/source.list.erb: -------------------------------------------------------------------------------- 1 | # <%= @name %> 2 | deb <% if @architecture %>[arch=<%= @architecture %>] <% end %><%= @location %> <%= @release_real %> <%= @repos %> 3 | <%- if @include_src then -%> 4 | deb-src <% if @architecture %>[arch=<%= @architecture %>] <% end %><%= @location %> <%= @release_real %> <%= @repos %> 5 | <%- end -%> 6 | -------------------------------------------------------------------------------- /modules/apt/tests/builddep.pp: -------------------------------------------------------------------------------- 1 | class { 'apt': } 2 | apt::builddep{ 'glusterfs-server': } 3 | -------------------------------------------------------------------------------- /modules/apt/tests/debian/testing.pp: -------------------------------------------------------------------------------- 1 | class { 'apt': } 2 | class { 'apt::debian::testing': } 3 | -------------------------------------------------------------------------------- /modules/apt/tests/debian/unstable.pp: -------------------------------------------------------------------------------- 1 | class { 'apt': } 2 | class { 'apt::debian::unstable': } 3 | -------------------------------------------------------------------------------- /modules/apt/tests/force.pp: -------------------------------------------------------------------------------- 1 | # force.pp 2 | 3 | # force a package from a specific release 4 | apt::force { 'package1': 5 | release => 'backports', 6 | } 7 | 8 | # force a package to be a specific version 9 | apt::force { 'package2': 10 | version => '1.0.0-1', 11 | } 12 | 13 | # force a package from a specific release to be a specific version 14 | apt::force { 'package3': 15 | release => 'sid', 16 | version => '2.0.0-1', 17 | } 18 | -------------------------------------------------------------------------------- /modules/apt/tests/init.pp: -------------------------------------------------------------------------------- 1 | class { 'apt': } 2 | -------------------------------------------------------------------------------- /modules/apt/tests/key.pp: -------------------------------------------------------------------------------- 1 | # Declare Apt key for apt.puppetlabs.com source 2 | apt::key { 'puppetlabs': 3 | key => '4BD6EC30', 4 | key_server => 'pgp.mit.edu', 5 | key_options => 'http-proxy="http://proxyuser:proxypass@example.org:3128"', 6 | } 7 | -------------------------------------------------------------------------------- /modules/apt/tests/params.pp: -------------------------------------------------------------------------------- 1 | include apt::params 2 | -------------------------------------------------------------------------------- /modules/apt/tests/pin.pp: -------------------------------------------------------------------------------- 1 | # pin a release in apt, useful for unstable repositories 2 | apt::pin { 'foo': 3 | packages => '*', 4 | priority => 0, 5 | } 6 | -------------------------------------------------------------------------------- /modules/apt/tests/ppa.pp: -------------------------------------------------------------------------------- 1 | class { 'apt': } 2 | 3 | # Example declaration of an Apt PPA 4 | apt::ppa{ 'ppa:openstack-ppa/bleeding-edge': } 5 | -------------------------------------------------------------------------------- /modules/apt/tests/release.pp: -------------------------------------------------------------------------------- 1 | class { 'apt': } 2 | class { 'apt::release': 3 | release_id => 'karmic' 4 | } 5 | -------------------------------------------------------------------------------- /modules/apt/tests/source.pp: -------------------------------------------------------------------------------- 1 | # Declare the apt class to manage /etc/apt/sources.list and /etc/sources.list.d 2 | class { 'apt': } 3 | 4 | # Install the puppetlabs apt source 5 | # Release is automatically obtained from lsbdistcodename fact if available. 6 | apt::source { 'puppetlabs': 7 | location => 'http://apt.puppetlabs.com', 8 | repos => 'main', 9 | key => '4BD6EC30', 10 | key_server => 'pgp.mit.edu', 11 | } 12 | 13 | # test two sources with the same key 14 | apt::source { 'debian_testing': 15 | location => 'http://debian.mirror.iweb.ca/debian/', 16 | release => 'testing', 17 | repos => 'main contrib non-free', 18 | key => '46925553', 19 | key_server => 'subkeys.pgp.net', 20 | pin => '-10', 21 | } 22 | apt::source { 'debian_unstable': 23 | location => 'http://debian.mirror.iweb.ca/debian/', 24 | release => 'unstable', 25 | repos => 'main contrib non-free', 26 | key => '46925553', 27 | key_server => 'subkeys.pgp.net', 28 | pin => '-10', 29 | } 30 | -------------------------------------------------------------------------------- /modules/apt/tests/unattended_upgrades.pp: -------------------------------------------------------------------------------- 1 | include apt::unattended_upgrades 2 | -------------------------------------------------------------------------------- /modules/docker/Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | group :test do 4 | gem "rake" 5 | gem "puppet", ENV['PUPPET_VERSION'] || '~> 2.7.0' 6 | gem "puppet-lint" 7 | gem "rspec-puppet", '~> 1.0.0' 8 | gem "puppet-syntax" 9 | gem "puppetlabs_spec_helper" 10 | end 11 | 12 | group :development do 13 | gem "travis" 14 | gem "travis-lint" 15 | gem "rspec-system-puppet" 16 | gem "rspec-system-serverspec" 17 | gem "vagrant-wrapper" 18 | gem "puppet-blacksmith" 19 | end 20 | -------------------------------------------------------------------------------- /modules/docker/Modulefile: -------------------------------------------------------------------------------- 1 | name 'garethr-docker' 2 | version '0.13.0' 3 | source 'git://github.com/garethr/garethr-docker.git' 4 | author 'Gareth Rushgrove' 5 | summary 'Module for installing docker from repository on get.docker.io' 6 | description 'Install and manage docker' 7 | license 'Apache License, Version 2.0' 8 | 9 | dependency 'puppetlabs/apt', '>= 1.1.0' 10 | dependency 'puppetlabs/stdlib', '>=4.1.0' 11 | dependency 'stahnma/epel', '>=0.0.6' 12 | -------------------------------------------------------------------------------- /modules/docker/Rakefile: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/rake_tasks' 2 | require 'puppet-lint/tasks/puppet-lint' 3 | require 'puppet-syntax/tasks/puppet-syntax' 4 | 5 | # These two gems aren't always present, for instance 6 | # on Travis with --without development 7 | begin 8 | require 'rspec-system/rake_task' 9 | rescue LoadError 10 | end 11 | 12 | begin 13 | require 'puppet_blacksmith/rake_tasks' 14 | rescue LoadError 15 | end 16 | 17 | PuppetLint.configuration.send("disable_80chars") 18 | PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" 19 | PuppetLint.configuration.fail_on_warnings = true 20 | 21 | # Forsake support for Puppet 2.6.2 for the benefit of cleaner code. 22 | # http://puppet-lint.com/checks/class_parameter_defaults/ 23 | PuppetLint.configuration.send('disable_class_parameter_defaults') 24 | # http://puppet-lint.com/checks/class_inherits_from_params_class/ 25 | PuppetLint.configuration.send('disable_class_inherits_from_params_class') 26 | 27 | exclude_paths = [ 28 | "pkg/**/*", 29 | "vendor/**/*", 30 | "spec/**/*", 31 | ] 32 | PuppetLint.configuration.ignore_paths = exclude_paths 33 | PuppetSyntax.exclude_paths = exclude_paths 34 | 35 | desc "Run syntax, lint, and spec tests." 36 | task :test => [ 37 | :syntax, 38 | :lint, 39 | :spec, 40 | ] 41 | -------------------------------------------------------------------------------- /modules/docker/manifests/config.pp: -------------------------------------------------------------------------------- 1 | # == Class: docker::config 2 | # 3 | class docker::config { 4 | } 5 | -------------------------------------------------------------------------------- /modules/docker/manifests/params.pp: -------------------------------------------------------------------------------- 1 | # == Class: docker::params 2 | # 3 | # Defaut parameter values for the docker module 4 | # 5 | class docker::params { 6 | $version = undef 7 | $ensure = present 8 | $tcp_bind = undef 9 | $socket_bind = 'unix:///var/run/docker.sock' 10 | $use_upstream_package_source = true 11 | $service_state = running 12 | $service_enable = true 13 | $root_dir = undef 14 | $dns = undef 15 | case $::osfamily { 16 | 'Debian': { $package_source_location = 'https://get.docker.io/ubuntu' } 17 | default: { $package_source_location = '' } 18 | } 19 | $proxy = undef 20 | $no_proxy = undef 21 | $execdriver = undef 22 | } 23 | -------------------------------------------------------------------------------- /modules/docker/manifests/run_instance.pp: -------------------------------------------------------------------------------- 1 | # docker::run_instance 2 | class docker::run_instance($instance) { 3 | create_resources(docker::run, $instance) 4 | } 5 | -------------------------------------------------------------------------------- /modules/docker/spec/defines/image_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'docker::image', :type => :define do 4 | let(:title) { 'base' } 5 | it { should contain_exec('docker pull base') } 6 | 7 | context 'with ensure => absent' do 8 | let(:params) { { 'ensure' => 'absent' } } 9 | it { should contain_exec('docker rmi base') } 10 | end 11 | 12 | context 'with ensure => absent and image_tag => precise' do 13 | let(:params) { { 'ensure' => 'absent', 'image_tag' => 'precise' } } 14 | it { should contain_exec('docker rmi base:precise') } 15 | end 16 | 17 | context 'with ensure => present' do 18 | let(:params) { { 'ensure' => 'present' } } 19 | it { should contain_exec('docker pull base') } 20 | end 21 | 22 | context 'with ensure => present and image_tag => precise' do 23 | let(:params) { { 'ensure' => 'present', 'image_tag' => 'precise' } } 24 | it { should contain_exec('docker pull -t="precise" base') } 25 | end 26 | 27 | context 'with an invalid image name' do 28 | let(:title) { 'with spaces' } 29 | it do 30 | expect { 31 | should contain_exec('docker pull with spaces') 32 | }.to raise_error(Puppet::Error) 33 | end 34 | end 35 | 36 | context 'with an invalid ensure value' do 37 | let(:params) { { 'ensure' => 'not present or absent' } } 38 | it do 39 | expect { 40 | should contain_exec('docker rmi base') 41 | }.to raise_error(Puppet::Error) 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /modules/docker/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/module_spec_helper' 2 | -------------------------------------------------------------------------------- /modules/docker/spec/spec_helper_system.rb: -------------------------------------------------------------------------------- 1 | require 'rspec-system/spec_helper' 2 | require 'rspec-system-puppet/helpers' 3 | require 'rspec-system-serverspec/helpers' 4 | include RSpecSystemPuppet::Helpers 5 | 6 | RSpec.configure do |c| 7 | proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) 8 | c.tty = true 9 | c.include RSpecSystemPuppet::Helpers 10 | 11 | c.before :suite do 12 | puppet_install 13 | puppet_module_install(:source => proj_root, :module_name => 'docker') 14 | shell('puppet module install puppetlabs-stdlib') 15 | shell('puppet module install puppetlabs-apt') 16 | shell('puppet module install stahnma-epel') 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /modules/docker/spec/system/docker_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper_system' 2 | 3 | describe 'docker class' do 4 | 5 | context 'default parameters' do 6 | 7 | it 'should install without errors' do 8 | pp = <<-EOS 9 | class { 'docker': } 10 | EOS 11 | 12 | puppet_apply(pp) do |run| 13 | run.exit_code.should == 2 14 | run.refresh 15 | run.exit_code.should be_zero 16 | end 17 | end 18 | 19 | describe service('docker') do 20 | it { should be_enabled } 21 | it { should be_running } 22 | end 23 | 24 | describe command('sudo docker version') do 25 | it { should return_exit_status 0 } 26 | it { should return_stdout(/0\.7\./) } 27 | end 28 | 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /modules/docker/templates/etc/init/docker-run.conf.erb: -------------------------------------------------------------------------------- 1 | description "start and stop <%= @title %> in docker" 2 | author "Gareth Rushgrove" 3 | 4 | start on (started docker) 5 | stop on runlevel [!2345] 6 | 7 | setuid root 8 | 9 | respawn 10 | respawn limit 5 20 11 | 12 | exec docker run <% if @username %>-u '<%= @username %>' <% end %><% if @hostname %>-h '<%= @hostname %>'<% end %><% if @disable_network %> -n false<%end %><% if @dns %><% @dns_array.each do |address| %> -dns <%= address %><% end %><% end %><% if @env %><% @env_array.each do |env| %> -e <%= env %><% end %><% end %><% if @ports %><% @ports_array.each do |port| %> -p <%= port %><% end %><% end %><% if @volumes %><% @volumes_array.each do |volume| %> -v <%= volume %><% end %><% end %><% if @volumes_from %> -volumes-from <%= @volumes_from %><% end %> -m <%= @memory_limit %> <% if @links %><%= @links_array.map {|link| "-link #{link}" }.join(' ') %> <% end %><% if @use_name %>-name <%= @name %><% end %><% if @lxc_conf_array %><% @lxc_conf_array.each do |lxcconf| %> -lxc-conf="<%=lxcconf%>"<% end %><% end %> <%= @image %> <% if @command %><%= @command %><% end %> 13 | -------------------------------------------------------------------------------- /modules/docker/templates/etc/init/docker.conf.erb: -------------------------------------------------------------------------------- 1 | description "Run docker" 2 | 3 | start on filesystem or runlevel [2345] 4 | stop on runlevel [!2345] 5 | 6 | respawn 7 | 8 | script 9 | exec <% if @proxy %>http_proxy=<%= @proxy %> https_proxy=<%= @proxy %> <% end %><% if @no_proxy %>no_proxy=<%= @no_proxy %> <% end %>/usr/bin/docker -d <% if @root_dir %>-g <%= @root_dir %> <% end %><% if @execdriver %>-e <%= @execdriver %> <% end %><% if @tcp_bind %>-H <%= @tcp_bind %><% end %><% if @socket_bind %> -H <%= @socket_bind %><% end %> <% if @dns %> -dns <%= @dns %><% end %><% if @extra_parameters %><% @extra_parameters.each do |param| %> <%= param %><% end %><% end %> 10 | end script 11 | 12 | -------------------------------------------------------------------------------- /modules/docker/templates/etc/sysconfig/docker.erb: -------------------------------------------------------------------------------- 1 | other_args="<% if @root_dir %>-g <%= @root_dir %><% end %> <% if @tcp_bind %>-H <%= @tcp_bind %><% end %><% if @socket_bind %> -H <%= @socket_bind %><% end %><% if @extra_parameters %><% @extra_parameters.each do |param| %> <%= param %><% end %><% end %>" 2 | <% if @proxy %>export http_proxy=<%= @proxy %> 3 | export https_proxy=<%= @proxy %><% end %> 4 | <% if @no_proxy %>export no_proxy=<%= @no_proxy %><% end %> -------------------------------------------------------------------------------- /modules/docker/tests/base.pp: -------------------------------------------------------------------------------- 1 | include 'docker' 2 | -------------------------------------------------------------------------------- /modules/epel/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | group :development, :test do 4 | gem 'rake', :require => false 5 | gem 'rspec-puppet', :require => false 6 | gem 'puppetlabs_spec_helper', :require => false 7 | gem 'puppet-lint', :require => false 8 | gem 'rspec-system-puppet', '~>2.0.0' 9 | end 10 | 11 | if puppetversion = ENV['PUPPET_GEM_VERSION'] 12 | gem 'puppet', puppetversion, :require => false 13 | else 14 | gem 'puppet', :require => false 15 | end -------------------------------------------------------------------------------- /modules/epel/Modulefile: -------------------------------------------------------------------------------- 1 | name 'stahnma-epel' 2 | version '0.0.6' 3 | source 'http://github.com/stahnma/puppet-module-epel' 4 | author 'stahnma' 5 | license 'Apache License, Version 2.0' 6 | summary 'Setup the EPEL package repo' 7 | description 'Setup the EPEL package repo on Centos/RHEL et all' 8 | project_page 'http://github.com/stahnma/puppet-module-epel' 9 | -------------------------------------------------------------------------------- /modules/epel/Rakefile: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/rake_tasks' 2 | require 'puppet-lint/tasks/puppet-lint' 3 | require 'rspec-system/rake_task' 4 | 5 | task :default do 6 | sh %{rake -T} 7 | end 8 | 9 | # Disable specific puppet-lint checks 10 | PuppetLint.configuration.send("disable_80chars") 11 | PuppetLint.configuration.send("disable_class_inherits_from_params_class") 12 | 13 | desc "Run rspec-puppet and puppet-lint tasks" 14 | task :ci => [ 15 | :lint, 16 | :spec, 17 | ] 18 | -------------------------------------------------------------------------------- /modules/epel/lib/facter/os_maj_version.rb: -------------------------------------------------------------------------------- 1 | # This is a simple fact to get the Major version of an OS without having to 2 | # have the entire LSB suite installed. LSB seems to pull in about 300 megs of 3 | # stuff I often don't require. This fact is quick to load so it shouldn't be 4 | # much of an issue. 5 | 6 | Facter.add(:os_maj_version) do 7 | setcode do 8 | v = Facter.value(:operatingsystemrelease) 9 | v.split('.')[0].strip 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /modules/epel/manifests/rpm_gpg_key.pp: -------------------------------------------------------------------------------- 1 | # Define epel::rpm_gpg_key 2 | # 3 | # Actions: 4 | # Import a RPM gpg key 5 | # 6 | # Parameters: 7 | # 8 | # [*path*] 9 | # Path of the RPM GPG key to import 10 | # 11 | # Reqiures: 12 | # You should probably be on an Enterprise Linux variant. (Centos, RHEL, Scientific, Oracle, Ascendos, et al) 13 | # 14 | # Sample Usage: 15 | # epel::rpm_gpg_key{ "EPEL-6": 16 | # path => "/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6" 17 | # } 18 | # 19 | define epel::rpm_gpg_key($path) { 20 | # Given the path to a key, see if it is imported, if not, import it 21 | exec { "import-${name}": 22 | path => '/bin:/usr/bin:/sbin:/usr/sbin', 23 | command => "rpm --import ${path}", 24 | unless => "rpm -q gpg-pubkey-$(echo $(gpg --throw-keyids < ${path}) | cut --characters=11-18 | tr '[A-Z]' '[a-z]')", 25 | require => File[$path], 26 | logoutput => 'on_failure', 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /modules/epel/spec/classes/shared_base.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | shared_context :base do 4 | it do 5 | should contain_yumrepo('epel').with({ 6 | 'failovermethod' => 'priority', 7 | 'proxy' => 'absent', 8 | 'enabled' => '1', 9 | 'gpgcheck' => '1', 10 | }) 11 | end 12 | end 13 | 14 | shared_context :base_6 do 15 | include_context :base 16 | 17 | it do 18 | should contain_yumrepo('epel').with({ 19 | 'mirrorlist' => "http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=#{facts[:architecture]}", 20 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6", 21 | 'descr' => "Extra Packages for Enterprise Linux 6 - #{facts[:architecture]}", 22 | }) 23 | end 24 | end 25 | 26 | shared_context :base_5 do 27 | include_context :base 28 | 29 | it do 30 | should contain_yumrepo('epel').with({ 31 | 'mirrorlist' => "http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=#{facts[:architecture]}", 32 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5", 33 | 'descr' => "Extra Packages for Enterprise Linux 5 - #{facts[:architecture]}", 34 | }) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /modules/epel/spec/classes/shared_debuginfo.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | shared_context :epel_debuginfo do 4 | it do 5 | should contain_yumrepo('epel-debuginfo').with({ 6 | 'proxy' => 'absent', 7 | 'failovermethod' => 'priority', 8 | 'enabled' => '0', 9 | 'gpgcheck' => '1', 10 | }) 11 | end 12 | end 13 | 14 | shared_context :epel_debuginfo_6 do 15 | include_context :epel_debuginfo 16 | 17 | it do 18 | should contain_yumrepo('epel-debuginfo').with({ 19 | 'mirrorlist' => "http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-6&arch=#{facts[:architecture]}", 20 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6", 21 | 'descr' => "Extra Packages for Enterprise Linux 6 - #{facts[:architecture]} - Debug", 22 | }) 23 | end 24 | end 25 | 26 | shared_context :epel_debuginfo_5 do 27 | include_context :epel_debuginfo 28 | 29 | it do 30 | should contain_yumrepo('epel-debuginfo').with({ 31 | 'mirrorlist' => "http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=#{facts[:architecture]}", 32 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5", 33 | 'descr' => "Extra Packages for Enterprise Linux 5 - #{facts[:architecture]} - Debug", 34 | }) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /modules/epel/spec/classes/shared_gpgkey.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | shared_context :gpgkey_6 do 4 | it do 5 | should contain_file("/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6").with({ 6 | 'ensure' => 'present', 7 | 'owner' => 'root', 8 | 'group' => 'root', 9 | 'mode' => '0644', 10 | 'source' => "puppet:///modules/epel/RPM-GPG-KEY-EPEL-6", 11 | }) 12 | end 13 | 14 | it do 15 | should contain_epel__rpm_gpg_key("EPEL-6").with({ 16 | 'path' => "/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6" 17 | }) 18 | end 19 | end 20 | 21 | shared_context :gpgkey_5 do 22 | it do 23 | should contain_file("/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5").with({ 24 | 'ensure' => 'present', 25 | 'owner' => 'root', 26 | 'group' => 'root', 27 | 'mode' => '0644', 28 | 'source' => "puppet:///modules/epel/RPM-GPG-KEY-EPEL-5", 29 | }) 30 | end 31 | 32 | it do 33 | should contain_epel__rpm_gpg_key("EPEL-5").with({ 34 | 'path' => "/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5" 35 | }) 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /modules/epel/spec/classes/shared_source.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | shared_context :epel_source do 4 | it do 5 | should contain_yumrepo('epel-source').with({ 6 | 'proxy' => 'absent', 7 | 'failovermethod' => 'priority', 8 | 'enabled' => '0', 9 | 'gpgcheck' => '1', 10 | }) 11 | end 12 | end 13 | 14 | shared_context :epel_source_6 do 15 | include_context :epel_source 16 | 17 | it do 18 | should contain_yumrepo('epel-source').with({ 19 | 'mirrorlist' => "http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-6&arch=#{facts[:architecture]}", 20 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6", 21 | 'descr' => "Extra Packages for Enterprise Linux 6 - #{facts[:architecture]} - Source", 22 | }) 23 | end 24 | end 25 | 26 | shared_context :epel_source_5 do 27 | include_context :epel_source 28 | 29 | it do 30 | should contain_yumrepo('epel-source').with({ 31 | 'mirrorlist' => "http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=#{facts[:architecture]}", 32 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5", 33 | 'descr' => "Extra Packages for Enterprise Linux 5 - #{facts[:architecture]} - Source", 34 | }) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /modules/epel/spec/classes/shared_testing.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | shared_context :epel_testing do 4 | it do 5 | should contain_yumrepo('epel-testing').with({ 6 | 'failovermethod' => 'priority', 7 | 'proxy' => 'absent', 8 | 'enabled' => '0', 9 | 'gpgcheck' => '1', 10 | }) 11 | end 12 | end 13 | 14 | shared_context :epel_testing_6 do 15 | include_context :epel_testing 16 | 17 | it do 18 | should contain_yumrepo('epel-testing').with({ 19 | 'baseurl' => "http://download.fedoraproject.org/pub/epel/testing/6/#{facts[:architecture]}", 20 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6", 21 | 'descr' => "Extra Packages for Enterprise Linux 6 - Testing - #{facts[:architecture]} ", 22 | }) 23 | end 24 | end 25 | 26 | shared_context :epel_testing_5 do 27 | include_context :epel_testing 28 | 29 | it do 30 | should contain_yumrepo('epel-testing').with({ 31 | 'baseurl' => "http://download.fedoraproject.org/pub/epel/testing/5/#{facts[:architecture]}", 32 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5", 33 | 'descr' => "Extra Packages for Enterprise Linux 5 - Testing - #{facts[:architecture]} ", 34 | }) 35 | end 36 | end -------------------------------------------------------------------------------- /modules/epel/spec/classes/shared_testing_debuginfo.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | shared_context :epel_testing_debuginfo do 4 | it do 5 | should contain_yumrepo('epel-testing-debuginfo').with({ 6 | 'failovermethod' => 'priority', 7 | 'proxy' => 'absent', 8 | 'enabled' => '0', 9 | 'gpgcheck' => '1', 10 | }) 11 | end 12 | end 13 | 14 | shared_context :epel_testing_debuginfo_6 do 15 | include_context :epel_testing_debuginfo 16 | 17 | it do 18 | should contain_yumrepo('epel-testing-debuginfo').with({ 19 | 'baseurl' => "http://download.fedoraproject.org/pub/epel/testing/6/#{facts[:architecture]}/debug", 20 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6", 21 | 'descr' => "Extra Packages for Enterprise Linux 6 - Testing - #{facts[:architecture]} - Debug", 22 | }) 23 | end 24 | end 25 | 26 | shared_context :epel_testing_debuginfo_5 do 27 | include_context :epel_testing_debuginfo 28 | 29 | it do 30 | should contain_yumrepo('epel-testing-debuginfo').with({ 31 | 'baseurl' => "http://download.fedoraproject.org/pub/epel/testing/5/#{facts[:architecture]}/debug", 32 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5", 33 | 'descr' => "Extra Packages for Enterprise Linux 5 - Testing - #{facts[:architecture]} - Debug", 34 | }) 35 | end 36 | end -------------------------------------------------------------------------------- /modules/epel/spec/classes/shared_testing_source.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | shared_context :epel_testing_source do 4 | it do 5 | should contain_yumrepo('epel-testing-source').with({ 6 | 'failovermethod' => 'priority', 7 | 'proxy' => 'absent', 8 | 'enabled' => '0', 9 | 'gpgcheck' => '1', 10 | }) 11 | end 12 | end 13 | 14 | shared_context :epel_testing_source_6 do 15 | include_context :epel_testing_source 16 | 17 | it do 18 | should contain_yumrepo('epel-testing-source').with({ 19 | 'baseurl' => "http://download.fedoraproject.org/pub/epel/testing/6/SRPMS", 20 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6", 21 | 'descr' => "Extra Packages for Enterprise Linux 6 - Testing - #{facts[:architecture]} - Source", 22 | }) 23 | end 24 | end 25 | 26 | shared_context :epel_testing_source_5 do 27 | include_context :epel_testing_source 28 | 29 | it do 30 | should contain_yumrepo('epel-testing-source').with({ 31 | 'baseurl' => "http://download.fedoraproject.org/pub/epel/testing/5/SRPMS", 32 | 'gpgkey' => "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-5", 33 | 'descr' => "Extra Packages for Enterprise Linux 5 - Testing - #{facts[:architecture]} - Source", 34 | }) 35 | end 36 | end -------------------------------------------------------------------------------- /modules/epel/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/module_spec_helper' 2 | 3 | def default_facts 4 | { 5 | :osfamily => 'RedHat', 6 | :operatingsystem => 'CentOS', 7 | :architecture => 'x86_64', 8 | } 9 | end 10 | -------------------------------------------------------------------------------- /modules/epel/spec/spec_helper_system.rb: -------------------------------------------------------------------------------- 1 | require 'rspec-system/spec_helper' 2 | require 'rspec-system-puppet/helpers' 3 | 4 | include RSpecSystemPuppet::Helpers 5 | 6 | RSpec.configure do |c| 7 | # Project root for the this module's code 8 | proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) 9 | 10 | # Enable colour in Jenkins 11 | c.tty = true 12 | 13 | c.include RSpecSystemPuppet::Helpers 14 | 15 | # This is where we 'setup' the nodes before running our tests 16 | c.before :suite do 17 | # Install puppet 18 | puppet_install 19 | puppet_master_install 20 | 21 | puppet_module_install(:source => proj_root, :module_name => 'epel') 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /modules/epel/spec/system/basic_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper_system' 2 | 3 | describe 'epel class:' do 4 | context puppet_agent do 5 | its(:stderr) { should be_empty } 6 | its(:exit_code) { should_not == 1 } 7 | end 8 | 9 | # Verify the os_maj_version fact is working 10 | context shell 'facter --puppet os_maj_version' do 11 | its(:stdout) { should_not be_empty } 12 | its(:stderr) { should be_empty } 13 | its(:exit_code) { should be_zero } 14 | end 15 | 16 | pp = "class { 'epel': }" 17 | 18 | context puppet_apply pp do 19 | its(:stderr) { should be_empty } 20 | its(:exit_code) { should_not == 1 } 21 | its(:refresh) { should be_nil } 22 | its(:stderr) { should be_empty } 23 | its(:exit_code) { should be_zero } 24 | end 25 | 26 | context 'test EPEL repo presence' do 27 | facts = node.facts 28 | 29 | # Only test for EPEL's presence if not Fedora 30 | if facts['operatingsystem'] !~ /Fedora/ 31 | context shell '/usr/bin/yum-config-manager epel | grep -q "\[epel\]"' do 32 | its(:exit_code) { should be_zero } 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /modules/epel/spec/unit/facter/os_maj_version_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'os_maj_version fact' do 4 | before :each do 5 | Facter.clear 6 | end 7 | 8 | context "on 5.9 operatingsystemrelease" do 9 | it "should have os_maj_version => 5" do 10 | Facter.fact(:operatingsystemrelease).stubs(:value).returns("5.9") 11 | Facter.fact(:os_maj_version).value.should == "5" 12 | end 13 | end 14 | 15 | context "on 6.4 operatingsystemrelease" do 16 | it "should have os_maj_version => 6" do 17 | Facter.fact(:operatingsystemrelease).stubs(:value).returns("6.4") 18 | Facter.fact(:os_maj_version).value.should == "6" 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /modules/epel/tests/init.pp: -------------------------------------------------------------------------------- 1 | # And by test, I mean, run this thing for me using Puppet apply and I'll check 2 | # it out. 3 | include 'epel' 4 | -------------------------------------------------------------------------------- /modules/stdlib/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | def location_for(place, fake_version = nil) 4 | mdata = /^(git:[^#]*)#(.*)/.match(place) 5 | if mdata 6 | [fake_version, { :git => mdata[1], :branch => mdata[2], :require => false }].compact 7 | elsif place =~ /^file:\/\/(.*)/ 8 | ['>= 0', { :path => File.expand_path(mdata[1]), :require => false }] 9 | else 10 | [place, { :require => false }] 11 | end 12 | end 13 | 14 | group :development do 15 | gem 'watchr' 16 | end 17 | 18 | group :development, :test do 19 | gem 'rake' 20 | gem 'puppetmodule-stdlib', ">= 1.0.0", :path => File.expand_path("..", __FILE__) 21 | gem 'rspec', "~> 2.11.0", :require => false 22 | gem 'mocha', "~> 0.10.5", :require => false 23 | gem 'puppetlabs_spec_helper', :require => false 24 | gem 'rspec-puppet', :require => false 25 | end 26 | 27 | facterversion = ENV['GEM_FACTER_VERSION'] 28 | if facterversion 29 | gem 'facter', *location_for(facterversion) 30 | else 31 | gem 'facter', :require => false 32 | end 33 | 34 | ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION'] 35 | puppetversion = ENV['GEM_PUPPET_VERSION'] 36 | if puppetversion 37 | gem 'puppet', *location_for(puppetversion) 38 | else 39 | gem 'puppet', :require => false 40 | end 41 | 42 | # vim:ft=ruby 43 | -------------------------------------------------------------------------------- /modules/stdlib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2011 Puppet Labs Inc 2 | 3 | and some parts: 4 | 5 | Copyright (C) 2011 Krzysztof Wilczynski 6 | 7 | Puppet Labs can be contacted at: info@puppetlabs.com 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | -------------------------------------------------------------------------------- /modules/stdlib/Modulefile: -------------------------------------------------------------------------------- 1 | name 'puppetlabs-stdlib' 2 | version '4.1.0' 3 | source 'git://github.com/puppetlabs/puppetlabs-stdlib.git' 4 | author 'puppetlabs' 5 | license 'Apache 2.0' 6 | summary 'Puppet Module Standard Library' 7 | description 'Standard Library for Puppet Modules' 8 | project_page 'https://github.com/puppetlabs/puppetlabs-stdlib' 9 | 10 | ## Add dependencies, if any: 11 | # dependency 'username/name', '>= 1.2.0' 12 | -------------------------------------------------------------------------------- /modules/stdlib/README_SPECS.markdown: -------------------------------------------------------------------------------- 1 | NOTE 2 | ==== 3 | 4 | This project's specs depend on puppet core, and thus they require the 5 | `puppetlabs_spec_helper` project. For more information please see the README 6 | in that project, which can be found here: [puppetlabs spec 7 | helper](https://github.com/puppetlabs/puppetlabs_spec_helper) 8 | -------------------------------------------------------------------------------- /modules/stdlib/RELEASE_PROCESS.markdown: -------------------------------------------------------------------------------- 1 | # Contributing to this module # 2 | 3 | * Work in a topic branch 4 | * Submit a github pull request 5 | * Address any comments / feeback 6 | * Merge into master using --no-ff 7 | 8 | # Releasing this module # 9 | 10 | * This module adheres to http://semver.org/ 11 | * Look for API breaking changes using git diff vX.Y.Z..master 12 | * If no API breaking changes, the minor version may be bumped. 13 | * If there are API breaking changes, the major version must be bumped. 14 | * If there are only small minor changes, the patch version may be bumped. 15 | * Update the CHANGELOG 16 | * Update the Modulefile 17 | * Commit these changes with a message along the lines of "Update CHANGELOG and 18 | Modulefile for release" 19 | * Create an annotated tag with git tag -a vX.Y.Z -m 'version X.Y.Z' (NOTE the 20 | leading v as per semver.org) 21 | * Push the tag with git push origin --tags 22 | * Build a new package with puppet-module or the rake build task if it exists 23 | * Publish the new package to the forge 24 | * Bonus points for an announcement to puppet-users. 25 | -------------------------------------------------------------------------------- /modules/stdlib/Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'puppetlabs_spec_helper/rake_tasks' 3 | -------------------------------------------------------------------------------- /modules/stdlib/lib/facter/pe_version.rb: -------------------------------------------------------------------------------- 1 | # Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version 2 | # 3 | # Purpose: Return various facts about the PE state of the system 4 | # 5 | # Resolution: Uses a regex match against puppetversion to determine whether the 6 | # machine has Puppet Enterprise installed, and what version (overall, major, 7 | # minor, patch) is installed. 8 | # 9 | # Caveats: 10 | # 11 | Facter.add("pe_version") do 12 | setcode do 13 | pe_ver = Facter.value("puppetversion").match(/Puppet Enterprise (\d+\.\d+\.\d+)/) 14 | pe_ver[1] if pe_ver 15 | end 16 | end 17 | 18 | Facter.add("is_pe") do 19 | setcode do 20 | if Facter.value(:pe_version).to_s.empty? then 21 | false 22 | else 23 | true 24 | end 25 | end 26 | end 27 | 28 | Facter.add("pe_major_version") do 29 | confine :is_pe => true 30 | setcode do 31 | if pe_version = Facter.value(:pe_version) 32 | pe_version.to_s.split('.')[0] 33 | end 34 | end 35 | end 36 | 37 | Facter.add("pe_minor_version") do 38 | confine :is_pe => true 39 | setcode do 40 | if pe_version = Facter.value(:pe_version) 41 | pe_version.to_s.split('.')[1] 42 | end 43 | end 44 | end 45 | 46 | Facter.add("pe_patch_version") do 47 | confine :is_pe => true 48 | setcode do 49 | if pe_version = Facter.value(:pe_version) 50 | pe_version.to_s.split('.')[2] 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /modules/stdlib/lib/facter/puppet_vardir.rb: -------------------------------------------------------------------------------- 1 | # This facter fact returns the value of the Puppet vardir setting for the node 2 | # running puppet or puppet agent. The intent is to enable Puppet modules to 3 | # automatically have insight into a place where they can place variable data, 4 | # regardless of the node's platform. 5 | # 6 | # The value should be directly usable in a File resource path attribute. 7 | 8 | 9 | begin 10 | require 'facter/util/puppet_settings' 11 | rescue LoadError => e 12 | # puppet apply does not add module lib directories to the $LOAD_PATH (See 13 | # #4248). It should (in the future) but for the time being we need to be 14 | # defensive which is what this rescue block is doing. 15 | rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb') 16 | load rb_file if File.exists?(rb_file) or raise e 17 | end 18 | 19 | Facter.add(:puppet_vardir) do 20 | setcode do 21 | # This will be nil if Puppet is not available. 22 | Facter::Util::PuppetSettings.with_puppet do 23 | Puppet[:vardir] 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /modules/stdlib/lib/facter/root_home.rb: -------------------------------------------------------------------------------- 1 | # A facter fact to determine the root home directory. 2 | # This varies on PE supported platforms and may be 3 | # reconfigured by the end user. 4 | 5 | module Facter::Util::RootHome 6 | class << self 7 | def get_root_home 8 | root_ent = Facter::Util::Resolution.exec("getent passwd root") 9 | # The home directory is the sixth element in the passwd entry 10 | # If the platform doesn't have getent, root_ent will be nil and we should 11 | # return it straight away. 12 | root_ent && root_ent.split(":")[5] 13 | end 14 | end 15 | end 16 | 17 | Facter.add(:root_home) do 18 | setcode { Facter::Util::RootHome.get_root_home } 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/lib/facter/util/puppet_settings.rb: -------------------------------------------------------------------------------- 1 | module Facter 2 | module Util 3 | module PuppetSettings 4 | # This method is intended to provide a convenient way to evaluate a 5 | # Facter code block only if Puppet is loaded. This is to account for the 6 | # situation where the fact happens to be in the load path, but Puppet is 7 | # not loaded for whatever reason. Perhaps the user is simply running 8 | # facter without the --puppet flag and they happen to be working in a lib 9 | # directory of a module. 10 | def self.with_puppet 11 | begin 12 | Module.const_get("Puppet") 13 | rescue NameError 14 | nil 15 | else 16 | yield 17 | end 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/abs.rb: -------------------------------------------------------------------------------- 1 | # 2 | # abs.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:abs, :type => :rvalue, :doc => <<-EOS 7 | Returns the absolute value of a number, for example -34.56 becomes 8 | 34.56. Takes a single integer and float value as an argument. 9 | EOS 10 | ) do |arguments| 11 | 12 | raise(Puppet::ParseError, "abs(): Wrong number of arguments " + 13 | "given (#{arguments.size} for 1)") if arguments.size < 1 14 | 15 | value = arguments[0] 16 | 17 | # Numbers in Puppet are often string-encoded which is troublesome ... 18 | if value.is_a?(String) 19 | if value.match(/^-?(?:\d+)(?:\.\d+){1}$/) 20 | value = value.to_f 21 | elsif value.match(/^-?\d+$/) 22 | value = value.to_i 23 | else 24 | raise(Puppet::ParseError, 'abs(): Requires float or ' + 25 | 'integer to work with') 26 | end 27 | end 28 | 29 | # We have numeric value to handle ... 30 | result = value.abs 31 | 32 | return result 33 | end 34 | end 35 | 36 | # vim: set ts=2 sw=2 et : 37 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/any2array.rb: -------------------------------------------------------------------------------- 1 | # 2 | # any2array.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:any2array, :type => :rvalue, :doc => <<-EOS 7 | This converts any object to an array containing that object. Empty argument 8 | lists are converted to an empty array. Arrays are left untouched. Hashes are 9 | converted to arrays of alternating keys and values. 10 | EOS 11 | ) do |arguments| 12 | 13 | if arguments.empty? 14 | return [] 15 | end 16 | 17 | if arguments.length == 1 18 | if arguments[0].kind_of?(Array) 19 | return arguments[0] 20 | elsif arguments[0].kind_of?(Hash) 21 | result = [] 22 | arguments[0].each do |key, value| 23 | result << key << value 24 | end 25 | return result 26 | end 27 | end 28 | 29 | return arguments 30 | end 31 | end 32 | 33 | # vim: set ts=2 sw=2 et : 34 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/capitalize.rb: -------------------------------------------------------------------------------- 1 | # 2 | # capitalize.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS 7 | Capitalizes the first letter of a string or array of strings. 8 | Requires either a single string or an array as an input. 9 | EOS 10 | ) do |arguments| 11 | 12 | raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " + 13 | "given (#{arguments.size} for 1)") if arguments.size < 1 14 | 15 | value = arguments[0] 16 | klass = value.class 17 | 18 | unless [Array, String].include?(klass) 19 | raise(Puppet::ParseError, 'capitalize(): Requires either ' + 20 | 'array or string to work with') 21 | end 22 | 23 | if value.is_a?(Array) 24 | # Numbers in Puppet are often string-encoded which is troublesome ... 25 | result = value.collect { |i| i.is_a?(String) ? i.capitalize : i } 26 | else 27 | result = value.capitalize 28 | end 29 | 30 | return result 31 | end 32 | end 33 | 34 | # vim: set ts=2 sw=2 et : 35 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/chomp.rb: -------------------------------------------------------------------------------- 1 | # 2 | # chomp.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS' 7 | Removes the record separator from the end of a string or an array of 8 | strings, for example `hello\n` becomes `hello`. 9 | Requires a single string or array as an input. 10 | EOS 11 | ) do |arguments| 12 | 13 | raise(Puppet::ParseError, "chomp(): Wrong number of arguments " + 14 | "given (#{arguments.size} for 1)") if arguments.size < 1 15 | 16 | value = arguments[0] 17 | klass = value.class 18 | 19 | unless [Array, String].include?(klass) 20 | raise(Puppet::ParseError, 'chomp(): Requires either ' + 21 | 'array or string to work with') 22 | end 23 | 24 | if value.is_a?(Array) 25 | # Numbers in Puppet are often string-encoded which is troublesome ... 26 | result = value.collect { |i| i.is_a?(String) ? i.chomp : i } 27 | else 28 | result = value.chomp 29 | end 30 | 31 | return result 32 | end 33 | end 34 | 35 | # vim: set ts=2 sw=2 et : 36 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/chop.rb: -------------------------------------------------------------------------------- 1 | # 2 | # chop.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:chop, :type => :rvalue, :doc => <<-'EOS' 7 | Returns a new string with the last character removed. If the string ends 8 | with `\r\n`, both characters are removed. Applying chop to an empty 9 | string returns an empty string. If you wish to merely remove record 10 | separators then you should use the `chomp` function. 11 | Requires a string or array of strings as input. 12 | EOS 13 | ) do |arguments| 14 | 15 | raise(Puppet::ParseError, "chop(): Wrong number of arguments " + 16 | "given (#{arguments.size} for 1)") if arguments.size < 1 17 | 18 | value = arguments[0] 19 | klass = value.class 20 | 21 | unless [Array, String].include?(klass) 22 | raise(Puppet::ParseError, 'chop(): Requires either an ' + 23 | 'array or string to work with') 24 | end 25 | 26 | if value.is_a?(Array) 27 | # Numbers in Puppet are often string-encoded which is troublesome ... 28 | result = value.collect { |i| i.is_a?(String) ? i.chop : i } 29 | else 30 | result = value.chop 31 | end 32 | 33 | return result 34 | end 35 | end 36 | 37 | # vim: set ts=2 sw=2 et : 38 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/concat.rb: -------------------------------------------------------------------------------- 1 | # 2 | # concat.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:concat, :type => :rvalue, :doc => <<-EOS 7 | Appends the contents of array 2 onto array 1. 8 | 9 | *Example:* 10 | 11 | concat(['1','2','3'],['4','5','6']) 12 | 13 | Would result in: 14 | 15 | ['1','2','3','4','5','6'] 16 | EOS 17 | ) do |arguments| 18 | 19 | # Check that 2 arguments have been given ... 20 | raise(Puppet::ParseError, "concat(): Wrong number of arguments " + 21 | "given (#{arguments.size} for 2)") if arguments.size != 2 22 | 23 | a = arguments[0] 24 | b = arguments[1] 25 | 26 | # Check that both args are arrays. 27 | unless a.is_a?(Array) and b.is_a?(Array) 28 | raise(Puppet::ParseError, 'concat(): Requires array to work with') 29 | end 30 | 31 | result = a.concat(b) 32 | 33 | return result 34 | end 35 | end 36 | 37 | # vim: set ts=2 sw=2 et : 38 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/count.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-EOS 3 | Takes an array as first argument and an optional second argument. 4 | Count the number of elements in array that matches second argument. 5 | If called with only an array it counts the number of elements that are not nil/undef. 6 | EOS 7 | ) do |args| 8 | 9 | if (args.size > 2) then 10 | raise(ArgumentError, "count(): Wrong number of arguments "+ 11 | "given #{args.size} for 1 or 2.") 12 | end 13 | 14 | collection, item = args 15 | 16 | if item then 17 | collection.count item 18 | else 19 | collection.count { |obj| obj != nil && obj != :undef && obj != '' } 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb: -------------------------------------------------------------------------------- 1 | # Test whether a given class or definition is defined 2 | require 'puppet/parser/functions' 3 | 4 | Puppet::Parser::Functions.newfunction(:defined_with_params, 5 | :type => :rvalue, 6 | :doc => <<-'ENDOFDOC' 7 | Takes a resource reference and an optional hash of attributes. 8 | 9 | Returns true if a resource with the specified attributes has already been added 10 | to the catalog, and false otherwise. 11 | 12 | user { 'dan': 13 | ensure => present, 14 | } 15 | 16 | if ! defined_with_params(User[dan], {'ensure' => 'present' }) { 17 | user { 'dan': ensure => present, } 18 | } 19 | ENDOFDOC 20 | ) do |vals| 21 | reference, params = vals 22 | raise(ArgumentError, 'Must specify a reference') unless reference 23 | if (! params) || params == '' 24 | params = {} 25 | end 26 | ret = false 27 | if resource = findresource(reference.to_s) 28 | matches = params.collect do |key, value| 29 | resource[key] == value 30 | end 31 | ret = params.empty? || !matches.include?(false) 32 | end 33 | Puppet.debug("Resource #{reference} was not determined to be defined") 34 | ret 35 | end 36 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/delete.rb: -------------------------------------------------------------------------------- 1 | # 2 | # delete.rb 3 | # 4 | 5 | # TODO(Krzysztof Wilczynski): We need to add support for regular expression ... 6 | 7 | module Puppet::Parser::Functions 8 | newfunction(:delete, :type => :rvalue, :doc => <<-EOS 9 | Deletes all instances of a given element from an array, substring from a 10 | string, or key from a hash. 11 | 12 | *Examples:* 13 | 14 | delete(['a','b','c','b'], 'b') 15 | Would return: ['a','c'] 16 | 17 | delete({'a'=>1,'b'=>2,'c'=>3}, 'b') 18 | Would return: {'a'=>1,'c'=>3} 19 | 20 | delete('abracadabra', 'bra') 21 | Would return: 'acada' 22 | EOS 23 | ) do |arguments| 24 | 25 | if (arguments.size != 2) then 26 | raise(Puppet::ParseError, "delete(): Wrong number of arguments "+ 27 | "given #{arguments.size} for 2.") 28 | end 29 | 30 | collection = arguments[0] 31 | item = arguments[1] 32 | 33 | case collection 34 | when Array, Hash 35 | collection.delete item 36 | when String 37 | collection.gsub! item, '' 38 | else 39 | raise(TypeError, "delete(): First argument must be an Array, " + 40 | "String, or Hash. Given an argument of class #{collection.class}.") 41 | end 42 | collection 43 | end 44 | end 45 | 46 | # vim: set ts=2 sw=2 et : 47 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/delete_at.rb: -------------------------------------------------------------------------------- 1 | # 2 | # delete_at.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS 7 | Deletes a determined indexed value from an array. 8 | 9 | *Examples:* 10 | 11 | delete_at(['a','b','c'], 1) 12 | 13 | Would return: ['a','c'] 14 | EOS 15 | ) do |arguments| 16 | 17 | raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " + 18 | "given (#{arguments.size} for 2)") if arguments.size < 2 19 | 20 | array = arguments[0] 21 | 22 | unless array.is_a?(Array) 23 | raise(Puppet::ParseError, 'delete_at(): Requires array to work with') 24 | end 25 | 26 | index = arguments[1] 27 | 28 | if index.is_a?(String) and not index.match(/^\d+$/) 29 | raise(Puppet::ParseError, 'delete_at(): You must provide ' + 30 | 'non-negative numeric index') 31 | end 32 | 33 | result = array.clone 34 | 35 | # Numbers in Puppet are often string-encoded which is troublesome ... 36 | index = index.to_i 37 | 38 | if index > result.size - 1 # First element is at index 0 is it not? 39 | raise(Puppet::ParseError, 'delete_at(): Given index ' + 40 | 'exceeds size of array given') 41 | end 42 | 43 | result.delete_at(index) # We ignore the element that got deleted ... 44 | 45 | return result 46 | end 47 | end 48 | 49 | # vim: set ts=2 sw=2 et : 50 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/dirname.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | newfunction(:dirname, :type => :rvalue, :doc => <<-EOS 3 | Returns the dirname of a path. 4 | EOS 5 | ) do |arguments| 6 | 7 | raise(Puppet::ParseError, "dirname(): Wrong number of arguments " + 8 | "given (#{arguments.size} for 1)") if arguments.size < 1 9 | 10 | path = arguments[0] 11 | return File.dirname(path) 12 | end 13 | end 14 | 15 | # vim: set ts=2 sw=2 et : 16 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/downcase.rb: -------------------------------------------------------------------------------- 1 | # 2 | # downcase.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:downcase, :type => :rvalue, :doc => <<-EOS 7 | Converts the case of a string or all strings in an array to lower case. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "downcase(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size < 1 13 | 14 | value = arguments[0] 15 | klass = value.class 16 | 17 | unless [Array, String].include?(klass) 18 | raise(Puppet::ParseError, 'downcase(): Requires either ' + 19 | 'array or string to work with') 20 | end 21 | 22 | if value.is_a?(Array) 23 | # Numbers in Puppet are often string-encoded which is troublesome ... 24 | result = value.collect { |i| i.is_a?(String) ? i.downcase : i } 25 | else 26 | result = value.downcase 27 | end 28 | 29 | return result 30 | end 31 | end 32 | 33 | # vim: set ts=2 sw=2 et : 34 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/empty.rb: -------------------------------------------------------------------------------- 1 | # 2 | # empty.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:empty, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the variable is empty. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "empty(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size < 1 13 | 14 | value = arguments[0] 15 | klass = value.class 16 | 17 | unless [Array, Hash, String].include?(klass) 18 | raise(Puppet::ParseError, 'empty(): Requires either ' + 19 | 'array, hash or string to work with') 20 | end 21 | 22 | result = value.empty? 23 | 24 | return result 25 | end 26 | end 27 | 28 | # vim: set ts=2 sw=2 et : 29 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb: -------------------------------------------------------------------------------- 1 | # 2 | # ensure_packages.rb 3 | # 4 | require 'puppet/parser/functions' 5 | 6 | module Puppet::Parser::Functions 7 | newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS 8 | Takes a list of packages and only installs them if they don't already exist. 9 | EOS 10 | ) do |arguments| 11 | 12 | raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " + 13 | "given (#{arguments.size} for 1)") if arguments.size != 1 14 | raise(Puppet::ParseError, "ensure_packages(): Requires array " + 15 | "given (#{arguments[0].class})") if !arguments[0].kind_of?(Array) 16 | 17 | Puppet::Parser::Functions.function(:ensure_resource) 18 | arguments[0].each { |package_name| 19 | function_ensure_resource(['package', package_name, {'ensure' => 'present' } ]) 20 | } 21 | end 22 | end 23 | 24 | # vim: set ts=2 sw=2 et : 25 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/flatten.rb: -------------------------------------------------------------------------------- 1 | # 2 | # flatten.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:flatten, :type => :rvalue, :doc => <<-EOS 7 | This function flattens any deeply nested arrays and returns a single flat array 8 | as a result. 9 | 10 | *Examples:* 11 | 12 | flatten(['a', ['b', ['c']]]) 13 | 14 | Would return: ['a','b','c'] 15 | EOS 16 | ) do |arguments| 17 | 18 | raise(Puppet::ParseError, "flatten(): Wrong number of arguments " + 19 | "given (#{arguments.size} for 1)") if arguments.size != 1 20 | 21 | array = arguments[0] 22 | 23 | unless array.is_a?(Array) 24 | raise(Puppet::ParseError, 'flatten(): Requires array to work with') 25 | end 26 | 27 | result = array.flatten 28 | 29 | return result 30 | end 31 | end 32 | 33 | # vim: set ts=2 sw=2 et : 34 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/floor.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | newfunction(:floor, :type => :rvalue, :doc => <<-EOS 3 | Returns the largest integer less or equal to the argument. 4 | Takes a single numeric value as an argument. 5 | EOS 6 | ) do |arguments| 7 | 8 | raise(Puppet::ParseError, "floor(): Wrong number of arguments " + 9 | "given (#{arguments.size} for 1)") if arguments.size != 1 10 | 11 | arg = arguments[0] 12 | 13 | raise(Puppet::ParseError, "floor(): Wrong argument type " + 14 | "given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false 15 | 16 | arg.floor 17 | end 18 | end 19 | 20 | # vim: set ts=2 sw=2 et : 21 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb: -------------------------------------------------------------------------------- 1 | # 2 | # fqdn_rotate.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:fqdn_rotate, :type => :rvalue, :doc => <<-EOS 7 | Rotates an array a random number of times based on a nodes fqdn. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size < 1 13 | 14 | value = arguments[0] 15 | klass = value.class 16 | require 'digest/md5' 17 | 18 | unless [Array, String].include?(klass) 19 | raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' + 20 | 'array or string to work with') 21 | end 22 | 23 | result = value.clone 24 | 25 | string = value.is_a?(String) ? true : false 26 | 27 | # Check whether it makes sense to rotate ... 28 | return result if result.size <= 1 29 | 30 | # We turn any string value into an array to be able to rotate ... 31 | result = string ? result.split('') : result 32 | 33 | elements = result.size 34 | 35 | srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),arguments].join(':')).hex) 36 | rand(elements).times { 37 | result.push result.shift 38 | } 39 | 40 | result = string ? result.join : result 41 | 42 | return result 43 | end 44 | end 45 | 46 | # vim: set ts=2 sw=2 et : 47 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/get_module_path.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | newfunction(:get_module_path, :type =>:rvalue, :doc => <<-EOT 3 | Returns the absolute path of the specified module for the current 4 | environment. 5 | 6 | Example: 7 | $module_path = get_module_path('stdlib') 8 | EOT 9 | ) do |args| 10 | raise(Puppet::ParseError, "get_module_path(): Wrong number of arguments, expects one") unless args.size == 1 11 | if module_path = Puppet::Module.find(args[0], compiler.environment.to_s) 12 | module_path.path 13 | else 14 | raise(Puppet::ParseError, "Could not find module #{args[0]} in environment #{compiler.environment}") 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/getparam.rb: -------------------------------------------------------------------------------- 1 | # Test whether a given class or definition is defined 2 | require 'puppet/parser/functions' 3 | 4 | Puppet::Parser::Functions.newfunction(:getparam, 5 | :type => :rvalue, 6 | :doc => <<-'ENDOFDOC' 7 | Takes a resource reference and name of the parameter and 8 | returns value of resource's parameter. 9 | 10 | *Examples:* 11 | 12 | define example_resource($param) { 13 | } 14 | 15 | example_resource { "example_resource_instance": 16 | param => "param_value" 17 | } 18 | 19 | getparam(Example_resource["example_resource_instance"], "param") 20 | 21 | Would return: param_value 22 | ENDOFDOC 23 | ) do |vals| 24 | reference, param = vals 25 | raise(ArgumentError, 'Must specify a reference') unless reference 26 | raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String 27 | 28 | return '' if param.empty? 29 | 30 | if resource = findresource(reference.to_s) 31 | return resource[param] if resource[param] 32 | end 33 | 34 | return '' 35 | end 36 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/getvar.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | 3 | newfunction(:getvar, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| 4 | Lookup a variable in a remote namespace. 5 | 6 | For example: 7 | 8 | $foo = getvar('site::data::foo') 9 | # Equivalent to $foo = $site::data::foo 10 | 11 | This is useful if the namespace itself is stored in a string: 12 | 13 | $datalocation = 'site::data' 14 | $bar = getvar("${datalocation}::bar") 15 | # Equivalent to $bar = $site::data::bar 16 | ENDHEREDOC 17 | 18 | unless args.length == 1 19 | raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)") 20 | end 21 | 22 | self.lookupvar("#{args[0]}") 23 | 24 | end 25 | 26 | end 27 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/grep.rb: -------------------------------------------------------------------------------- 1 | # 2 | # grep.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:grep, :type => :rvalue, :doc => <<-EOS 7 | This function searches through an array and returns any elements that match 8 | the provided regular expression. 9 | 10 | *Examples:* 11 | 12 | grep(['aaa','bbb','ccc','aaaddd'], 'aaa') 13 | 14 | Would return: 15 | 16 | ['aaa','aaaddd'] 17 | EOS 18 | ) do |arguments| 19 | 20 | if (arguments.size != 2) then 21 | raise(Puppet::ParseError, "grep(): Wrong number of arguments "+ 22 | "given #{arguments.size} for 2") 23 | end 24 | 25 | a = arguments[0] 26 | pattern = Regexp.new(arguments[1]) 27 | 28 | a.grep(pattern) 29 | 30 | end 31 | end 32 | 33 | # vim: set ts=2 sw=2 et : 34 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb: -------------------------------------------------------------------------------- 1 | # 2 | # has_interface_with 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:has_interface_with, :type => :rvalue, :doc => <<-EOS 7 | Returns boolean based on kind and value: 8 | * macaddress 9 | * netmask 10 | * ipaddress 11 | * network 12 | 13 | has_interface_with("macaddress", "x:x:x:x:x:x") 14 | has_interface_with("ipaddress", "127.0.0.1") => true 15 | etc. 16 | 17 | If no "kind" is given, then the presence of the interface is checked: 18 | has_interface_with("lo") => true 19 | EOS 20 | ) do |args| 21 | 22 | raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments " + 23 | "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2 24 | 25 | interfaces = lookupvar('interfaces') 26 | 27 | # If we do not have any interfaces, then there are no requested attributes 28 | return false if (interfaces == :undefined) 29 | 30 | interfaces = interfaces.split(',') 31 | 32 | if args.size == 1 33 | return interfaces.member?(args[0]) 34 | end 35 | 36 | kind, value = args 37 | 38 | if lookupvar(kind) == value 39 | return true 40 | end 41 | 42 | result = false 43 | interfaces.each do |iface| 44 | if value == lookupvar("#{kind}_#{iface}") 45 | result = true 46 | break 47 | end 48 | end 49 | 50 | result 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb: -------------------------------------------------------------------------------- 1 | # 2 | # has_ip_address 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:has_ip_address, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the client has the requested IP address on some interface. 8 | 9 | This function iterates through the 'interfaces' fact and checks the 10 | 'ipaddress_IFACE' facts, performing a simple string comparison. 11 | EOS 12 | ) do |args| 13 | 14 | raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments " + 15 | "given (#{args.size} for 1)") if args.size != 1 16 | 17 | Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ 18 | unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with) 19 | 20 | function_has_interface_with(['ipaddress', args[0]]) 21 | 22 | end 23 | end 24 | 25 | # vim:sts=2 sw=2 26 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb: -------------------------------------------------------------------------------- 1 | # 2 | # has_ip_network 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:has_ip_network, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the client has an IP address within the requested network. 8 | 9 | This function iterates through the 'interfaces' fact and checks the 10 | 'network_IFACE' facts, performing a simple string comparision. 11 | EOS 12 | ) do |args| 13 | 14 | raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments " + 15 | "given (#{args.size} for 1)") if args.size != 1 16 | 17 | Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ 18 | unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with) 19 | 20 | function_has_interface_with(['network', args[0]]) 21 | 22 | end 23 | end 24 | 25 | # vim:sts=2 sw=2 26 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/has_key.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | 3 | newfunction(:has_key, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| 4 | Determine if a hash has a certain key value. 5 | 6 | Example: 7 | 8 | $my_hash = {'key_one' => 'value_one'} 9 | if has_key($my_hash, 'key_two') { 10 | notice('we will not reach here') 11 | } 12 | if has_key($my_hash, 'key_one') { 13 | notice('this will be printed') 14 | } 15 | 16 | ENDHEREDOC 17 | 18 | unless args.length == 2 19 | raise Puppet::ParseError, ("has_key(): wrong number of arguments (#{args.length}; must be 2)") 20 | end 21 | unless args[0].is_a?(Hash) 22 | raise Puppet::ParseError, "has_key(): expects the first argument to be a hash, got #{args[0].inspect} which is of type #{args[0].class}" 23 | end 24 | args[0].has_key?(args[1]) 25 | 26 | end 27 | 28 | end 29 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/hash.rb: -------------------------------------------------------------------------------- 1 | # 2 | # hash.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:hash, :type => :rvalue, :doc => <<-EOS 7 | This function converts an array into a hash. 8 | 9 | *Examples:* 10 | 11 | hash(['a',1,'b',2,'c',3]) 12 | 13 | Would return: {'a'=>1,'b'=>2,'c'=>3} 14 | EOS 15 | ) do |arguments| 16 | 17 | raise(Puppet::ParseError, "hash(): Wrong number of arguments " + 18 | "given (#{arguments.size} for 1)") if arguments.size < 1 19 | 20 | array = arguments[0] 21 | 22 | unless array.is_a?(Array) 23 | raise(Puppet::ParseError, 'hash(): Requires array to work with') 24 | end 25 | 26 | result = {} 27 | 28 | begin 29 | # This is to make it compatible with older version of Ruby ... 30 | array = array.flatten 31 | result = Hash[*array] 32 | rescue Exception 33 | raise(Puppet::ParseError, 'hash(): Unable to compute ' + 34 | 'hash from array given') 35 | end 36 | 37 | return result 38 | end 39 | end 40 | 41 | # vim: set ts=2 sw=2 et : 42 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/is_array.rb: -------------------------------------------------------------------------------- 1 | # 2 | # is_array.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:is_array, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the variable passed to this function is an array. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "is_array(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size < 1 13 | 14 | type = arguments[0] 15 | 16 | result = type.is_a?(Array) 17 | 18 | return result 19 | end 20 | end 21 | 22 | # vim: set ts=2 sw=2 et : 23 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb: -------------------------------------------------------------------------------- 1 | # 2 | # is_domain_name.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:is_domain_name, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the string passed to this function is a syntactically correct domain name. 8 | EOS 9 | ) do |arguments| 10 | 11 | if (arguments.size != 1) then 12 | raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments "+ 13 | "given #{arguments.size} for 1") 14 | end 15 | 16 | domain = arguments[0] 17 | 18 | # Limits (rfc1035, 3.1) 19 | domain_max_length=255 20 | label_min_length=1 21 | label_max_length=63 22 | 23 | # Allow ".", it is the top level domain 24 | return true if domain == '.' 25 | 26 | # Remove the final dot, if present. 27 | domain.chomp!('.') 28 | 29 | # Check the whole domain 30 | return false if domain.empty? 31 | return false if domain.length > domain_max_length 32 | 33 | # Check each label in the domain 34 | labels = domain.split('.') 35 | vlabels = labels.each do |label| 36 | break if label.length < label_min_length 37 | break if label.length > label_max_length 38 | break if label[-1..-1] == '-' 39 | break if label[0..0] == '-' 40 | break unless /^[a-z\d-]+$/i.match(label) 41 | end 42 | return vlabels == labels 43 | 44 | end 45 | end 46 | 47 | # vim: set ts=2 sw=2 et : 48 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/is_float.rb: -------------------------------------------------------------------------------- 1 | # 2 | # is_float.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:is_float, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the variable passed to this function is a float. 8 | EOS 9 | ) do |arguments| 10 | 11 | if (arguments.size != 1) then 12 | raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+ 13 | "given #{arguments.size} for 1") 14 | end 15 | 16 | value = arguments[0] 17 | 18 | if value != value.to_f.to_s and !value.is_a? Float then 19 | return false 20 | else 21 | return true 22 | end 23 | 24 | end 25 | end 26 | 27 | # vim: set ts=2 sw=2 et : 28 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/is_function_available.rb: -------------------------------------------------------------------------------- 1 | # 2 | # is_function_available.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:is_function_available, :type => :rvalue, :doc => <<-EOS 7 | This function accepts a string as an argument, determines whether the 8 | Puppet runtime has access to a function by that name. It returns a 9 | true if the function exists, false if not. 10 | EOS 11 | ) do |arguments| 12 | 13 | if (arguments.size != 1) then 14 | raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments "+ 15 | "given #{arguments.size} for 1") 16 | end 17 | 18 | function = Puppet::Parser::Functions.function(arguments[0].to_sym) 19 | function.is_a?(String) and not function.empty? 20 | end 21 | end 22 | 23 | # vim: set ts=2 sw=2 et : 24 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/is_hash.rb: -------------------------------------------------------------------------------- 1 | # 2 | # is_hash.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:is_hash, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the variable passed to this function is a hash. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "is_hash(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size != 1 13 | 14 | type = arguments[0] 15 | 16 | result = type.is_a?(Hash) 17 | 18 | return result 19 | end 20 | end 21 | 22 | # vim: set ts=2 sw=2 et : 23 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/is_integer.rb: -------------------------------------------------------------------------------- 1 | # 2 | # is_integer.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the variable returned to this string is an integer. 8 | EOS 9 | ) do |arguments| 10 | 11 | if (arguments.size != 1) then 12 | raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+ 13 | "given #{arguments.size} for 1") 14 | end 15 | 16 | value = arguments[0] 17 | 18 | if value != value.to_i.to_s and !value.is_a? Fixnum then 19 | return false 20 | else 21 | return true 22 | end 23 | 24 | end 25 | end 26 | 27 | # vim: set ts=2 sw=2 et : 28 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb: -------------------------------------------------------------------------------- 1 | # 2 | # is_ip_address.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:is_ip_address, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the string passed to this function is a valid IP address. 8 | EOS 9 | ) do |arguments| 10 | 11 | require 'ipaddr' 12 | 13 | if (arguments.size != 1) then 14 | raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+ 15 | "given #{arguments.size} for 1") 16 | end 17 | 18 | begin 19 | ip = IPAddr.new(arguments[0]) 20 | rescue ArgumentError 21 | return false 22 | end 23 | 24 | if ip.ipv4? or ip.ipv6? then 25 | return true 26 | else 27 | return false 28 | end 29 | end 30 | end 31 | 32 | # vim: set ts=2 sw=2 et : 33 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb: -------------------------------------------------------------------------------- 1 | # 2 | # is_mac_address.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:is_mac_address, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the string passed to this function is a valid mac address. 8 | EOS 9 | ) do |arguments| 10 | 11 | if (arguments.size != 1) then 12 | raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments "+ 13 | "given #{arguments.size} for 1") 14 | end 15 | 16 | mac = arguments[0] 17 | 18 | if /^[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}$/.match(mac) then 19 | return true 20 | else 21 | return false 22 | end 23 | 24 | end 25 | end 26 | 27 | # vim: set ts=2 sw=2 et : 28 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/is_numeric.rb: -------------------------------------------------------------------------------- 1 | # 2 | # is_numeric.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the variable passed to this function is a number. 8 | EOS 9 | ) do |arguments| 10 | 11 | if (arguments.size != 1) then 12 | raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments "+ 13 | "given #{arguments.size} for 1") 14 | end 15 | 16 | value = arguments[0] 17 | 18 | if value == value.to_f.to_s or value == value.to_i.to_s or value.is_a? Numeric then 19 | return true 20 | else 21 | return false 22 | end 23 | 24 | end 25 | end 26 | 27 | # vim: set ts=2 sw=2 et : 28 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/is_string.rb: -------------------------------------------------------------------------------- 1 | # 2 | # is_string.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:is_string, :type => :rvalue, :doc => <<-EOS 7 | Returns true if the variable passed to this function is a string. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "is_string(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size < 1 13 | 14 | type = arguments[0] 15 | 16 | result = type.is_a?(String) 17 | 18 | if result and (type == type.to_f.to_s or type == type.to_i.to_s) then 19 | return false 20 | end 21 | 22 | return result 23 | end 24 | end 25 | 26 | # vim: set ts=2 sw=2 et : 27 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/join.rb: -------------------------------------------------------------------------------- 1 | # 2 | # join.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:join, :type => :rvalue, :doc => <<-EOS 7 | This function joins an array into a string using a seperator. 8 | 9 | *Examples:* 10 | 11 | join(['a','b','c'], ",") 12 | 13 | Would result in: "a,b,c" 14 | EOS 15 | ) do |arguments| 16 | 17 | # Technically we support two arguments but only first is mandatory ... 18 | raise(Puppet::ParseError, "join(): Wrong number of arguments " + 19 | "given (#{arguments.size} for 1)") if arguments.size < 1 20 | 21 | array = arguments[0] 22 | 23 | unless array.is_a?(Array) 24 | raise(Puppet::ParseError, 'join(): Requires array to work with') 25 | end 26 | 27 | suffix = arguments[1] if arguments[1] 28 | 29 | if suffix 30 | unless suffix.is_a?(String) 31 | raise(Puppet::ParseError, 'join(): Requires string to work with') 32 | end 33 | end 34 | 35 | result = suffix ? array.join(suffix) : array.join 36 | 37 | return result 38 | end 39 | end 40 | 41 | # vim: set ts=2 sw=2 et : 42 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb: -------------------------------------------------------------------------------- 1 | # 2 | # join.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:join_keys_to_values, :type => :rvalue, :doc => <<-EOS 7 | This function joins each key of a hash to that key's corresponding value with a 8 | separator. Keys and values are cast to strings. The return value is an array in 9 | which each element is one joined key/value pair. 10 | 11 | *Examples:* 12 | 13 | join_keys_to_values({'a'=>1,'b'=>2}, " is ") 14 | 15 | Would result in: ["a is 1","b is 2"] 16 | EOS 17 | ) do |arguments| 18 | 19 | # Validate the number of arguments. 20 | if arguments.size != 2 21 | raise(Puppet::ParseError, "join_keys_to_values(): Takes exactly two " + 22 | "arguments, but #{arguments.size} given.") 23 | end 24 | 25 | # Validate the first argument. 26 | hash = arguments[0] 27 | if not hash.is_a?(Hash) 28 | raise(TypeError, "join_keys_to_values(): The first argument must be a " + 29 | "hash, but a #{hash.class} was given.") 30 | end 31 | 32 | # Validate the second argument. 33 | separator = arguments[1] 34 | if not separator.is_a?(String) 35 | raise(TypeError, "join_keys_to_values(): The second argument must be a " + 36 | "string, but a #{separator.class} was given.") 37 | end 38 | 39 | # Join the keys to their values. 40 | hash.map do |k,v| 41 | String(k) + separator + String(v) 42 | end 43 | 44 | end 45 | end 46 | 47 | # vim: set ts=2 sw=2 et : 48 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/keys.rb: -------------------------------------------------------------------------------- 1 | # 2 | # keys.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:keys, :type => :rvalue, :doc => <<-EOS 7 | Returns the keys of a hash as an array. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "keys(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size < 1 13 | 14 | hash = arguments[0] 15 | 16 | unless hash.is_a?(Hash) 17 | raise(Puppet::ParseError, 'keys(): Requires hash to work with') 18 | end 19 | 20 | result = hash.keys 21 | 22 | return result 23 | end 24 | end 25 | 26 | # vim: set ts=2 sw=2 et : 27 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/loadyaml.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | 3 | newfunction(:loadyaml, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| 4 | Load a YAML file containing an array, string, or hash, and return the data 5 | in the corresponding native data type. 6 | 7 | For example: 8 | 9 | $myhash = loadyaml('/etc/puppet/data/myhash.yaml') 10 | ENDHEREDOC 11 | 12 | unless args.length == 1 13 | raise Puppet::ParseError, ("loadyaml(): wrong number of arguments (#{args.length}; must be 1)") 14 | end 15 | 16 | YAML.load_file(args[0]) 17 | 18 | end 19 | 20 | end 21 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/lstrip.rb: -------------------------------------------------------------------------------- 1 | # 2 | # lstrip.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS 7 | Strips leading spaces to the left of a string. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "lstrip(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size < 1 13 | 14 | value = arguments[0] 15 | klass = value.class 16 | 17 | unless [Array, String].include?(klass) 18 | raise(Puppet::ParseError, 'lstrip(): Requires either ' + 19 | 'array or string to work with') 20 | end 21 | 22 | if value.is_a?(Array) 23 | # Numbers in Puppet are often string-encoded which is troublesome ... 24 | result = value.collect { |i| i.is_a?(String) ? i.lstrip : i } 25 | else 26 | result = value.lstrip 27 | end 28 | 29 | return result 30 | end 31 | end 32 | 33 | # vim: set ts=2 sw=2 et : 34 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/max.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | newfunction(:max, :type => :rvalue, :doc => <<-EOS 3 | Returns the highest value of all arguments. 4 | Requires at least one argument. 5 | EOS 6 | ) do |args| 7 | 8 | raise(Puppet::ParseError, "max(): Wrong number of arguments " + 9 | "need at least one") if args.size == 0 10 | 11 | # Sometimes we get numbers as numerics and sometimes as strings. 12 | # We try to compare them as numbers when possible 13 | return args.max do |a,b| 14 | if a.to_s =~ /\A-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then 15 | a.to_f <=> b.to_f 16 | else 17 | a.to_s <=> b.to_s 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/member.rb: -------------------------------------------------------------------------------- 1 | # 2 | # member.rb 3 | # 4 | 5 | # TODO(Krzysztof Wilczynski): We need to add support for regular expression ... 6 | # TODO(Krzysztof Wilczynski): Support for strings and hashes too ... 7 | 8 | module Puppet::Parser::Functions 9 | newfunction(:member, :type => :rvalue, :doc => <<-EOS 10 | This function determines if a variable is a member of an array. 11 | 12 | *Examples:* 13 | 14 | member(['a','b'], 'b') 15 | 16 | Would return: true 17 | 18 | member(['a','b'], 'c') 19 | 20 | Would return: false 21 | EOS 22 | ) do |arguments| 23 | 24 | raise(Puppet::ParseError, "member(): Wrong number of arguments " + 25 | "given (#{arguments.size} for 2)") if arguments.size < 2 26 | 27 | array = arguments[0] 28 | 29 | unless array.is_a?(Array) 30 | raise(Puppet::ParseError, 'member(): Requires array to work with') 31 | end 32 | 33 | item = arguments[1] 34 | 35 | raise(Puppet::ParseError, 'member(): You must provide item ' + 36 | 'to search for within array given') if item.empty? 37 | 38 | result = array.include?(item) 39 | 40 | return result 41 | end 42 | end 43 | 44 | # vim: set ts=2 sw=2 et : 45 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/merge.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | newfunction(:merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| 3 | Merges two or more hashes together and returns the resulting hash. 4 | 5 | For example: 6 | 7 | $hash1 = {'one' => 1, 'two', => 2} 8 | $hash2 = {'two' => 'dos', 'three', => 'tres'} 9 | $merged_hash = merge($hash1, $hash2) 10 | # The resulting hash is equivalent to: 11 | # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'} 12 | 13 | When there is a duplicate key, the key in the rightmost hash will "win." 14 | 15 | ENDHEREDOC 16 | 17 | if args.length < 2 18 | raise Puppet::ParseError, ("merge(): wrong number of arguments (#{args.length}; must be at least 2)") 19 | end 20 | 21 | # The hash we accumulate into 22 | accumulator = Hash.new 23 | # Merge into the accumulator hash 24 | args.each do |arg| 25 | unless arg.is_a?(Hash) 26 | raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments" 27 | end 28 | accumulator.merge!(arg) 29 | end 30 | # Return the fully merged hash 31 | accumulator 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/min.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | newfunction(:min, :type => :rvalue, :doc => <<-EOS 3 | Returns the lowest value of all arguments. 4 | Requires at least one argument. 5 | EOS 6 | ) do |args| 7 | 8 | raise(Puppet::ParseError, "min(): Wrong number of arguments " + 9 | "need at least one") if args.size == 0 10 | 11 | # Sometimes we get numbers as numerics and sometimes as strings. 12 | # We try to compare them as numbers when possible 13 | return args.min do |a,b| 14 | if a.to_s =~ /\A^-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then 15 | a.to_f <=> b.to_f 16 | else 17 | a.to_s <=> b.to_s 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/num2bool.rb: -------------------------------------------------------------------------------- 1 | # 2 | # num2bool.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:num2bool, :type => :rvalue, :doc => <<-EOS 7 | This function converts a number or a string representation of a number into a 8 | true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0 9 | become true. 10 | EOS 11 | ) do |arguments| 12 | 13 | raise(Puppet::ParseError, "num2bool(): Wrong number of arguments " + 14 | "given (#{arguments.size} for 1)") if arguments.size != 1 15 | 16 | number = arguments[0] 17 | 18 | case number 19 | when Numeric 20 | # Yay, it's a number 21 | when String 22 | begin 23 | number = Float(number) 24 | rescue ArgumentError => ex 25 | raise(Puppet::ParseError, "num2bool(): '#{number}' does not look like a number: #{ex.message}") 26 | end 27 | else 28 | begin 29 | number = number.to_s 30 | rescue NoMethodError => ex 31 | raise(Puppet::ParseError, "num2bool(): Unable to parse argument: #{ex.message}") 32 | end 33 | end 34 | 35 | # Truncate Floats 36 | number = number.to_i 37 | 38 | # Return true for any positive number and false otherwise 39 | return number > 0 40 | end 41 | end 42 | 43 | # vim: set ts=2 sw=2 et : 44 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/parsejson.rb: -------------------------------------------------------------------------------- 1 | # 2 | # parsejson.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:parsejson, :type => :rvalue, :doc => <<-EOS 7 | This function accepts JSON as a string and converts into the correct Puppet 8 | structure. 9 | EOS 10 | ) do |arguments| 11 | 12 | if (arguments.size != 1) then 13 | raise(Puppet::ParseError, "parsejson(): Wrong number of arguments "+ 14 | "given #{arguments.size} for 1") 15 | end 16 | 17 | json = arguments[0] 18 | 19 | # PSON is natively available in puppet 20 | PSON.load(json) 21 | end 22 | end 23 | 24 | # vim: set ts=2 sw=2 et : 25 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/parseyaml.rb: -------------------------------------------------------------------------------- 1 | # 2 | # parseyaml.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:parseyaml, :type => :rvalue, :doc => <<-EOS 7 | This function accepts YAML as a string and converts it into the correct 8 | Puppet structure. 9 | EOS 10 | ) do |arguments| 11 | 12 | if (arguments.size != 1) then 13 | raise(Puppet::ParseError, "parseyaml(): Wrong number of arguments "+ 14 | "given #{arguments.size} for 1") 15 | end 16 | 17 | require 'yaml' 18 | 19 | YAML::load(arguments[0]) 20 | 21 | end 22 | end 23 | 24 | # vim: set ts=2 sw=2 et : 25 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/pick.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | newfunction(:pick, :type => :rvalue, :doc => <<-EOS 3 | 4 | This function is similar to a coalesce function in SQL in that it will return 5 | the first value in a list of values that is not undefined or an empty string 6 | (two things in Puppet that will return a boolean false value). Typically, 7 | this function is used to check for a value in the Puppet Dashboard/Enterprise 8 | Console, and failover to a default value like the following: 9 | 10 | $real_jenkins_version = pick($::jenkins_version, '1.449') 11 | 12 | The value of $real_jenkins_version will first look for a top-scope variable 13 | called 'jenkins_version' (note that parameters set in the Puppet Dashboard/ 14 | Enterprise Console are brought into Puppet as top-scope variables), and, 15 | failing that, will use a default value of 1.449. 16 | 17 | EOS 18 | ) do |args| 19 | args = args.compact 20 | args.delete(:undef) 21 | args.delete(:undefined) 22 | args.delete("") 23 | if args[0].to_s.empty? then 24 | fail "Must provide non empty value." 25 | else 26 | return args[0] 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/prefix.rb: -------------------------------------------------------------------------------- 1 | # 2 | # prefix.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:prefix, :type => :rvalue, :doc => <<-EOS 7 | This function applies a prefix to all elements in an array. 8 | 9 | *Examples:* 10 | 11 | prefix(['a','b','c'], 'p') 12 | 13 | Will return: ['pa','pb','pc'] 14 | EOS 15 | ) do |arguments| 16 | 17 | # Technically we support two arguments but only first is mandatory ... 18 | raise(Puppet::ParseError, "prefix(): Wrong number of arguments " + 19 | "given (#{arguments.size} for 1)") if arguments.size < 1 20 | 21 | array = arguments[0] 22 | 23 | unless array.is_a?(Array) 24 | raise Puppet::ParseError, "prefix(): expected first argument to be an Array, got #{array.inspect}" 25 | end 26 | 27 | prefix = arguments[1] if arguments[1] 28 | 29 | if prefix 30 | unless prefix.is_a?(String) 31 | raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{suffix.inspect}" 32 | end 33 | end 34 | 35 | # Turn everything into string same as join would do ... 36 | result = array.collect do |i| 37 | i = i.to_s 38 | prefix ? prefix + i : i 39 | end 40 | 41 | return result 42 | end 43 | end 44 | 45 | # vim: set ts=2 sw=2 et : 46 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/reject.rb: -------------------------------------------------------------------------------- 1 | # 2 | # reject.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:reject, :type => :rvalue, :doc => <<-EOS) do |args| 7 | This function searches through an array and rejects all elements that match 8 | the provided regular expression. 9 | 10 | *Examples:* 11 | 12 | reject(['aaa','bbb','ccc','aaaddd'], 'aaa') 13 | 14 | Would return: 15 | 16 | ['bbb','ccc'] 17 | EOS 18 | 19 | if (args.size != 2) 20 | raise Puppet::ParseError, 21 | "reject(): Wrong number of arguments given #{args.size} for 2" 22 | end 23 | 24 | ary = args[0] 25 | pattern = Regexp.new(args[1]) 26 | 27 | ary.reject { |e| e =~ pattern } 28 | end 29 | end 30 | 31 | # vim: set ts=2 sw=2 et : 32 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/reverse.rb: -------------------------------------------------------------------------------- 1 | # 2 | # reverse.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:reverse, :type => :rvalue, :doc => <<-EOS 7 | Reverses the order of a string or array. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "reverse(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size < 1 13 | 14 | value = arguments[0] 15 | klass = value.class 16 | 17 | unless [Array, String].include?(klass) 18 | raise(Puppet::ParseError, 'reverse(): Requires either ' + 19 | 'array or string to work with') 20 | end 21 | 22 | result = value.reverse 23 | 24 | return result 25 | end 26 | end 27 | 28 | # vim: set ts=2 sw=2 et : 29 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/rstrip.rb: -------------------------------------------------------------------------------- 1 | # 2 | # rstrip.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS 7 | Strips leading spaces to the right of the string. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "rstrip(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size < 1 13 | 14 | value = arguments[0] 15 | klass = value.class 16 | 17 | unless [Array, String].include?(klass) 18 | raise(Puppet::ParseError, 'rstrip(): Requires either ' + 19 | 'array or string to work with') 20 | end 21 | 22 | if value.is_a?(Array) 23 | result = value.collect { |i| i.is_a?(String) ? i.rstrip : i } 24 | else 25 | result = value.rstrip 26 | end 27 | 28 | return result 29 | end 30 | end 31 | 32 | # vim: set ts=2 sw=2 et : 33 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/shuffle.rb: -------------------------------------------------------------------------------- 1 | # 2 | # shuffle.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:shuffle, :type => :rvalue, :doc => <<-EOS 7 | Randomizes the order of a string or array elements. 8 | EOS 9 | ) do |arguments| 10 | 11 | raise(Puppet::ParseError, "shuffle(): Wrong number of arguments " + 12 | "given (#{arguments.size} for 1)") if arguments.size < 1 13 | 14 | value = arguments[0] 15 | klass = value.class 16 | 17 | unless [Array, String].include?(klass) 18 | raise(Puppet::ParseError, 'shuffle(): Requires either ' + 19 | 'array or string to work with') 20 | end 21 | 22 | result = value.clone 23 | 24 | string = value.is_a?(String) ? true : false 25 | 26 | # Check whether it makes sense to shuffle ... 27 | return result if result.size <= 1 28 | 29 | # We turn any string value into an array to be able to shuffle ... 30 | result = string ? result.split('') : result 31 | 32 | elements = result.size 33 | 34 | # Simple implementation of Fisher–Yates in-place shuffle ... 35 | elements.times do |i| 36 | j = rand(elements - i) + i 37 | result[j], result[i] = result[i], result[j] 38 | end 39 | 40 | result = string ? result.join : result 41 | 42 | return result 43 | end 44 | end 45 | 46 | # vim: set ts=2 sw=2 et : 47 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/size.rb: -------------------------------------------------------------------------------- 1 | # 2 | # size.rb 3 | # 4 | 5 | # TODO(Krzysztof Wilczynski): Support for hashes would be nice too ... 6 | 7 | module Puppet::Parser::Functions 8 | newfunction(:size, :type => :rvalue, :doc => <<-EOS 9 | Returns the number of elements in a string or array. 10 | EOS 11 | ) do |arguments| 12 | 13 | raise(Puppet::ParseError, "size(): Wrong number of arguments " + 14 | "given (#{arguments.size} for 1)") if arguments.size < 1 15 | 16 | item = arguments[0] 17 | 18 | if item.is_a?(String) 19 | 20 | begin 21 | # 22 | # Check whether your item is a numeric value or not ... 23 | # This will take care about positive and/or negative numbers 24 | # for both integer and floating-point values ... 25 | # 26 | # Please note that Puppet has no notion of hexadecimal 27 | # nor octal numbers for its DSL at this point in time ... 28 | # 29 | Float(item) 30 | 31 | raise(Puppet::ParseError, 'size(): Requires either ' + 32 | 'string or array to work with') 33 | 34 | rescue ArgumentError 35 | result = item.size 36 | end 37 | 38 | elsif item.is_a?(Array) 39 | result = item.size 40 | else 41 | raise(Puppet::ParseError, 'size(): Unknown type given') 42 | end 43 | 44 | return result 45 | end 46 | end 47 | 48 | # vim: set ts=2 sw=2 et : 49 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/sort.rb: -------------------------------------------------------------------------------- 1 | # 2 | # sort.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:sort, :type => :rvalue, :doc => <<-EOS 7 | Sorts strings and arrays lexically. 8 | EOS 9 | ) do |arguments| 10 | 11 | if (arguments.size != 1) then 12 | raise(Puppet::ParseError, "sort(): Wrong number of arguments "+ 13 | "given #{arguments.size} for 1") 14 | end 15 | 16 | value = arguments[0] 17 | 18 | if value.is_a?(Array) then 19 | value.sort 20 | elsif value.is_a?(String) then 21 | value.split("").sort.join("") 22 | end 23 | 24 | end 25 | end 26 | 27 | # vim: set ts=2 sw=2 et : 28 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/squeeze.rb: -------------------------------------------------------------------------------- 1 | # 2 | # squeeze.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS 7 | Returns a new string where runs of the same character that occur in this set are replaced by a single character. 8 | EOS 9 | ) do |arguments| 10 | 11 | if ((arguments.size != 2) and (arguments.size != 1)) then 12 | raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+ 13 | "given #{arguments.size} for 2 or 1") 14 | end 15 | 16 | item = arguments[0] 17 | squeezeval = arguments[1] 18 | 19 | if item.is_a?(Array) then 20 | if squeezeval then 21 | item.collect { |i| i.squeeze(squeezeval) } 22 | else 23 | item.collect { |i| i.squeeze } 24 | end 25 | else 26 | if squeezeval then 27 | item.squeeze(squeezeval) 28 | else 29 | item.squeeze 30 | end 31 | end 32 | 33 | end 34 | end 35 | 36 | # vim: set ts=2 sw=2 et : 37 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb: -------------------------------------------------------------------------------- 1 | # 2 | # str2saltedsha512.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:str2saltedsha512, :type => :rvalue, :doc => <<-EOS 7 | This converts a string to a salted-SHA512 password hash (which is used for 8 | OS X versions >= 10.7). Given any simple string, you will get a hex version 9 | of a salted-SHA512 password hash that can be inserted into your Puppet 10 | manifests as a valid password attribute. 11 | EOS 12 | ) do |arguments| 13 | require 'digest/sha2' 14 | 15 | raise(Puppet::ParseError, "str2saltedsha512(): Wrong number of arguments " + 16 | "passed (#{arguments.size} but we require 1)") if arguments.size != 1 17 | 18 | password = arguments[0] 19 | 20 | unless password.is_a?(String) 21 | raise(Puppet::ParseError, 'str2saltedsha512(): Requires a ' + 22 | "String argument, you passed: #{password.class}") 23 | end 24 | 25 | seedint = rand(2**31 - 1) 26 | seedstring = Array(seedint).pack("L") 27 | saltedpass = Digest::SHA512.digest(seedstring + password) 28 | (seedstring + saltedpass).unpack('H*')[0] 29 | end 30 | end 31 | 32 | # vim: set ts=2 sw=2 et : 33 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/strip.rb: -------------------------------------------------------------------------------- 1 | # 2 | # strip.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:strip, :type => :rvalue, :doc => <<-EOS 7 | This function removes leading and trailing whitespace from a string or from 8 | every string inside an array. 9 | 10 | *Examples:* 11 | 12 | strip(" aaa ") 13 | 14 | Would result in: "aaa" 15 | EOS 16 | ) do |arguments| 17 | 18 | raise(Puppet::ParseError, "strip(): Wrong number of arguments " + 19 | "given (#{arguments.size} for 1)") if arguments.size < 1 20 | 21 | value = arguments[0] 22 | klass = value.class 23 | 24 | unless [Array, String].include?(klass) 25 | raise(Puppet::ParseError, 'strip(): Requires either ' + 26 | 'array or string to work with') 27 | end 28 | 29 | if value.is_a?(Array) 30 | result = value.collect { |i| i.is_a?(String) ? i.strip : i } 31 | else 32 | result = value.strip 33 | end 34 | 35 | return result 36 | end 37 | end 38 | 39 | # vim: set ts=2 sw=2 et : 40 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/suffix.rb: -------------------------------------------------------------------------------- 1 | # 2 | # suffix.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:suffix, :type => :rvalue, :doc => <<-EOS 7 | This function applies a suffix to all elements in an array. 8 | 9 | *Examples:* 10 | 11 | suffix(['a','b','c'], 'p') 12 | 13 | Will return: ['ap','bp','cp'] 14 | EOS 15 | ) do |arguments| 16 | 17 | # Technically we support two arguments but only first is mandatory ... 18 | raise(Puppet::ParseError, "suffix(): Wrong number of arguments " + 19 | "given (#{arguments.size} for 1)") if arguments.size < 1 20 | 21 | array = arguments[0] 22 | 23 | unless array.is_a?(Array) 24 | raise Puppet::ParseError, "suffix(): expected first argument to be an Array, got #{array.inspect}" 25 | end 26 | 27 | suffix = arguments[1] if arguments[1] 28 | 29 | if suffix 30 | unless suffix.is_a? String 31 | raise Puppet::ParseError, "suffix(): expected second argument to be a String, got #{suffix.inspect}" 32 | end 33 | end 34 | 35 | # Turn everything into string same as join would do ... 36 | result = array.collect do |i| 37 | i = i.to_s 38 | suffix ? i + suffix : i 39 | end 40 | 41 | return result 42 | end 43 | end 44 | 45 | # vim: set ts=2 sw=2 et : 46 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/swapcase.rb: -------------------------------------------------------------------------------- 1 | # 2 | # swapcase.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS 7 | This function will swap the existing case of a string. 8 | 9 | *Examples:* 10 | 11 | swapcase("aBcD") 12 | 13 | Would result in: "AbCd" 14 | EOS 15 | ) do |arguments| 16 | 17 | raise(Puppet::ParseError, "swapcase(): Wrong number of arguments " + 18 | "given (#{arguments.size} for 1)") if arguments.size < 1 19 | 20 | value = arguments[0] 21 | klass = value.class 22 | 23 | unless [Array, String].include?(klass) 24 | raise(Puppet::ParseError, 'swapcase(): Requires either ' + 25 | 'array or string to work with') 26 | end 27 | 28 | if value.is_a?(Array) 29 | # Numbers in Puppet are often string-encoded which is troublesome ... 30 | result = value.collect { |i| i.is_a?(String) ? i.swapcase : i } 31 | else 32 | result = value.swapcase 33 | end 34 | 35 | return result 36 | end 37 | end 38 | 39 | # vim: set ts=2 sw=2 et : 40 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/time.rb: -------------------------------------------------------------------------------- 1 | # 2 | # time.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:time, :type => :rvalue, :doc => <<-EOS 7 | This function will return the current time since epoch as an integer. 8 | 9 | *Examples:* 10 | 11 | time() 12 | 13 | Will return something like: 1311972653 14 | EOS 15 | ) do |arguments| 16 | 17 | # The Time Zone argument is optional ... 18 | time_zone = arguments[0] if arguments[0] 19 | 20 | if (arguments.size != 0) and (arguments.size != 1) then 21 | raise(Puppet::ParseError, "time(): Wrong number of arguments "+ 22 | "given #{arguments.size} for 0 or 1") 23 | end 24 | 25 | time = Time.new 26 | 27 | # There is probably a better way to handle Time Zone ... 28 | if time_zone and not time_zone.empty? 29 | original_zone = ENV['TZ'] 30 | 31 | local_time = time.clone 32 | local_time = local_time.utc 33 | 34 | ENV['TZ'] = time_zone 35 | 36 | time = local_time.localtime 37 | 38 | ENV['TZ'] = original_zone 39 | end 40 | 41 | # Calling Time#to_i on a receiver changes it. Trust me I am the Doctor. 42 | result = time.strftime('%s') 43 | result = result.to_i 44 | 45 | return result 46 | end 47 | end 48 | 49 | # vim: set ts=2 sw=2 et : 50 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/to_bytes.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | newfunction(:to_bytes, :type => :rvalue, :doc => <<-EOS 3 | Converts the argument into bytes, for example 4 kB becomes 4096. 4 | Takes a single string value as an argument. 5 | EOS 6 | ) do |arguments| 7 | 8 | raise(Puppet::ParseError, "to_bytes(): Wrong number of arguments " + 9 | "given (#{arguments.size} for 1)") if arguments.size != 1 10 | 11 | arg = arguments[0] 12 | 13 | return arg if arg.is_a? Numeric 14 | 15 | value,prefix = */([0-9.e+-]*)\s*([^bB]?)/.match(arg)[1,2] 16 | 17 | value = value.to_f 18 | case prefix 19 | when '' then return value.to_i 20 | when 'k' then return (value*(1<<10)).to_i 21 | when 'M' then return (value*(1<<20)).to_i 22 | when 'G' then return (value*(1<<30)).to_i 23 | when 'T' then return (value*(1<<40)).to_i 24 | when 'E' then return (value*(1<<50)).to_i 25 | else raise Puppet::ParseError, "to_bytes(): Unknown prefix #{prefix}" 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/type.rb: -------------------------------------------------------------------------------- 1 | # 2 | # type.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:type, :type => :rvalue, :doc => <<-EOS 7 | Returns the type when passed a variable. Type can be one of: 8 | 9 | * string 10 | * array 11 | * hash 12 | * float 13 | * integer 14 | * boolean 15 | EOS 16 | ) do |arguments| 17 | 18 | raise(Puppet::ParseError, "type(): Wrong number of arguments " + 19 | "given (#{arguments.size} for 1)") if arguments.size < 1 20 | 21 | value = arguments[0] 22 | 23 | klass = value.class 24 | 25 | if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass) 26 | raise(Puppet::ParseError, 'type(): Unknown type') 27 | end 28 | 29 | klass = klass.to_s # Ugly ... 30 | 31 | # We note that Integer is the parent to Bignum and Fixnum ... 32 | result = case klass 33 | when /^(?:Big|Fix)num$/ then 'integer' 34 | when /^(?:True|False)Class$/ then 'boolean' 35 | else klass 36 | end 37 | 38 | if result == "String" then 39 | if value == value.to_i.to_s then 40 | result = "Integer" 41 | elsif value == value.to_f.to_s then 42 | result = "Float" 43 | end 44 | end 45 | 46 | return result.downcase 47 | end 48 | end 49 | 50 | # vim: set ts=2 sw=2 et : 51 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/unique.rb: -------------------------------------------------------------------------------- 1 | # 2 | # unique.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:unique, :type => :rvalue, :doc => <<-EOS 7 | This function will remove duplicates from strings and arrays. 8 | 9 | *Examples:* 10 | 11 | unique("aabbcc") 12 | 13 | Will return: 14 | 15 | abc 16 | 17 | You can also use this with arrays: 18 | 19 | unique(["a","a","b","b","c","c"]) 20 | 21 | This returns: 22 | 23 | ["a","b","c"] 24 | EOS 25 | ) do |arguments| 26 | 27 | raise(Puppet::ParseError, "unique(): Wrong number of arguments " + 28 | "given (#{arguments.size} for 1)") if arguments.size < 1 29 | 30 | value = arguments[0] 31 | klass = value.class 32 | 33 | unless [Array, String].include?(klass) 34 | raise(Puppet::ParseError, 'unique(): Requires either ' + 35 | 'array or string to work with') 36 | end 37 | 38 | result = value.clone 39 | 40 | string = value.is_a?(String) ? true : false 41 | 42 | # We turn any string value into an array to be able to shuffle ... 43 | result = string ? result.split('') : result 44 | result = result.uniq # Remove duplicates ... 45 | result = string ? result.join : result 46 | 47 | return result 48 | end 49 | end 50 | 51 | # vim: set ts=2 sw=2 et : 52 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/upcase.rb: -------------------------------------------------------------------------------- 1 | # 2 | # upcase.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:upcase, :type => :rvalue, :doc => <<-EOS 7 | Converts a string or an array of strings to uppercase. 8 | 9 | *Examples:* 10 | 11 | upcase("abcd") 12 | 13 | Will return: 14 | 15 | ASDF 16 | EOS 17 | ) do |arguments| 18 | 19 | raise(Puppet::ParseError, "upcase(): Wrong number of arguments " + 20 | "given (#{arguments.size} for 1)") if arguments.size < 1 21 | 22 | value = arguments[0] 23 | klass = value.class 24 | 25 | unless [Array, String].include?(klass) 26 | raise(Puppet::ParseError, 'upcase(): Requires either ' + 27 | 'array or string to work with') 28 | end 29 | 30 | if value.is_a?(Array) 31 | # Numbers in Puppet are often string-encoded which is troublesome ... 32 | result = value.collect { |i| i.is_a?(String) ? i.upcase : i } 33 | else 34 | result = value.upcase 35 | end 36 | 37 | return result 38 | end 39 | end 40 | 41 | # vim: set ts=2 sw=2 et : 42 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/uriescape.rb: -------------------------------------------------------------------------------- 1 | # 2 | # uriescape.rb 3 | # 4 | require 'uri' 5 | 6 | module Puppet::Parser::Functions 7 | newfunction(:uriescape, :type => :rvalue, :doc => <<-EOS 8 | Urlencodes a string or array of strings. 9 | Requires either a single string or an array as an input. 10 | EOS 11 | ) do |arguments| 12 | 13 | raise(Puppet::ParseError, "uriescape(): Wrong number of arguments " + 14 | "given (#{arguments.size} for 1)") if arguments.size < 1 15 | 16 | value = arguments[0] 17 | klass = value.class 18 | unsafe = ":/?#[]@!$&'()*+,;= " 19 | 20 | unless [Array, String].include?(klass) 21 | raise(Puppet::ParseError, 'uriescape(): Requires either ' + 22 | 'array or string to work with') 23 | end 24 | 25 | if value.is_a?(Array) 26 | # Numbers in Puppet are often string-encoded which is troublesome ... 27 | result = value.collect { |i| i.is_a?(String) ? URI.escape(i,unsafe) : i } 28 | else 29 | result = URI.escape(value,unsafe) 30 | end 31 | 32 | return result 33 | end 34 | end 35 | 36 | # vim: set ts=2 sw=2 et : 37 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/validate_array.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | 3 | newfunction(:validate_array, :doc => <<-'ENDHEREDOC') do |args| 4 | Validate that all passed values are array data structures. Abort catalog 5 | compilation if any value fails this check. 6 | 7 | The following values will pass: 8 | 9 | $my_array = [ 'one', 'two' ] 10 | validate_array($my_array) 11 | 12 | The following values will fail, causing compilation to abort: 13 | 14 | validate_array(true) 15 | validate_array('some_string') 16 | $undefined = undef 17 | validate_array($undefined) 18 | 19 | ENDHEREDOC 20 | 21 | unless args.length > 0 then 22 | raise Puppet::ParseError, ("validate_array(): wrong number of arguments (#{args.length}; must be > 0)") 23 | end 24 | 25 | args.each do |arg| 26 | unless arg.is_a?(Array) 27 | raise Puppet::ParseError, ("#{arg.inspect} is not an Array. It looks to be a #{arg.class}") 28 | end 29 | end 30 | 31 | end 32 | 33 | end 34 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/validate_bool.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | 3 | newfunction(:validate_bool, :doc => <<-'ENDHEREDOC') do |args| 4 | Validate that all passed values are either true or false. Abort catalog 5 | compilation if any value fails this check. 6 | 7 | The following values will pass: 8 | 9 | $iamtrue = true 10 | validate_bool(true) 11 | validate_bool(true, true, false, $iamtrue) 12 | 13 | The following values will fail, causing compilation to abort: 14 | 15 | $some_array = [ true ] 16 | validate_bool("false") 17 | validate_bool("true") 18 | validate_bool($some_array) 19 | 20 | ENDHEREDOC 21 | 22 | unless args.length > 0 then 23 | raise Puppet::ParseError, ("validate_bool(): wrong number of arguments (#{args.length}; must be > 0)") 24 | end 25 | 26 | args.each do |arg| 27 | unless (arg.is_a?(TrueClass) || arg.is_a?(FalseClass)) 28 | raise Puppet::ParseError, ("#{arg.inspect} is not a boolean. It looks to be a #{arg.class}") 29 | end 30 | end 31 | 32 | end 33 | 34 | end 35 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/validate_hash.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | 3 | newfunction(:validate_hash, :doc => <<-'ENDHEREDOC') do |args| 4 | Validate that all passed values are hash data structures. Abort catalog 5 | compilation if any value fails this check. 6 | 7 | The following values will pass: 8 | 9 | $my_hash = { 'one' => 'two' } 10 | validate_hash($my_hash) 11 | 12 | The following values will fail, causing compilation to abort: 13 | 14 | validate_hash(true) 15 | validate_hash('some_string') 16 | $undefined = undef 17 | validate_hash($undefined) 18 | 19 | ENDHEREDOC 20 | 21 | unless args.length > 0 then 22 | raise Puppet::ParseError, ("validate_hash(): wrong number of arguments (#{args.length}; must be > 0)") 23 | end 24 | 25 | args.each do |arg| 26 | unless arg.is_a?(Hash) 27 | raise Puppet::ParseError, ("#{arg.inspect} is not a Hash. It looks to be a #{arg.class}") 28 | end 29 | end 30 | 31 | end 32 | 33 | end 34 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/validate_string.rb: -------------------------------------------------------------------------------- 1 | module Puppet::Parser::Functions 2 | 3 | newfunction(:validate_string, :doc => <<-'ENDHEREDOC') do |args| 4 | Validate that all passed values are string data structures. Abort catalog 5 | compilation if any value fails this check. 6 | 7 | The following values will pass: 8 | 9 | $my_string = "one two" 10 | validate_string($my_string, 'three') 11 | 12 | The following values will fail, causing compilation to abort: 13 | 14 | validate_string(true) 15 | validate_string([ 'some', 'array' ]) 16 | $undefined = undef 17 | validate_string($undefined) 18 | 19 | ENDHEREDOC 20 | 21 | unless args.length > 0 then 22 | raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)") 23 | end 24 | 25 | args.each do |arg| 26 | unless arg.is_a?(String) 27 | raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}") 28 | end 29 | end 30 | 31 | end 32 | 33 | end 34 | -------------------------------------------------------------------------------- /modules/stdlib/lib/puppet/parser/functions/values.rb: -------------------------------------------------------------------------------- 1 | # 2 | # values.rb 3 | # 4 | 5 | module Puppet::Parser::Functions 6 | newfunction(:values, :type => :rvalue, :doc => <<-EOS 7 | When given a hash this function will return the values of that hash. 8 | 9 | *Examples:* 10 | 11 | $hash = { 12 | 'a' => 1, 13 | 'b' => 2, 14 | 'c' => 3, 15 | } 16 | values($hash) 17 | 18 | This example would return: 19 | 20 | [1,2,3] 21 | EOS 22 | ) do |arguments| 23 | 24 | raise(Puppet::ParseError, "values(): Wrong number of arguments " + 25 | "given (#{arguments.size} for 1)") if arguments.size < 1 26 | 27 | hash = arguments[0] 28 | 29 | unless hash.is_a?(Hash) 30 | raise(Puppet::ParseError, 'values(): Requires hash to work with') 31 | end 32 | 33 | result = hash.values 34 | 35 | return result 36 | end 37 | end 38 | 39 | # vim: set ts=2 sw=2 et : 40 | -------------------------------------------------------------------------------- /modules/stdlib/manifests/init.pp: -------------------------------------------------------------------------------- 1 | # Class: stdlib 2 | # 3 | # This module manages stdlib. Most of stdlib's features are automatically 4 | # loaded by Puppet, but this class should be declared in order to use the 5 | # standardized run stages. 6 | # 7 | # Parameters: none 8 | # 9 | # Actions: 10 | # 11 | # Declares all other classes in the stdlib module. Currently, this consists 12 | # of stdlib::stages. 13 | # 14 | # Requires: nothing 15 | # 16 | class stdlib { 17 | 18 | class { 'stdlib::stages': } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /modules/stdlib/manifests/stages.pp: -------------------------------------------------------------------------------- 1 | # Class: stdlib::stages 2 | # 3 | # This class manages a standard set of run stages for Puppet. It is managed by 4 | # the stdlib class, and should not be declared independently. 5 | # 6 | # The high level stages are (in order): 7 | # 8 | # * setup 9 | # * main 10 | # * runtime 11 | # * setup_infra 12 | # * deploy_infra 13 | # * setup_app 14 | # * deploy_app 15 | # * deploy 16 | # 17 | # Parameters: none 18 | # 19 | # Actions: 20 | # 21 | # Declares various run-stages for deploying infrastructure, 22 | # language runtimes, and application layers. 23 | # 24 | # Requires: nothing 25 | # 26 | # Sample Usage: 27 | # 28 | # node default { 29 | # include stdlib 30 | # class { java: stage => 'runtime' } 31 | # } 32 | # 33 | class stdlib::stages { 34 | 35 | stage { 'setup': before => Stage['main'] } 36 | stage { 'runtime': require => Stage['main'] } 37 | -> stage { 'setup_infra': } 38 | -> stage { 'deploy_infra': } 39 | -> stage { 'setup_app': } 40 | -> stage { 'deploy_app': } 41 | -> stage { 'deploy': } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /modules/stdlib/spec/classes/anchor_spec.rb: -------------------------------------------------------------------------------- 1 | require 'puppet' 2 | require 'rspec-puppet' 3 | 4 | describe "anchorrefresh" do 5 | let(:node) { 'testhost.example.com' } 6 | let :pre_condition do 7 | <<-ANCHORCLASS 8 | class anchored { 9 | anchor { 'anchored::begin': } 10 | ~> anchor { 'anchored::end': } 11 | } 12 | 13 | class anchorrefresh { 14 | notify { 'first': } 15 | ~> class { 'anchored': } 16 | ~> anchor { 'final': } 17 | } 18 | ANCHORCLASS 19 | end 20 | 21 | def apply_catalog_and_return_exec_rsrc 22 | catalog = subject.to_ral 23 | transaction = catalog.apply 24 | transaction.resource_status("Anchor[final]") 25 | end 26 | 27 | it 'propagates events through the anchored class' do 28 | resource = apply_catalog_and_return_exec_rsrc 29 | 30 | expect(resource.restarted).to eq(true) 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /modules/stdlib/spec/fixtures/manifests/site.pp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naftulikay/docker-puppetmaster/cdaa92f1193e4844e174631a7b86bbb5203b50f8/modules/stdlib/spec/fixtures/manifests/site.pp -------------------------------------------------------------------------------- /modules/stdlib/spec/functions/ensure_packages_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby 2 | 3 | require 'spec_helper' 4 | require 'rspec-puppet' 5 | 6 | describe 'ensure_packages' do 7 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 8 | 9 | describe 'argument handling' do 10 | it 'fails with no arguments' do 11 | should run.with_params().and_raise_error(Puppet::ParseError) 12 | end 13 | it 'requires an array' do 14 | lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error 15 | end 16 | it 'fails when given a string' do 17 | should run.with_params('foo').and_raise_error(Puppet::ParseError) 18 | end 19 | end 20 | 21 | context 'given a catalog containing Package[puppet]{ensure => absent}' do 22 | let :pre_condition do 23 | 'package { puppet: ensure => absent }' 24 | end 25 | 26 | # NOTE: should run.with_params has the side effect of making the compiler 27 | # available to the test harness. 28 | it 'has no effect on Package[puppet]' do 29 | should run.with_params(['puppet']) 30 | rsrc = compiler.catalog.resource('Package[puppet]') 31 | rsrc.to_hash.should == {:ensure => "absent"} 32 | end 33 | end 34 | 35 | context 'given a clean catalog' do 36 | it 'declares package resources with ensure => present' do 37 | should run.with_params(['facter']) 38 | rsrc = compiler.catalog.resource('Package[facter]') 39 | rsrc.to_hash.should == {:name => "facter", :ensure => "present"} 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /modules/stdlib/spec/functions/getparam_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | require 'rspec-puppet' 5 | describe 'getparam' do 6 | describe 'when a resource is not specified' do 7 | it do 8 | should run.with_params().and_raise_error(ArgumentError) 9 | should run.with_params('User[dan]').and_raise_error(ArgumentError) 10 | should run.with_params('User[dan]', {}).and_raise_error(ArgumentError) 11 | should run.with_params('User[dan]', '').and_return('') 12 | end 13 | end 14 | describe 'when compared against a resource with no params' do 15 | let :pre_condition do 16 | 'user { "dan": }' 17 | end 18 | it do 19 | should run.with_params('User[dan]', 'shell').and_return('') 20 | end 21 | end 22 | 23 | describe 'when compared against a resource with params' do 24 | let :pre_condition do 25 | 'user { "dan": ensure => present, shell => "/bin/sh", managehome => false}' 26 | end 27 | it do 28 | should run.with_params('User[dan]', 'shell').and_return('/bin/sh') 29 | should run.with_params('User[dan]', '').and_return('') 30 | should run.with_params('User[dan]', 'ensure').and_return('present') 31 | should run.with_params('User[dan]', 'managehome').and_return(false) 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /modules/stdlib/spec/monkey_patches/alias_should_to_must.rb: -------------------------------------------------------------------------------- 1 | require 'rspec' 2 | 3 | class Object 4 | # This is necessary because the RAL has a 'should' 5 | # method. 6 | alias :must :should 7 | alias :must_not :should_not 8 | end 9 | -------------------------------------------------------------------------------- /modules/stdlib/spec/monkey_patches/publicize_methods.rb: -------------------------------------------------------------------------------- 1 | # Some monkey-patching to allow us to test private methods. 2 | class Class 3 | def publicize_methods(*methods) 4 | saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods 5 | 6 | self.class_eval { public(*saved_private_instance_methods) } 7 | yield 8 | self.class_eval { private(*saved_private_instance_methods) } 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /modules/stdlib/spec/spec.opts: -------------------------------------------------------------------------------- 1 | --format 2 | s 3 | --colour 4 | --loadby 5 | mtime 6 | --backtrace 7 | -------------------------------------------------------------------------------- /modules/stdlib/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | dir = File.expand_path(File.dirname(__FILE__)) 2 | $LOAD_PATH.unshift File.join(dir, 'lib') 3 | 4 | # Don't want puppet getting the command line arguments for rake or autotest 5 | ARGV.clear 6 | 7 | require 'puppet' 8 | require 'facter' 9 | require 'mocha' 10 | gem 'rspec', '>=2.0.0' 11 | require 'rspec/expectations' 12 | 13 | require 'puppetlabs_spec_helper/module_spec_helper' 14 | 15 | RSpec.configure do |config| 16 | # FIXME REVISIT - We may want to delegate to Facter like we do in 17 | # Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because 18 | # this behavior is a duplication of the spec_helper in Facter. 19 | config.before :each do 20 | # Ensure that we don't accidentally cache facts and environment between 21 | # test cases. This requires each example group to explicitly load the 22 | # facts being exercised with something like 23 | # Facter.collection.loader.load(:ipaddress) 24 | Facter::Util::Loader.any_instance.stubs(:load_all) 25 | Facter.clear 26 | Facter.clear_messages 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | require 'facter/util/puppet_settings' 3 | 4 | describe Facter::Util::PuppetSettings do 5 | 6 | describe "#with_puppet" do 7 | context "Without Puppet loaded" do 8 | before(:each) do 9 | Module.expects(:const_get).with("Puppet").raises(NameError) 10 | end 11 | 12 | it 'should be nil' do 13 | subject.with_puppet { Puppet[:vardir] }.should be_nil 14 | end 15 | it 'should not yield to the block' do 16 | Puppet.expects(:[]).never 17 | subject.with_puppet { Puppet[:vardir] }.should be_nil 18 | end 19 | end 20 | context "With Puppet loaded" do 21 | module Puppet; end 22 | let(:vardir) { "/var/lib/puppet" } 23 | 24 | before :each do 25 | Puppet.expects(:[]).with(:vardir).returns vardir 26 | end 27 | it 'should yield to the block' do 28 | subject.with_puppet { Puppet[:vardir] } 29 | end 30 | it 'should return the nodes vardir' do 31 | subject.with_puppet { Puppet[:vardir] }.should eq vardir 32 | end 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | 3 | require 'spec_helper' 4 | 5 | describe "the abs function" do 6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 7 | 8 | it "should exist" do 9 | Puppet::Parser::Functions.function("abs").should == "function_abs" 10 | end 11 | 12 | it "should raise a ParseError if there is less than 1 arguments" do 13 | lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError)) 14 | end 15 | 16 | it "should convert a negative number into a positive" do 17 | result = scope.function_abs(["-34"]) 18 | result.should(eq(34)) 19 | end 20 | 21 | it "should do nothing with a positive number" do 22 | result = scope.function_abs(["5678"]) 23 | result.should(eq(5678)) 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the bool2num function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("bool2num").should == "function_bool2num" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should convert true to 1" do 16 | result = scope.function_bool2num([true]) 17 | result.should(eq(1)) 18 | end 19 | 20 | it "should convert false to 0" do 21 | result = scope.function_bool2num([false]) 22 | result.should(eq(0)) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the capitalize function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("capitalize").should == "function_capitalize" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should capitalize the beginning of a string" do 16 | result = scope.function_capitalize(["abc"]) 17 | result.should(eq("Abc")) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the chomp function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("chomp").should == "function_chomp" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_chomp([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should chomp the end of a string" do 16 | result = scope.function_chomp(["abc\n"]) 17 | result.should(eq("abc")) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the chop function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("chop").should == "function_chop" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_chop([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should chop the end of a string" do 16 | result = scope.function_chop(["asdf\n"]) 17 | result.should(eq("asdf")) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the concat function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should raise a ParseError if there is less than 1 arguments" do 8 | lambda { scope.function_concat([]) }.should( raise_error(Puppet::ParseError)) 9 | end 10 | 11 | it "should be able to concat an array" do 12 | result = scope.function_concat([['1','2','3'],['4','5','6']]) 13 | result.should(eq(['1','2','3','4','5','6'])) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/count_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | 3 | require 'spec_helper' 4 | 5 | describe "the count function" do 6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 7 | 8 | it "should exist" do 9 | Puppet::Parser::Functions.function("count").should == "function_count" 10 | end 11 | 12 | it "should raise a ArgumentError if there is more than 2 arguments" do 13 | lambda { scope.function_count(['foo', 'bar', 'baz']) }.should( raise_error(ArgumentError)) 14 | end 15 | 16 | it "should be able to count arrays" do 17 | scope.function_count([["1","2","3"]]).should(eq(3)) 18 | end 19 | 20 | it "should be able to count matching elements in arrays" do 21 | scope.function_count([["1", "2", "2"], "2"]).should(eq(2)) 22 | end 23 | 24 | it "should not count nil or empty strings" do 25 | scope.function_count([["foo","bar",nil,""]]).should(eq(2)) 26 | end 27 | 28 | it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do 29 | expect(scope.function_count([["foo",:undef,:undef]])).to eq(1) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the delete_at function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("delete_at").should == "function_delete_at" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should delete an item at specified location from an array" do 16 | result = scope.function_delete_at([['a','b','c'],1]) 17 | result.should(eq(['a','c'])) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the delete function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("delete").should == "function_delete" 9 | end 10 | 11 | it "should raise a ParseError if there are fewer than 2 arguments" do 12 | lambda { scope.function_delete([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should raise a ParseError if there are greater than 2 arguments" do 16 | lambda { scope.function_delete([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError)) 17 | end 18 | 19 | it "should raise a TypeError if a number is passed as the first argument" do 20 | lambda { scope.function_delete([1, 'bar']) }.should( raise_error(TypeError)) 21 | end 22 | 23 | it "should delete all instances of an element from an array" do 24 | result = scope.function_delete([['a','b','c','b'],'b']) 25 | result.should(eq(['a','c'])) 26 | end 27 | 28 | it "should delete all instances of a substring from a string" do 29 | result = scope.function_delete(['foobarbabarz','bar']) 30 | result.should(eq('foobaz')) 31 | end 32 | 33 | it "should delete a key from a hash" do 34 | result = scope.function_delete([{ 'a' => 1, 'b' => 2, 'c' => 3 },'b']) 35 | result.should(eq({ 'a' => 1, 'c' => 3 })) 36 | end 37 | 38 | end 39 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the dirname function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("dirname").should == "function_dirname" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_dirname([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return dirname for an absolute path" do 16 | result = scope.function_dirname(['/path/to/a/file.ext']) 17 | result.should(eq('/path/to/a')) 18 | end 19 | 20 | it "should return dirname for a relative path" do 21 | result = scope.function_dirname(['path/to/a/file.ext']) 22 | result.should(eq('path/to/a')) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the downcase function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("downcase").should == "function_downcase" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_downcase([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should downcase a string" do 16 | result = scope.function_downcase(["ASFD"]) 17 | result.should(eq("asfd")) 18 | end 19 | 20 | it "should do nothing to a string that is already downcase" do 21 | result = scope.function_downcase(["asdf asdf"]) 22 | result.should(eq("asdf asdf")) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the empty function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | it "should exist" do 7 | Puppet::Parser::Functions.function("empty").should == "function_empty" 8 | end 9 | 10 | it "should raise a ParseError if there is less than 1 arguments" do 11 | lambda { scope.function_empty([]) }.should( raise_error(Puppet::ParseError)) 12 | end 13 | 14 | it "should return a true for an empty string" do 15 | result = scope.function_empty(['']) 16 | result.should(eq(true)) 17 | end 18 | 19 | it "should return a false for a non-empty string" do 20 | result = scope.function_empty(['asdf']) 21 | result.should(eq(false)) 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the flatten function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | it "should exist" do 7 | Puppet::Parser::Functions.function("flatten").should == "function_flatten" 8 | end 9 | 10 | it "should raise a ParseError if there is less than 1 arguments" do 11 | lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError)) 12 | end 13 | 14 | it "should raise a ParseError if there is more than 1 argument" do 15 | lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError)) 16 | end 17 | 18 | it "should flatten a complex data structure" do 19 | result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]]) 20 | result.should(eq(["a","b","c","d","e","f","g"])) 21 | end 22 | 23 | it "should do nothing to a structure that is already flat" do 24 | result = scope.function_flatten([["a","b","c","d"]]) 25 | result.should(eq(["a","b","c","d"])) 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | 3 | require 'spec_helper' 4 | 5 | describe "the floor function" do 6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 7 | 8 | it "should exist" do 9 | Puppet::Parser::Functions.function("floor").should == "function_floor" 10 | end 11 | 12 | it "should raise a ParseError if there is less than 1 argument" do 13 | lambda { scope.function_floor([]) }.should( raise_error(Puppet::ParseError, /Wrong number of arguments/)) 14 | end 15 | 16 | it "should should raise a ParseError if input isn't numeric (eg. String)" do 17 | lambda { scope.function_floor(["foo"]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/)) 18 | end 19 | 20 | it "should should raise a ParseError if input isn't numeric (eg. Boolean)" do 21 | lambda { scope.function_floor([true]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/)) 22 | end 23 | 24 | it "should return an integer when a numeric type is passed" do 25 | result = scope.function_floor([12.4]) 26 | result.is_a?(Integer).should(eq(true)) 27 | end 28 | 29 | it "should return the input when an integer is passed" do 30 | result = scope.function_floor([7]) 31 | result.should(eq(7)) 32 | end 33 | 34 | it "should return the largest integer less than or equal to the input" do 35 | result = scope.function_floor([3.8]) 36 | result.should(eq(3)) 37 | end 38 | end 39 | 40 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the fqdn_rotate function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("fqdn_rotate").should == "function_fqdn_rotate" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_fqdn_rotate([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should rotate a string and the result should be the same size" do 16 | scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") 17 | result = scope.function_fqdn_rotate(["asdf"]) 18 | result.size.should(eq(4)) 19 | end 20 | 21 | it "should rotate a string to give the same results for one host" do 22 | scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice 23 | scope.function_fqdn_rotate(["abcdefg"]).should eql(scope.function_fqdn_rotate(["abcdefg"])) 24 | end 25 | 26 | it "should rotate a string to give different values on different hosts" do 27 | scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") 28 | val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"]) 29 | scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2") 30 | val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"]) 31 | val1.should_not eql(val2) 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe Puppet::Parser::Functions.function(:getvar) do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | describe 'when calling getvar from puppet' do 7 | 8 | it "should not compile when no arguments are passed" do 9 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ 10 | Puppet[:code] = '$foo = getvar()' 11 | expect { 12 | scope.compiler.compile 13 | }.to raise_error(Puppet::ParseError, /wrong number of arguments/) 14 | end 15 | 16 | it "should not compile when too many arguments are passed" do 17 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ 18 | Puppet[:code] = '$foo = getvar("foo::bar", "baz")' 19 | expect { 20 | scope.compiler.compile 21 | }.to raise_error(Puppet::ParseError, /wrong number of arguments/) 22 | end 23 | 24 | it "should lookup variables in other namespaces" do 25 | pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ 26 | Puppet[:code] = <<-'ENDofPUPPETcode' 27 | class site::data { $foo = 'baz' } 28 | include site::data 29 | $foo = getvar("site::data::foo") 30 | if $foo != 'baz' { 31 | fail('getvar did not return what we expect') 32 | } 33 | ENDofPUPPETcode 34 | scope.compiler.compile 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the grep function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("grep").should == "function_grep" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_grep([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should grep contents from an array" do 16 | result = scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"]) 17 | result.should(eq(["aaabbb","bbbccc"])) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe Puppet::Parser::Functions.function(:has_ip_address) do 5 | 6 | let(:scope) do 7 | PuppetlabsSpec::PuppetInternals.scope 8 | end 9 | 10 | subject do 11 | function_name = Puppet::Parser::Functions.function(:has_ip_address) 12 | scope.method(function_name) 13 | end 14 | 15 | context "On Linux Systems" do 16 | before :each do 17 | scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo') 18 | scope.stubs(:lookupvar).with('ipaddress').returns('10.0.2.15') 19 | scope.stubs(:lookupvar).with('ipaddress_eth0').returns('10.0.2.15') 20 | scope.stubs(:lookupvar).with('ipaddress_lo').returns('127.0.0.1') 21 | end 22 | 23 | it 'should have primary address (10.0.2.15)' do 24 | subject.call(['10.0.2.15']).should be_true 25 | end 26 | 27 | it 'should have lookupback address (127.0.0.1)' do 28 | subject.call(['127.0.0.1']).should be_true 29 | end 30 | 31 | it 'should not have other address' do 32 | subject.call(['192.1681.1.1']).should be_false 33 | end 34 | 35 | it 'should not have "mspiggy" on an interface' do 36 | subject.call(['mspiggy']).should be_false 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe Puppet::Parser::Functions.function(:has_ip_network) do 5 | 6 | let(:scope) do 7 | PuppetlabsSpec::PuppetInternals.scope 8 | end 9 | 10 | subject do 11 | function_name = Puppet::Parser::Functions.function(:has_ip_network) 12 | scope.method(function_name) 13 | end 14 | 15 | context "On Linux Systems" do 16 | before :each do 17 | scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo') 18 | scope.stubs(:lookupvar).with('network').returns(:undefined) 19 | scope.stubs(:lookupvar).with('network_eth0').returns('10.0.2.0') 20 | scope.stubs(:lookupvar).with('network_lo').returns('127.0.0.1') 21 | end 22 | 23 | it 'should have primary network (10.0.2.0)' do 24 | subject.call(['10.0.2.0']).should be_true 25 | end 26 | 27 | it 'should have loopback network (127.0.0.0)' do 28 | subject.call(['127.0.0.1']).should be_true 29 | end 30 | 31 | it 'should not have other network' do 32 | subject.call(['192.168.1.0']).should be_false 33 | end 34 | end 35 | end 36 | 37 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the hash function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("hash").should == "function_hash" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_hash([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should convert an array to a hash" do 16 | result = scope.function_hash([['a',1,'b',2,'c',3]]) 17 | result.should(eq({'a'=>1,'b'=>2,'c'=>3})) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the is_array function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("is_array").should == "function_is_array" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_is_array([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return true if passed an array" do 16 | result = scope.function_is_array([[1,2,3]]) 17 | result.should(eq(true)) 18 | end 19 | 20 | it "should return false if passed a hash" do 21 | result = scope.function_is_array([{'a'=>1}]) 22 | result.should(eq(false)) 23 | end 24 | 25 | it "should return false if passed a string" do 26 | result = scope.function_is_array(["asdf"]) 27 | result.should(eq(false)) 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the is_float function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("is_float").should == "function_is_float" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_is_float([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return true if a float" do 16 | result = scope.function_is_float(["0.12"]) 17 | result.should(eq(true)) 18 | end 19 | 20 | it "should return false if a string" do 21 | result = scope.function_is_float(["asdf"]) 22 | result.should(eq(false)) 23 | end 24 | 25 | it "should return false if an integer" do 26 | result = scope.function_is_float(["3"]) 27 | result.should(eq(false)) 28 | end 29 | it "should return true if a float is created from an arithmetical operation" do 30 | result = scope.function_is_float([3.2*2]) 31 | result.should(eq(true)) 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rspec 2 | require 'spec_helper' 3 | 4 | describe "the is_function_available function" do 5 | before :all do 6 | Puppet::Parser::Functions.autoloader.loadall 7 | end 8 | 9 | before :each do 10 | @scope = Puppet::Parser::Scope.new 11 | end 12 | 13 | it "should exist" do 14 | Puppet::Parser::Functions.function("is_function_available").should == "function_is_function_available" 15 | end 16 | 17 | it "should raise a ParseError if there is less than 1 arguments" do 18 | lambda { @scope.function_is_function_available([]) }.should( raise_error(Puppet::ParseError)) 19 | end 20 | 21 | it "should return false if a nonexistent function is passed" do 22 | result = @scope.function_is_function_available(['jeff_mccunes_left_sock']) 23 | result.should(eq(false)) 24 | end 25 | 26 | it "should return true if an available function is passed" do 27 | result = @scope.function_is_function_available(['require']) 28 | result.should(eq(true)) 29 | end 30 | 31 | end 32 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the is_hash function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("is_hash").should == "function_is_hash" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return true if passed a hash" do 16 | result = scope.function_is_hash([{"a"=>1,"b"=>2}]) 17 | result.should(eq(true)) 18 | end 19 | 20 | it "should return false if passed an array" do 21 | result = scope.function_is_hash([["a","b"]]) 22 | result.should(eq(false)) 23 | end 24 | 25 | it "should return false if passed a string" do 26 | result = scope.function_is_hash(["asdf"]) 27 | result.should(eq(false)) 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the is_integer function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("is_integer").should == "function_is_integer" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return true if an integer" do 16 | result = scope.function_is_integer(["3"]) 17 | result.should(eq(true)) 18 | end 19 | 20 | it "should return false if a float" do 21 | result = scope.function_is_integer(["3.2"]) 22 | result.should(eq(false)) 23 | end 24 | 25 | it "should return false if a string" do 26 | result = scope.function_is_integer(["asdf"]) 27 | result.should(eq(false)) 28 | end 29 | 30 | it "should return true if an integer is created from an arithmetical operation" do 31 | result = scope.function_is_integer([3*2]) 32 | result.should(eq(true)) 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the is_ip_address function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("is_ip_address").should == "function_is_ip_address" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return true if an IPv4 address" do 16 | result = scope.function_is_ip_address(["1.2.3.4"]) 17 | result.should(eq(true)) 18 | end 19 | 20 | it "should return true if a full IPv6 address" do 21 | result = scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"]) 22 | result.should(eq(true)) 23 | end 24 | 25 | it "should return true if a compressed IPv6 address" do 26 | result = scope.function_is_ip_address(["fe00::1"]) 27 | result.should(eq(true)) 28 | end 29 | 30 | it "should return false if not valid" do 31 | result = scope.function_is_ip_address(["asdf"]) 32 | result.should(eq(false)) 33 | end 34 | 35 | it "should return false if IP octets out of range" do 36 | result = scope.function_is_ip_address(["1.1.1.300"]) 37 | result.should(eq(false)) 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the is_mac_address function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("is_mac_address").should == "function_is_mac_address" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return true if a valid mac address" do 16 | result = scope.function_is_mac_address(["00:a0:1f:12:7f:a0"]) 17 | result.should(eq(true)) 18 | end 19 | 20 | it "should return false if octets are out of range" do 21 | result = scope.function_is_mac_address(["00:a0:1f:12:7f:g0"]) 22 | result.should(eq(false)) 23 | end 24 | 25 | it "should return false if not valid" do 26 | result = scope.function_is_mac_address(["not valid"]) 27 | result.should(eq(false)) 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the is_numeric function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("is_numeric").should == "function_is_numeric" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 argument" do 12 | lambda { scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return true if an integer" do 16 | result = scope.function_is_numeric(["3"]) 17 | result.should(eq(true)) 18 | end 19 | 20 | it "should return true if a float" do 21 | result = scope.function_is_numeric(["3.2"]) 22 | result.should(eq(true)) 23 | end 24 | 25 | it "should return true if an integer is created from an arithmetical operation" do 26 | result = scope.function_is_numeric([3*2]) 27 | result.should(eq(true)) 28 | end 29 | 30 | it "should return true if a float is created from an arithmetical operation" do 31 | result = scope.function_is_numeric([3.2*2]) 32 | result.should(eq(true)) 33 | end 34 | 35 | it "should return false if a string" do 36 | result = scope.function_is_numeric(["asdf"]) 37 | result.should(eq(false)) 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the is_string function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("is_string").should == "function_is_string" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_is_string([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return true if a string" do 16 | result = scope.function_is_string(["asdf"]) 17 | result.should(eq(true)) 18 | end 19 | 20 | it "should return false if an integer" do 21 | result = scope.function_is_string(["3"]) 22 | result.should(eq(false)) 23 | end 24 | 25 | it "should return false if a float" do 26 | result = scope.function_is_string(["3.23"]) 27 | result.should(eq(false)) 28 | end 29 | 30 | it "should return false if an array" do 31 | result = scope.function_is_string([["a","b","c"]]) 32 | result.should(eq(false)) 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the join function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("join").should == "function_join" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_join([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should join an array into a string" do 16 | result = scope.function_join([["a","b","c"], ":"]) 17 | result.should(eq("a:b:c")) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the keys function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("keys").should == "function_keys" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_keys([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return an array of keys when given a hash" do 16 | result = scope.function_keys([{'a'=>1, 'b'=>2}]) 17 | # =~ performs 'array with same elements' (set) matching 18 | # For more info see RSpec::Matchers::MatchArray 19 | result.should =~ ['a','b'] 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the lstrip function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("lstrip").should == "function_lstrip" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should lstrip a string" do 16 | result = scope.function_lstrip([" asdf"]) 17 | result.should(eq('asdf')) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | 3 | require 'spec_helper' 4 | 5 | describe "the max function" do 6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 7 | 8 | it "should exist" do 9 | Puppet::Parser::Functions.function("max").should == "function_max" 10 | end 11 | 12 | it "should raise a ParseError if there is less than 1 arguments" do 13 | lambda { scope.function_max([]) }.should( raise_error(Puppet::ParseError)) 14 | end 15 | 16 | it "should be able to compare strings" do 17 | scope.function_max(["albatross","dog","horse"]).should(eq("horse")) 18 | end 19 | 20 | it "should be able to compare numbers" do 21 | scope.function_max([6,8,4]).should(eq(8)) 22 | end 23 | 24 | it "should be able to compare a number with a stringified number" do 25 | scope.function_max([1,"2"]).should(eq("2")) 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the member function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("member").should == "function_member" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_member([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return true if a member is in an array" do 16 | result = scope.function_member([["a","b","c"], "a"]) 17 | result.should(eq(true)) 18 | end 19 | 20 | it "should return false if a member is not in an array" do 21 | result = scope.function_member([["a","b","c"], "d"]) 22 | result.should(eq(false)) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | 3 | require 'spec_helper' 4 | 5 | describe "the min function" do 6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 7 | 8 | it "should exist" do 9 | Puppet::Parser::Functions.function("min").should == "function_min" 10 | end 11 | 12 | it "should raise a ParseError if there is less than 1 arguments" do 13 | lambda { scope.function_min([]) }.should( raise_error(Puppet::ParseError)) 14 | end 15 | 16 | it "should be able to compare strings" do 17 | scope.function_min(["albatross","dog","horse"]).should(eq("albatross")) 18 | end 19 | 20 | it "should be able to compare numbers" do 21 | scope.function_min([6,8,4]).should(eq(4)) 22 | end 23 | 24 | it "should be able to compare a number with a stringified number" do 25 | scope.function_min([1,"2"]).should(eq(1)) 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the parsejson function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("parsejson").should == "function_parsejson" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should convert JSON to a data structure" do 16 | json = <<-EOS 17 | ["aaa","bbb","ccc"] 18 | EOS 19 | result = scope.function_parsejson([json]) 20 | result.should(eq(['aaa','bbb','ccc'])) 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the parseyaml function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should convert YAML to a data structure" do 16 | yaml = <<-EOS 17 | - aaa 18 | - bbb 19 | - ccc 20 | EOS 21 | result = scope.function_parseyaml([yaml]) 22 | result.should(eq(['aaa','bbb','ccc'])) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the pick function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("pick").should == "function_pick" 9 | end 10 | 11 | it 'should return the correct value' do 12 | scope.function_pick(['first', 'second']).should == 'first' 13 | end 14 | 15 | it 'should return the correct value if the first value is empty' do 16 | scope.function_pick(['', 'second']).should == 'second' 17 | end 18 | 19 | it 'should remove empty string values' do 20 | scope.function_pick(['', 'first']).should == 'first' 21 | end 22 | 23 | it 'should remove :undef values' do 24 | scope.function_pick([:undef, 'first']).should == 'first' 25 | end 26 | 27 | it 'should remove :undefined values' do 28 | scope.function_pick([:undefined, 'first']).should == 'first' 29 | end 30 | 31 | it 'should error if no values are passed' do 32 | expect { scope.function_pick([]) }.to raise_error(Puppet::Error, /Must provide non empty value./) 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the prefix function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("prefix").should == "function_prefix" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_prefix([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return a prefixed array" do 16 | result = scope.function_prefix([['a','b','c'], 'p']) 17 | result.should(eq(['pa','pb','pc'])) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the range function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("range").should == "function_range" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_range([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return a letter range" do 16 | result = scope.function_range(["a","d"]) 17 | result.should(eq(['a','b','c','d'])) 18 | end 19 | 20 | it "should return a number range" do 21 | result = scope.function_range(["1","4"]) 22 | result.should(eq([1,2,3,4])) 23 | end 24 | 25 | it "should work with padded hostname like strings" do 26 | expected = ("host01".."host10").to_a 27 | scope.function_range(["host01","host10"]).should eq expected 28 | end 29 | 30 | it "should coerce zero padded digits to integers" do 31 | expected = (0..10).to_a 32 | scope.function_range(["00", "10"]).should eq expected 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'spec_helper' 4 | 5 | describe "the reject function" do 6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 7 | 8 | it "should exist" do 9 | Puppet::Parser::Functions.function("reject").should == "function_reject" 10 | end 11 | 12 | it "should raise a ParseError if there is less than 1 arguments" do 13 | lambda { scope.function_reject([]) }.should( raise_error(Puppet::ParseError)) 14 | end 15 | 16 | it "should reject contents from an array" do 17 | result = scope.function_reject([["1111", "aaabbb","bbbccc","dddeee"], "bbb"]) 18 | result.should(eq(["1111", "dddeee"])) 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the reverse function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("reverse").should == "function_reverse" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_reverse([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should reverse a string" do 16 | result = scope.function_reverse(["asdfghijkl"]) 17 | result.should(eq('lkjihgfdsa')) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the rstrip function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("rstrip").should == "function_rstrip" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_rstrip([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should rstrip a string" do 16 | result = scope.function_rstrip(["asdf "]) 17 | result.should(eq('asdf')) 18 | end 19 | 20 | it "should rstrip each element in an array" do 21 | result = scope.function_rstrip([["a ","b ", "c "]]) 22 | result.should(eq(['a','b','c'])) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the shuffle function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("shuffle").should == "function_shuffle" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_shuffle([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should shuffle a string and the result should be the same size" do 16 | result = scope.function_shuffle(["asdf"]) 17 | result.size.should(eq(4)) 18 | end 19 | 20 | it "should shuffle a string but the sorted contents should still be the same" do 21 | result = scope.function_shuffle(["adfs"]) 22 | result.split("").sort.join("").should(eq("adfs")) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the size function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("size").should == "function_size" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_size([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return the size of a string" do 16 | result = scope.function_size(["asdf"]) 17 | result.should(eq(4)) 18 | end 19 | 20 | it "should return the size of an array" do 21 | result = scope.function_size([["a","b","c"]]) 22 | result.should(eq(3)) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the sort function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("sort").should == "function_sort" 9 | end 10 | 11 | it "should raise a ParseError if there is not 1 arguments" do 12 | lambda { scope.function_sort(['','']) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should sort an array" do 16 | result = scope.function_sort([["a","c","b"]]) 17 | result.should(eq(['a','b','c'])) 18 | end 19 | 20 | it "should sort a string" do 21 | result = scope.function_sort(["acb"]) 22 | result.should(eq('abc')) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the squeeze function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("squeeze").should == "function_squeeze" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 2 arguments" do 12 | lambda { scope.function_squeeze([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should squeeze a string" do 16 | result = scope.function_squeeze(["aaabbbbcccc"]) 17 | result.should(eq('abc')) 18 | end 19 | 20 | it "should squeeze all elements in an array" do 21 | result = scope.function_squeeze([["aaabbbbcccc","dddfff"]]) 22 | result.should(eq(['abc','df'])) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the str2bool function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("str2bool").should == "function_str2bool" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_str2bool([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should convert string 'true' to true" do 16 | result = scope.function_str2bool(["true"]) 17 | result.should(eq(true)) 18 | end 19 | 20 | it "should convert string 'undef' to false" do 21 | result = scope.function_str2bool(["undef"]) 22 | result.should(eq(false)) 23 | end 24 | 25 | it "should return the boolean it was called with" do 26 | result = scope.function_str2bool([true]) 27 | result.should(eq(true)) 28 | result = scope.function_str2bool([false]) 29 | result.should(eq(false)) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the strftime function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("strftime").should == "function_strftime" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_strftime([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "using %s should be higher then when I wrote this test" do 16 | result = scope.function_strftime(["%s"]) 17 | result.to_i.should(be > 1311953157) 18 | end 19 | 20 | it "using %s should be lower then 1.5 trillion" do 21 | result = scope.function_strftime(["%s"]) 22 | result.to_i.should(be < 1500000000) 23 | end 24 | 25 | it "should return a date when given %Y-%m-%d" do 26 | result = scope.function_strftime(["%Y-%m-%d"]) 27 | result.should =~ /^\d{4}-\d{2}-\d{2}$/ 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the strip function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | it "should exist" do 7 | Puppet::Parser::Functions.function("strip").should == "function_strip" 8 | end 9 | 10 | it "should raise a ParseError if there is less than 1 arguments" do 11 | lambda { scope.function_strip([]) }.should( raise_error(Puppet::ParseError)) 12 | end 13 | 14 | it "should strip a string" do 15 | result = scope.function_strip([" ab cd "]) 16 | result.should(eq('ab cd')) 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the suffix function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("suffix").should == "function_suffix" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_suffix([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return a suffixed array" do 16 | result = scope.function_suffix([['a','b','c'], 'p']) 17 | result.should(eq(['ap','bp','cp'])) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the swapcase function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("swapcase").should == "function_swapcase" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_swapcase([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should swapcase a string" do 16 | result = scope.function_swapcase(["aaBBccDD"]) 17 | result.should(eq('AAbbCCdd')) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the time function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("time").should == "function_time" 9 | end 10 | 11 | it "should raise a ParseError if there is more than 2 arguments" do 12 | lambda { scope.function_time(['','']) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return a number" do 16 | result = scope.function_time([]) 17 | result.should be_an(Integer) 18 | end 19 | 20 | it "should be higher then when I wrote this test" do 21 | result = scope.function_time([]) 22 | result.should(be > 1311953157) 23 | end 24 | 25 | it "should be lower then 1.5 trillion" do 26 | result = scope.function_time([]) 27 | result.should(be < 1500000000) 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the type function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | it "should exist" do 7 | Puppet::Parser::Functions.function("type").should == "function_type" 8 | end 9 | 10 | it "should raise a ParseError if there is less than 1 arguments" do 11 | lambda { scope.function_type([]) }.should( raise_error(Puppet::ParseError)) 12 | end 13 | 14 | it "should return string when given a string" do 15 | result = scope.function_type(["aaabbbbcccc"]) 16 | result.should(eq('string')) 17 | end 18 | 19 | it "should return array when given an array" do 20 | result = scope.function_type([["aaabbbbcccc","asdf"]]) 21 | result.should(eq('array')) 22 | end 23 | 24 | it "should return hash when given a hash" do 25 | result = scope.function_type([{"a"=>1,"b"=>2}]) 26 | result.should(eq('hash')) 27 | end 28 | 29 | it "should return integer when given an integer" do 30 | result = scope.function_type(["1"]) 31 | result.should(eq('integer')) 32 | end 33 | 34 | it "should return float when given a float" do 35 | result = scope.function_type(["1.34"]) 36 | result.should(eq('float')) 37 | end 38 | 39 | it "should return boolean when given a boolean" do 40 | result = scope.function_type([true]) 41 | result.should(eq('boolean')) 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the unique function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("unique").should == "function_unique" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_unique([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should remove duplicate elements in a string" do 16 | result = scope.function_unique(["aabbc"]) 17 | result.should(eq('abc')) 18 | end 19 | 20 | it "should remove duplicate elements in an array" do 21 | result = scope.function_unique([["a","a","b","b","c"]]) 22 | result.should(eq(['a','b','c'])) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the upcase function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("upcase").should == "function_upcase" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_upcase([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should upcase a string" do 16 | result = scope.function_upcase(["abc"]) 17 | result.should(eq('ABC')) 18 | end 19 | 20 | it "should do nothing if a string is already upcase" do 21 | result = scope.function_upcase(["ABC"]) 22 | result.should(eq('ABC')) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the uriescape function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("uriescape").should == "function_uriescape" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_uriescape([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should uriescape a string" do 16 | result = scope.function_uriescape([":/?#[]@!$&'()*+,;= "]) 17 | result.should(eq('%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%20')) 18 | end 19 | 20 | it "should do nothing if a string is already safe" do 21 | result = scope.function_uriescape(["ABCdef"]) 22 | result.should(eq('ABCdef')) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | 3 | require 'spec_helper' 4 | 5 | describe Puppet::Parser::Functions.function(:validate_array) do 6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 7 | describe 'when calling validate_array from puppet' do 8 | 9 | %w{ true false }.each do |the_string| 10 | it "should not compile when #{the_string} is a string" do 11 | Puppet[:code] = "validate_array('#{the_string}')" 12 | expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) 13 | end 14 | 15 | it "should not compile when #{the_string} is a bare word" do 16 | Puppet[:code] = "validate_array(#{the_string})" 17 | expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) 18 | end 19 | end 20 | 21 | it "should compile when multiple array arguments are passed" do 22 | Puppet[:code] = <<-'ENDofPUPPETcode' 23 | $foo = [ ] 24 | $bar = [ 'one', 'two' ] 25 | validate_array($foo, $bar) 26 | ENDofPUPPETcode 27 | scope.compiler.compile 28 | end 29 | 30 | it "should not compile when an undef variable is passed" do 31 | Puppet[:code] = <<-'ENDofPUPPETcode' 32 | $foo = undef 33 | validate_array($foo) 34 | ENDofPUPPETcode 35 | expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | 3 | require 'spec_helper' 4 | 5 | describe Puppet::Parser::Functions.function(:validate_hash) do 6 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 7 | 8 | describe 'when calling validate_hash from puppet' do 9 | 10 | %w{ true false }.each do |the_string| 11 | 12 | it "should not compile when #{the_string} is a string" do 13 | Puppet[:code] = "validate_hash('#{the_string}')" 14 | expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) 15 | end 16 | 17 | it "should not compile when #{the_string} is a bare word" do 18 | Puppet[:code] = "validate_hash(#{the_string})" 19 | expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) 20 | end 21 | 22 | end 23 | 24 | it "should compile when multiple hash arguments are passed" do 25 | Puppet[:code] = <<-'ENDofPUPPETcode' 26 | $foo = {} 27 | $bar = { 'one' => 'two' } 28 | validate_hash($foo, $bar) 29 | ENDofPUPPETcode 30 | scope.compiler.compile 31 | end 32 | 33 | it "should not compile when an undef variable is passed" do 34 | Puppet[:code] = <<-'ENDofPUPPETcode' 35 | $foo = undef 36 | validate_hash($foo) 37 | ENDofPUPPETcode 38 | expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) 39 | end 40 | 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the values function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should exist" do 8 | Puppet::Parser::Functions.function("values").should == "function_values" 9 | end 10 | 11 | it "should raise a ParseError if there is less than 1 arguments" do 12 | lambda { scope.function_values([]) }.should( raise_error(Puppet::ParseError)) 13 | end 14 | 15 | it "should return values from a hash" do 16 | result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}]) 17 | # =~ is the RSpec::Matchers::MatchArray matcher. 18 | # A.K.A. "array with same elements" (multiset) matching 19 | result.should =~ %w{ 1 2 3 } 20 | end 21 | 22 | it "should return a multiset" do 23 | result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}]) 24 | result.should =~ %w{ 1 3 3 } 25 | result.should_not =~ %w{ 1 3 } 26 | end 27 | 28 | it "should raise a ParseError unless a Hash is provided" do 29 | lambda { scope.function_values([['a','b','c']]) }.should( raise_error(Puppet::ParseError)) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby -S rspec 2 | require 'spec_helper' 3 | 4 | describe "the zip function" do 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope } 6 | 7 | it "should raise a ParseError if there is less than 1 arguments" do 8 | lambda { scope.function_zip([]) }.should( raise_error(Puppet::ParseError)) 9 | end 10 | 11 | it "should be able to zip an array" do 12 | result = scope.function_zip([['1','2','3'],['4','5','6']]) 13 | result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]])) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /modules/stdlib/spec/unit/puppet/type/anchor_spec.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'puppet' 4 | 5 | anchor = Puppet::Type.type(:anchor).new(:name => "ntp::begin") 6 | 7 | describe anchor do 8 | it "should stringify normally" do 9 | anchor.to_s.should == "Anchor[ntp::begin]" 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /modules/stdlib/tests/file_line.pp: -------------------------------------------------------------------------------- 1 | # This is a simple smoke test 2 | # of the file_line resource type. 3 | file { '/tmp/dansfile': 4 | ensure => present 5 | }-> 6 | file_line { 'dans_line': 7 | line => 'dan is awesome', 8 | path => '/tmp/dansfile', 9 | } 10 | -------------------------------------------------------------------------------- /modules/stdlib/tests/has_interface_with.pp: -------------------------------------------------------------------------------- 1 | include stdlib 2 | info('has_interface_with(\'lo\'):', has_interface_with('lo')) 3 | info('has_interface_with(\'loX\'):', has_interface_with('loX')) 4 | info('has_interface_with(\'ipaddress\', \'127.0.0.1\'):', has_interface_with('ipaddress', '127.0.0.1')) 5 | info('has_interface_with(\'ipaddress\', \'127.0.0.100\'):', has_interface_with('ipaddress', '127.0.0.100')) 6 | info('has_interface_with(\'network\', \'127.0.0.0\'):', has_interface_with('network', '127.0.0.0')) 7 | info('has_interface_with(\'network\', \'128.0.0.0\'):', has_interface_with('network', '128.0.0.0')) 8 | info('has_interface_with(\'netmask\', \'255.0.0.0\'):', has_interface_with('netmask', '255.0.0.0')) 9 | info('has_interface_with(\'netmask\', \'256.0.0.0\'):', has_interface_with('netmask', '256.0.0.0')) 10 | 11 | -------------------------------------------------------------------------------- /modules/stdlib/tests/has_ip_address.pp: -------------------------------------------------------------------------------- 1 | include stdlib 2 | info('has_ip_address(\'192.168.1.256\'):', has_ip_address('192.168.1.256')) 3 | info('has_ip_address(\'127.0.0.1\'):', has_ip_address('127.0.0.1')) 4 | -------------------------------------------------------------------------------- /modules/stdlib/tests/has_ip_network.pp: -------------------------------------------------------------------------------- 1 | include stdlib 2 | info('has_ip_network(\'127.0.0.0\'):', has_ip_network('127.0.0.0')) 3 | info('has_ip_network(\'128.0.0.0\'):', has_ip_network('128.0.0.0')) 4 | 5 | -------------------------------------------------------------------------------- /modules/stdlib/tests/init.pp: -------------------------------------------------------------------------------- 1 | include stdlib 2 | -------------------------------------------------------------------------------- /scripts/12_generate_puppetmaster_keys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # import environment variables 4 | source /etc/container_environment.sh 5 | 6 | # default SSL DNS names for certificate generation hostname,fqdn,puppet,puppet.domain 7 | hostname="$(facter hostname)" 8 | domain="$(facter domain)" 9 | fqdn="$(facter fqdn)" 10 | 11 | test -z "$PUPPETMASTER_DNS_NAMES" && \ 12 | export PUPPETMASTER_DNS_NAMES="$hostname,$fqdn,puppet,puppet.$domain" 13 | 14 | # if there's no certificate yet, generate it 15 | if [ -z "$(puppet cert list -a 2> /dev/null | grep \"$fqdn\")" ]; then 16 | puppet cert generate --path "$PATH" --dns_alt_names "$PUPPETMASTER_DNS_NAMES" $fqdn 17 | fi 18 | -------------------------------------------------------------------------------- /scripts/13_add_puppet_cron.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # load environment variables 4 | source /etc/container_environment.sh 5 | 6 | # default cron setting is every 30 minutes 7 | test -z "$PUPPET_AGENT_CRON" && export PUPPET_AGENT_CRON="0,30 * * * *" 8 | 9 | read -d '' cronscript < /etc/cron.d/puppet && chmod +x /etc/cron.d/puppet 19 | -------------------------------------------------------------------------------- /scripts/nginx-startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | exec nginx -c /etc/nginx/nginx.conf -g "daemon off;" 4 | -------------------------------------------------------------------------------- /scripts/run-puppet-agent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # load environment variables 4 | source /etc/container_environment.sh 5 | 6 | puppet_agent_args="-l syslog -o --no-daemonize --waitforcert 120" 7 | 8 | # if there is a puppet environment defined, append the environment parameter 9 | if [ ! -z "$PUPPET_AGENT_ENVIRONMENT" ]; then 10 | puppet_agent_args="$puppet_agent_args --environment $PUPPET_AGENT_ENVIRONMENT" 11 | fi 12 | 13 | # if they want verbose 14 | if [ ! -z "$PUPPET_AGENT_VERBOSE" ]; then 15 | puppet_agent_args="$puppet_agent_args --verbose" 16 | fi 17 | 18 | # if they want debug 19 | if [ ! -z "$PUPPET_AGENT_DEBUG" ]; then 20 | puppet_agent_args="$puppet_agent_args --debug" 21 | fi 22 | 23 | # run the puppet agent if it's not already running 24 | pgrep -f "/usr/bin/puppet agent" >/dev/null || /usr/bin/puppet agent $puppet_agent_args 25 | --------------------------------------------------------------------------------