utilities/unix/languages/ruby

This commit is contained in:
ts
2018-07-19 13:13:47 +01:00
parent ae1ecd4f37
commit 7aadf4a41b
37 changed files with 5416 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
## Release 1.0.0
### Summary
First major release. Brings it into the modern age with puppet 4, and into the future with archlinux.
### Changed
- Dropped puppet 3 compatibility
- Bumped stdlib lower bound to 4.13.1
### Added
- archlinux support
## Release 0.6.0
### Summary
This release includes support for Puppet 4 AIO, test fixes and cleanup.
#### Features
- Support Puppet v4 AIO
#### Bugfixes
- Fix bundler_package name for ubuntu
- Fix testing
- Update supported platforms
- Remove unused metadata
- Use community style
## Release 0.5.0
### Summary
This release includes several new OS support features/bugfixes and multiple updates to Gemfile, Rakefile and metadata.
#### Features
- Bundle options: Allow . char in filepath args
- Added FreeBSD 10 support
- Gemfile updated
- Rakefile updated to new syntax
- Pinned rake to v10 when using Ruby 1.8.7 as v11 drops support for it
#### Bugfixes
- Updated metadata summary
- Now requires ruby2.1-dev when installing on 2.1 Debian
- General typo fixes
- Readme updates and fixes
- Fixed issue were multiple gem sources generated an invalid yaml file
- Now uses ruby bundler on ubuntu < 14.04
##2014-11-18 - Release 0.4.0
###Summary
This release includes the ability to specify the `rake_provider`, improved default parameters for OSes, and updates to tests and docs.
####Features
- Add `rake_provider` parameter to `ruby::dev`
- Updated RHEL and Ubuntu parameters
- Test and documentation improvements
####Bugfixes
- Clean up lint errors
- Fix typo in README
##2014-09-16 - Release 0.3.0
###Summary
This release includes many new features and improvements, including better
handling for bundler and rake.
Special thanks to Aaron Hicks for his hard work improving this module!
####Features
- Added `$ruby_dev_gems` parameter to `ruby::dev`
- Added the following params to `ruby`
- `$suppress_warnings`
- `$set_system_default`
- `$system_default_bin`
- `$system_default_gem`
- `$gem_integration`
- `$gem_integration_package`
- Manage rake and bundler separately from core ruby packages with the addition
of ruby::bundle and ruby::rake
- Deprecated `$switch` in favor of `$set_system_default`
- Improved testing and documentation
####Bugfixes
- Fix package name to be 'bundler' instead of 'ruby-bundler' for Debian/Ubuntu
- Fix package list defaults for RHEL5 and RHEL6
- Fix package logic for trusty
##2014-07-15 - Release 0.2.1
###Summary
This release merely updates metadata.json so the module can be uninstalled and
upgraded via the puppet module command.
##2014-06-03 - Version 0.2.0
###Summary
This work adds the ability to manage the gemrc globally, as well as adds in
Ubuntu 14.04 support. There was a fair amount of under the hood changes to
improve the module and it's testing.
####Features
- `ruby::gemrc`: A class to allow you to configure the global gemrc file.
- `ruby::dev`: A class for configurating ruby development specific things.
- Rework the readme, tests, and rake tasks.
- Remove augeas packages.
- Add Ubuntu 14.04 support.
####Bugfixes
- Fix for selecting the right package name when using versions.
- Ruby-switch is gone from Ubuntu 14.04 onwards.
- Fixes to ruby-switch in general.
##2013-10-09 - Version 0.1.1
###Summary
Tiny fix to the metadata.json.
####Bugfixes
- metadata.json.
##2013-10-08 - Version 0.1.0
###Summary
Release an updated version of this. Highlights include OpenSUSE and general
spring cleaning done by our wonderful community members!
####Features
- OpenSUSE support
- Allow `rubygems_package` override.
- Add gemhome fact.
- Add ri package.
####Bugfixes
- Lint fixes.
- Remove virtual irb package.
- Update dev packages for Ubuntu/Debian

View File

@@ -0,0 +1,46 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end
gem 'puppetlabs_spec_helper', '>= 1.2.0', :require => false
gem 'facter', '>= 1.7.0', :require => false
gem 'rspec-puppet', :require => false
gem 'puppet-lint', '~> 2.0', :require => false
gem 'puppet-lint-absolute_classname-check', :require => false
gem 'puppet-lint-alias-check', :require => false
gem 'puppet-lint-empty_string-check', :require => false
gem 'puppet-lint-file_ensure-check', :require => false
gem 'puppet-lint-file_source_rights-check', :require => false
gem 'puppet-lint-leading_zero-check', :require => false
gem 'puppet-lint-spaceship_operator_without_tag-check', :require => false
gem 'puppet-lint-trailing_comma-check', :require => false
gem 'puppet-lint-undef_in_function-check', :require => false
gem 'puppet-lint-unquoted_string-check', :require => false
gem 'puppet-lint-variable_contains_upcase', :require => false
gem 'rspec','~> 2.0', :require => false if RUBY_VERSION < '1.9'
gem 'rake', '~> 10.0', :require => false if RUBY_VERSION < '1.9'
gem 'json', '<= 1.8', :require => false if RUBY_VERSION < '2.0.0'
gem 'json_pure', '<= 2.0.1', :require => false if RUBY_VERSION < '2.0.0'
gem 'json', :require => false if RUBY_VERSION >= '2.0.0'
gem 'metadata-json-lint', '0.0.11', :require => false if RUBY_VERSION < '1.9'
gem 'metadata-json-lint', :require => false if RUBY_VERSION >= '1.9'
group :system_tests do
if beaker_version = ENV['BEAKER_VERSION']
gem 'beaker', *location_for(beaker_version)
end
if beaker_rspec_version = ENV['BEAKER_RSPEC_VERSION']
gem 'beaker-rspec', *location_for(beaker_rspec_version)
else
gem 'beaker-rspec', :require => false
end
gem 'serverspec', :require => false
gem 'beaker-puppet_install_helper', :require => false
end
# vim:ft=ruby

View File

@@ -0,0 +1,15 @@
Copyright (C) 2012-2016 Puppet Labs Inc
Puppet Labs can be contacted at: info@puppetlabs.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@@ -0,0 +1,301 @@
# Ruby Module
This module manages Ruby and Rubygems.
# Compatibility
Puppet >= 4.7.0 with Ruby 2.1.9 and 2.4.1 on the following platforms.
* Debian 6
* Debian 7
* EL 5
* EL 6
* EL 7
* FreeBSD 10
* SLES 11 SP1
* Arch Linux
# Dependencies
* [PuppetLabs stdlib](https://forge.puppetlabs.com/puppetlabs/stdlib)
## Ruby Class
Installs and manages the core Ruby packages.
### Parameters
* *version*: (default installed) -
Set the version of Ruby to install
* *latest_release*: (default undefined) -
Set this to true and the Ruby module will install new releases if they are updated in the repositories, or if a new repository is added with a newer release. Note: In Debian and Ubuntu where Ruby version is specified by package name, this parameter will effectively install the latest release of the Ruby version specified with the `version` parameter.
* *gems_version*: (default installed) -
Set the version of Rubygems to be installed
* *rubygems_update*: (default true) -
If set to true, the module will ensure that the rubygems package is installed but will use rubygems-update (same as gem update --system but versionable) to update Rubygems to the version defined in $gems_version. If set to false then the rubygems package resource will be versioned from $gems_version
* *ruby_package*: (default ruby, modified for distribution and Ruby version) -
Set the package name for Ruby
* *rubygems_package*: (default rubygems) -
Set the package name for rubygems
* *ruby_dev_packages*: (default undefined) This sets the list of development packages passed to `ruby::dev`.
* *suppress_warnings*: (default false) This suppresses warnings when a package is not expected to be available for a specific Ruby version for specific Ubuntu\Debian distributions and releases, but when a repository is provided that supplies the unnatural packages.
* *set_system_default*: (default false) This sets the system default ruby and gem binaries to that specified by the `version` parameter. Only supported in Debian and Ubuntu.
* *system_default_bin*: (default undefined) This sets a custom ruby binary used by the `set_system_default` parameter. To be used when a custom ruby package is supplied.
* *system_default_gem*: (default undefined) This sets a custom gem binary used by the `set_system_default` parameter. To be used when a custom ruby or rubygems package is supplied.
* *gem_integration*: (default false) Install the `rubygems_integration` package for Debian/Ubuntu that provides some integration between gems and distribution packages. Only supported in Debian and Ubuntu.
* *gem_integration_package*: (default false) Specifies a custom `rubygems-integration` package.
* *switch*: This parameter is depreciated, but continued for compatibility. Has the same function as `set_system_default`.
### Usage
For a standard install using the latest Rubygems provided by rubygems-update on
CentOS or Redhat use:
```puppet
class { '::ruby':
gems_version => 'latest',
}
```
On Redhat this is equivilant to
$ yum install ruby rubygems
$ gem update --system
#### Specify Version
To install a specific version of ruby and rubygems but *not* use
rubygems-update use:
```puppet
class { '::ruby':
version => '1.8.7',
gems_version => '1.8.24',
rubygems_update => false,
}
```
On Redhat this is equivilant to
$ yum install ruby-1.8.7 rubygems-1.8.24
#### Alternative Ruby Packages
If you need to use different packages for either ruby or rubygems you
can. This could be for different versions or custom packages. For
instance the following installs ruby 1.9 on Ubuntu 12.04.
```puppet
class { '::ruby':
ruby_package => 'ruby1.9.1-full',
rubygems_package => 'rubygems1.9.1',
gems_version => 'latest',
}
```
This parameter will be particularly important if an alternative package repository is defined with [`yumrepo`](http://docs.puppetlabs.com/references/latest/type.html#yumrepo) or [`apt::source` or `apt::ppa`](https://forge.puppetlabs.com/puppetlabs/apt).
## Ruby Development Class
The `ruby::dev` class requires the base `ruby` class.
Installs and manages the installation of the Ruby development packages and tools, including [Rake](http://docs.seattlerb.org/rake/) and [Bundler](http://bundler.io/). Note that the `ruby::dev` class may not install all the dependencies required to install some gems.
There is some selection logic in the `ruby::dev` class that attempts to install the correct development libraries and tools for the Ruby version installed by the base `ruby` class. Hence the `ruby::dev` class requires the `ruby` class.
This class often installs a list of packages, so setting a package version is not available as this may behave unpredictably.
### Parameters
* *ensure*: (default is 'installed') -
This parameter sets the `ensure` parameter for all the Ruby development packages.
* *ruby_dev_packages*: (default is depends on OS distribution) -
This parameter replaces the list of default Ruby development packages.
* *rake_ensure*: (default is 'installed') -
This sets the `ensure` parameter of the rake package.
* *rake_package*: (default depends on OS distribution) -
This parameter replaces the default rake package.
* *bundler_ensure*: (default is 'installed') -
This sets the `ensure` parameter of the bundler package.
* *bundler_package*: (default is dependent on OS distribution) -
This parameter replaces the default bundler package.
* *bundler_provider*: (default is dependent on OS distribution) -
This parameter specifies what package provider should be used, only `gem` or `apt` are accepted.
## Rake Resource
The `ruby::rake` resource requires the `ruby::dev` class.
This resource runs [Rake](http://docs.seattlerb.org/rake/) tasks. This resource was created to be sure that Rake tasks would only be executed once their requirements were met by the `ruby::dev` class.
As running rake under bundle is a common scenario, the `bundle` parameter will automatically wrap a rake task as a `bundle exec rake` command. This ensures that the rake command passes through the sanity checking in the `ruby::rake` resource, and meets the dependency requirements needed for both rake and bundler tasks.
### Parameters
Most of the parameters for this resource are passed through to the underlying `exec` resource that runs the Rake task. Check the Puppetlabs documentation on the [exec resource](http://docs.puppetlabs.com/references/latest/type.html#exec) for more details. Some parameters are not available.
* *task*: (this parameter is required) -
This parameter is the Ruby task to be performed as a string with command line options. e.g. `db:setup`.
* *rails_env*: (default is `production`) -
This parameter is used to set the `RAILS_ENV` environment variable, the default is to set it to production. This parameter is combined with the `environment` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the rake task.
* *bundle*: (default is false) -
If set to true, the Rake task is automatically run under a `ruby::bundler` resource.
* *creates*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *cwd*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *environment*: (default is undefined) -
This parameter is combined with the `rails_env` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the rake task.
* *user*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *group*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *logoutput*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *onlyif*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *path*: (default is `['/usr/bin','/bin','/usr/sbin','/sbin']`) -
The rake executable has a minimum path requirement, if this parameter is left undefined, the default minimum path will be used. If a list of paths is provided, this list will be modified to be sure that it still meets the minimum path requirements for the rake executable. This is then passed to the underlying `exec` resource that runs the rake task.
* *refresh*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *refreshonly*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *timeout*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *tries*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *try_sleep*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
* *unless*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the rake task.
## Bundler Resource
The `ruby::bundle` resource requires the `ruby::dev` class.
This resource runs [Bundler](http://bundler.io/) tasks. This resource was created to be sure that Bundler tasks would only be executed once their requirements were met by the `ruby::dev` class.
### Parameters
Most of the parameters are passed through to the underlying `exec` resource that runs the bundler task. Check the Puppetlabs documentation on the [exec resource](http://docs.puppetlabs.com/references/latest/type.html#exec) for more details. Some parameters are not available.
* *command*: (default is 'install') -
This sets the command passed to the `bundler` executable. Not all bundler commands are currently supported. Only `exec`, `install` and `update` are currently supported.
* *option*: (default is undefined) -
This sets the options for the bundler command. Not all options are supported.
* *rails_env*: (default is $ruby::params::rails_env) -
This parameter is used to set the `RAILS_ENV` environment variable, the default is to set it to production. This parameter is combined with the `environment` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the bundler task.
* *creates*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *cwd*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *environment*: (default is undefined) -
This parameter is combined with the `rails_env` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the bundler task.
* *user*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *group*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *logoutput*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *onlyif*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *path*: (default is undefined) -
The bundle executable has a minimum path requirement, if this parameter is left undefined, the default minimum path will be used. If a list of paths is provided, this list will be modified to be sure that it still meets the minimum path requirements for the bundle executable. This is then passed to the underlying `exec` resource that runs the bundle task.
* *refresh*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *refreshonly*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *timeout*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *tries*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *try_sleep*: (default is undefined) -
Passed through to the underlying `exec` resource that runs the bundler task.
* *unless*: (default is undefined) -
The `unless` parameter is passed through to the underlying `exec` resource that runs the bundler task if the `ruby::bundler` resource `command` parameter is `exec`. For the `install` or `update` commands `unless` will be automatically set to, or overridden with, a command that makes the `ruby::bundle` resource idempotent.
#### Supported Bundler Commands
* **exec**: For the `exec` command to work, the command to be executed is passed as the option string. If the command is a rake task, it is recommended that the `ruby::rake` resource is used with the `bundle` parameter set to true. There are currently no constraints on the option string for the `exec` command.
* **install**: The `install` command only currently supports the `--clean`,`--deployment`,`--gemfile`,`--path`, `--without`, and `--no-prune` options.
* **update**: The `update` command only currently supports the `--local` and `--source` options. This command will try and update all the gems in a directory every time puppet runs.
## Ruby Configuration Class
Ruby Enterprise Edition, Ruby versions [later than 1.9.3-preview1](http://www.rubyinside.com/ruby-1-9-3-preview-1-released-5229.html), and some patched Ruby distributions allow some tuning of the Ruby memory heap and garbage collection. These features will not work with the standard Ruby distributions prior to 1.9.3.
The `ruby::config` class sets global environment variables that tune the Ruby memory heap and it's garbage collection as [per the Ruby Enterprise Edition documentation](http://www.rubyenterpriseedition.com/documentation.html#_garbage_collector_performance_tuning). This should allow the configuration of Ruby to better suit a deployed application and reduce the memory overhead of long-running Ruby processes (e.g. the [Puppet daemon](http://www.masterzen.fr/2010/01/28/puppet-memory-usage-not-a-fatality/)). The memory overhead issue can be further reduced by upgrading Ruby to a distribution using a [bitmap marked garbage collection](http://patshaughnessy.net/2012/3/23/why-you-should-be-excited-about-garbage-collection-in-ruby-2-0) patch (e.g. as provided by [BrightBox](http://docs.brightbox.com/ruby/ubuntu/)) or to [Ruby 2.x](https://www.ruby-lang.org/en/news/2013/02/24/ruby-2-0-0-p0-is-released/).
### More References
* [Demystifying the Ruby GC](http://samsaffron.com/archive/2013/11/22/demystifying-the-ruby-gc) by Sam Saffron
### Parameters
All the parameters are not set by default, which will revert to the default values for Ruby.
* *gc_malloc_limit* : Sets `RUBY_GC_MALLOC_LIMIT`, which is the amount of memory that can be allocated without triggering garbage collection. The default is 8000000.
* *heap_free_min* : Sets `RUBY_HEAP_FREE_MIN`, which is the number of heap slots that should be available after garbage collection is run. If fewer slots are available, new heap slots will be allocated. The default is 4096.
* *heap_slots_growth_factor* : Sets `RUBY_HEAP_SLOTS_GROWTH_FACTOR`, which is the multiplier for how many new slots to be created if fewer slots than `RUBY_HEAP_FREE_MIN` remain after garbage collection. The default is 1.8.
* *heap_min_slots* : This sets `RUBY_HEAP_MIN_SLOTS`, which is initial number of heap slots. The default is 10000.
* *heap_slots_increment* : This sets `RUBY_HEAP_SLOTS_INCREMENT`, which is the number of additional slots allocated the first time additional slots are required. The default is 10000.
### Usage
It should be possible to set any number of parameters, but setting no parameters is a special case that removes any modification to the Ruby environment settings.
#### No Parameters
If `ruby::config` is given with no parameters it removes the environment settings from the system, which restores the default Ruby settings.
```puppet
include ::ruby::config
```
#### With Parameters
```puppet
class { '::ruby::config':
heap_min_slots => 500000,
heap_slots_increment => 250000,
heap_slots_growth_factor => 1,
gc_malloc_limit => 50000000,
}
```
Which should result with the following environment variables set:
```
RUBY_HEAP_MIN_SLOTS=500000
RUBY_HEAP_SLOTS_INCREMENT=250000
RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
RUBY_GC_MALLOC_LIMIT=50000000
```
# Package sources
If the required Ruby version is not available for the distribution being used check the following repositories:
* For Ubuntu the [Brightbox Ruby PPA](http://www.ubuntuupdates.org/ppa/brightbox_ruby_ng_experimental) provides Ruby packages, use the following puppet code:
```puppet
include ::apt
::apt::ppa { 'ppa:brightbox/ruby-ng-experimental': }
class { '::ruby':
version => '1.9.1',
switch => true,
latest_release => true,
require => Apt::Ppa['ppa:brightbox/ruby-ng-experimental'],
}
```

View File

@@ -0,0 +1,19 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_140chars')
PuppetLint.configuration.relative = true
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
desc 'Validate manifests, templates, and ruby files'
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end

View File

@@ -0,0 +1,36 @@
{
"CHANGELOG.md": "b5bbf1b50ff67bd5ef7e39d65876a018",
"Gemfile": "ded016d3a37ecedea438d3151015fdb9",
"LICENSE": "279c29cf0e1b0871bde3f4a2736f1421",
"README.md": "4f4f6f237210174cd08bc7eb105a0cf7",
"Rakefile": "ec31f81d2cff151a48bca8b055300c6a",
"lib/facter/gemhome.rb": "a9eeb4dda783c97f89c37541af28afb7",
"manifests/bundle.pp": "a5b9984a15523a75f119e7f456df8ce6",
"manifests/config.pp": "151d5aff3817488eb4422e106e1c3e52",
"manifests/dev.pp": "52b599fd41e4a9752d881d44823aed20",
"manifests/gemrc.pp": "153dcd59e05639c0b604d87b5472453d",
"manifests/init.pp": "17ae00f2fafdb133dbc93f31ce24ee15",
"manifests/params.pp": "aacd84830344ea882716da7b8fbe8c64",
"manifests/rake.pp": "38dec4fe80db0d3d75f145c35119f18d",
"metadata.json": "c91788205ad3416cb5394cfcd62b5549",
"spec/classes/config_spec.rb": "2d6461ebfa27168f08ea3831f67f3d68",
"spec/classes/dev_spec.rb": "5996d212f76b920c7c72fb62c6f59f24",
"spec/classes/gemrc_spec.rb": "7f8525b0deb1745db3ca604a412274e2",
"spec/classes/init_spec.rb": "681d8d2ea01105a9002dab1726c9ce49",
"spec/defines/bundle_spec.rb": "e21204aa43fd4a0fb1d66d7a230b8d6c",
"spec/defines/rake_spec.rb": "f25d7566b94f6488c1ed26a18642228d",
"spec/spec.opts": "c407193b3d9028941ef59edd114f5968",
"spec/spec_helper.rb": "8468f20969fdb79ae451db3043dcf474",
"spec/spec_helper_system.rb": "ff5460b081e429ea85e86132fd57e3db",
"templates/gemrc.yaml.erb": "df98ee18556519b52e5d9a06092317c0",
"templates/ruby.sh.erb": "27418f1c66ad89fd15d1b60e685bbc68",
"tests/dev.pp": "135453a20b48db069f8d0a14f9d672e9",
"tests/init.pp": "2ff9df953b57b387d4961a53a24956bc",
"tests/params.pp": "29bb4f3d2a5ee648d10b20ccb5c24396",
"tests/ruby1.8.pp": "7573e0e1cc66368c735700e637d0631e",
"tests/ruby1.9.pp": "854e950069b11f84d4a1db28b686cbd8",
"tests/ruby1.9_switch.pp": "516724108bf92ea38b390c6a4d5da4cb",
"tests/ruby2.0.pp": "c26a720fbf1524ed5a36a8133c0a3468",
"tests/ruby2.1.pp": "c562177e46fd3200788a0d1d4e6c7a85",
"tests/ruby2_switch.pp": "44aecee447e61db8d1162f3abf401b32"
}

View File

@@ -0,0 +1,16 @@
# Fact: gemhome
#
# Purpose: Returns the gem home for rubygems
#
# Resolution: Returns GEM_HOME.
#
# Caveats:
#
begin
require 'rubygems'
Facter.add(:gemhome) do
setcode { Gem::dir }
end
rescue LoadError
end

View File

@@ -0,0 +1,171 @@
# == Define: ruby::bundle
#
# This resource runs [Bundler](http://bundler.io/) tasks. This resource was created to be sure that Bundler tasks would only be executed once their requirements were met by the `ruby::dev` class.
#
# === Parameters
#
# * *command*: (default is 'install') -
# This sets the command passed to the `bundler` executable. Not all bundler commands are currently supported. Only `exec`, `install` and `update` are currently supported.
# * *option*: (default is undefined) -
# This sets the options for the bundler command. Not all options are supported.
# * *rails_env*: (default is $ruby::params::rails_env) -
# This parameter is used to set the `RAILS_ENV` environment variable, the default is to set it to production. This parameter is combined with the `environment` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the bundler task.
# [*creates*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*cwd*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*environment*]
# (default is undefined) This parameter is combined with the `rails_env` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the bundler task.
# [*user*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*group*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*logoutput*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*onlyif*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*path*]
# (default is undefined) The bundle executable has a minimum path requirement, if this parameter is left undefined, the default minimum path will be used. If a list of paths is provided, this list will be modified to be sure that it still meets the minimum path requirements for the bundle executable. This is then passed to the underlying `exec` resource that runs the bundle task.
# [*refresh*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*refreshonly*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*timeout*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*tries*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*try_sleep*]
# (default is undefined) Passed through to the underlying `exec` resource that runs the bundler task.
# [*unless*]
# (default is undefined) The `unless` parameter is only passed through to the underlying `exec` resource that runs the bundler task if the `ruby::bundler` resource `command` parameter is `exec`. For the `install` or `update` commands `unless` will be automatically set to, or overridden with, a command that makes the `ruby::bundle` resource idempotent.
#
# === Examples
#
# Using ruby::bundle to install gems:
#
# ruby::bundle { 'install_app_gems':
# option => '--deployment',
# cwd => '/path/to/app',
# }
#
define ruby::bundle
(
$command = 'install',
$option = undef,
$rails_env = undef,
$multicore = undef,
$creates = undef,
$cwd = undef,
$environment = undef,
$user = undef,
$group = undef,
$logoutput = undef,
$onlyif = undef,
$path = undef,
$refresh = undef,
$refreshonly = undef,
$timeout = undef,
$tries = undef,
$try_sleep = undef,
$unless = undef,
) {
require ::ruby
if $rails_env == undef {
$rails_env_real = $ruby::params::rails_env
} else {
$rails_env_real = $rails_env
}
# ensure minimum path requirements for bundler
if $path {
$real_path = unique(flatten([$path, $ruby::params::minimum_path]))
} else {
$real_path = $ruby::params::minimum_path
}
# merge the environment and rails_env parameters
if $environment {
$real_environment = unique(flatten([$environment, ["RAILS_ENV=${rails_env_real}"]]))
} else {
$real_environment = "RAILS_ENV=${rails_env_real}"
}
if $multicore {
if "${multicore}" == '0' or versioncmp($multicore,$::processorcount) >= 0 { #lint:ignore:only_variable_string
$multicore_str = " --jobs ${::processorcount}"
} else {
$multicore_str = " --jobs ${multicore}"
}
} else {
$multicore_str = undef
}
case $command {
'install': {
if $option {
validate_re(
$option,
[
'\s*--clean\s*',
'\s*--deployment\s*',
'\s*--gemfile=[a-zA-Z0-9\/\\:\.]+\s*',
'\s*--path=[a-zA-Z0-9\/\\:\.]+\s*',
'\s*--no-prune\s*',
'\s*--without [[a-z0-9]+ ]+\s*',
],
'Only bundler options supported for the install command are: clean, deployment, gemfile, path, without, and no-prune'
)
$real_command = "bundle ${command}${multicore_str} ${option}"
} else {
$real_command = "bundle ${command}${multicore_str}"
}
$real_unless = 'bundle check'
}
'exec': {
if $option {
$real_command = "bundle ${command}${multicore_str} ${option}"
$real_unless = $unless
} else {
fail ('When given the exec command the ruby::bundle resource requires the command to be executed to be passed to the option parameter')
}
}
'update':{
if $option {
validate_re(
$option,
['--local', '--source='],
'Only bundler options supported for the update command are: local and source'
)
$real_command = "bundle ${command}${multicore_str} ${option}"
$real_unless = "bundle outdated${multicore_str} ${option}"
} else {
$real_command = "bundle ${command}${multicore_str}"
$real_unless = 'bundle outdated'
}
}
default: {
fail ('Only the bundler commands install, exec, and update are supported.')
}
}
exec{"ruby_bundle_${name}":
command => $real_command,
creates => $creates,
cwd => $cwd,
environment => $real_environment,
user => $user,
group => $group,
logoutput => $logoutput,
onlyif => $onlyif,
path => $real_path,
refresh => $refresh,
refreshonly => $refreshonly,
timeout => $timeout,
tries => $tries,
try_sleep => $try_sleep,
unless => $real_unless,
require => Package['bundler'],
}
}

View File

@@ -0,0 +1,31 @@
# Tunes the Ruby configuration
# Ruby's garbage colleciton is notoriously inefficient and leads to
# overallocation of memory to any long-running process that uses Ruby
# e.g. puppet daemons
# This class allows tuning of the Ruby environment variables
class ruby::config (
$gc_malloc_limit = undef,
$heap_free_min = undef,
$heap_slots_growth_factor = undef,
$heap_min_slots = undef,
$heap_slots_increment = undef
) inherits ruby::params {
if $gc_malloc_limit or
$heap_free_min or
$heap_slots_growth_factor or
$heap_min_slots or
$heap_slots_increment
{
$ensure = 'file'
} else{
$ensure = 'absent'
}
file{'ruby_environment':
ensure => $ensure,
path => $ruby::params::ruby_environment_file,
content => template('ruby/ruby.sh.erb'),
}
}

View File

@@ -0,0 +1,149 @@
# Class: ruby::dev
#
# This class installs Ruby development libraries. It's not right, and has no tests.
#
# Parameters:
#
# [*ensure*]
# (default is 'installed') This parameter sets the `ensure` parameter for all the Ruby development packages.
# [*ruby_dev_packages*]
# (default is depends on OS distribution) This parameter replaces the list of default Ruby development packages.
# [*rake_ensure*]
# (default is 'installed') This sets the `ensure` parameter of the rake package.
# [*rake_package*]
# (default depends on OS distribution) This parameter replaces the default rake package.
# [*rake_provider*]
# (default depends on OS distribution) This parameter replaces the default rake provider.
# [*bundler_ensure*]
# (default is 'installed') This sets the `ensure` parameter of the bundler package.
# [*bundler_package*]
# (default is depends on OS distribution) This parameter replaces the default bundler package.
# [*bundler_provider*]
# (default depends on OS distribution) This parameter replaces the default bundler provider.
#
# Actions:
# - Install RDoc, IRB, and development libraries
# - Optionally install Rake and Bundler (installed by default)
#
# Requires:
#
# - Ruby
#
# Sample Usage:
#
# include ruby
# include ruby::dev
#
class ruby::dev (
Enum['installed', 'present', 'absent', 'latest'] $ensure = 'installed',
$ruby_dev_packages = undef,
$rake_ensure = $ruby::params::rake_ensure,
$rake_package = $ruby::params::rake_package,
$rake_provider = $ruby::params::rake_provider,
$bundler_ensure = $ruby::params::bundler_ensure,
$bundler_package = $ruby::params::bundler_package,
Enum['gem', 'apt', 'pacman'] $bundler_provider = $ruby::params::bundler_provider,
) inherits ruby::params {
require ::ruby
case $::osfamily {
default: {
fail("Detected osfamily is <${::osfamily}> and supported values are 'Debian', 'RedHat', 'Archlinux' and 'Amazon'")
}
'Debian': {
if $ruby_dev_packages {
$ruby_dev = $ruby_dev_packages
} else {
case $::ruby::version {
/^1\.8.*$/:{
$ruby_dev = [
'ruby1.8-dev',
'ri1.8',
'pkg-config',
]
}
/^1\.9.*$/:{
$ruby_dev = [
'ruby1.9.1-dev',
'ri1.9.1',
'pkg-config',
]
}
/^2\.0.*$/:{
$ruby_dev = [
'ruby2.0-dev',
'ri',
'pkg-config',
]
}
/^2\.1.*$/:{
$ruby_dev = [
'ruby2.1-dev',
'ri',
'pkg-config',
]
}
default: {
$ruby_dev = $::ruby::params::ruby_dev
}
}
}
}
'RedHat', 'Amazon': {
# This specifically covers the case where there is no distro-provided
# package for bundler. We install it using gem instead. Right now, this is
# only set on RedHat and Amazon (see params.pp).
$ruby_dev_gems = $::ruby::params::ruby_dev_gems
if $ruby_dev_packages {
$ruby_dev = $ruby_dev_packages
} else {
$ruby_dev = $::ruby::params::ruby_dev
}
}
'Archlinux': {
$ruby_dev_gems = undef
$ruby_dev = undef
}
}
# The "version" switch seems to do nothing on a non-Debian distro. This is
# probably the safest behavior for the moment, since RedHat doesn't change
# the ruby package name the way Debian does when new versions become
# available. It's a bit misleading for the user, though, since they can
# specify a version and it will just silently continue installing the
# default version.
if $ruby_dev {
package { $ruby_dev:
ensure => $ensure,
before => Package['rake', 'bundler'],
require => Package['ruby'],
}
}
if $rake_package {
package { 'rake':
ensure => $rake_ensure,
name => $rake_package,
provider => $rake_provider,
require => Package['ruby'],
}
}
if $bundler_package {
package { 'bundler':
ensure => $bundler_ensure,
name => $bundler_package,
provider => $bundler_provider,
require => Package['ruby'],
}
}
if $ruby_dev_gems {
package { $ruby_dev_gems:
ensure => $ensure,
provider => gem,
}
}
}

View File

@@ -0,0 +1,70 @@
# Manage global gemrc configuration
#
# This class allows the management of entries in /etc/gemrc
# That can be useful when, e.g. configuring a rubygems proxy.
# === Parameters
#
# [*sources*]
# A YAML array of remote gem repositories to install gems from
#
# [*verbose*]
# Verbosity of the gem command. false, true, and :really are the levels
#
# [*update_sources*]
# Enable/disable automatic updating of repository metadata
#
# [*backtrace*]
# Print backtrace when RubyGems encounters an error
#
# [*gempath*]
# The paths in which to look for gems
#
# [*disable_default_gem_server*]
# Force specification of gem server host on push
#
# [*gem_command*]
# A string containing arguments for the specified gem command
# This takes an array of Hashes, i.e.:
#
# gem_command => {
# 'gem' => [ 'no-ri', 'http-proxy=http://waf-proxy' ],
# 'push' => [ 'host=https://our.rubygems.host' ],
# }
class ruby::gemrc (
$sources = undef,
Optional[Variant[Boolean, Enum[':really']]] $verbose = undef,
Optional[Boolean] $update_sources = undef,
Optional[Boolean] $backtrace = undef,
Optional[Array[String]] $gempath = undef,
Optional[Hash] $gem_command = undef,
Stdlib::Absolutepath $gemrc = $::ruby::params::gemrc,
String $owner = 'root',
String $group = 'root',
Pattern[/[0-7]{4}/] $mode = '0644',
Optional[Boolean] $disable_default_gem_server = undef
) inherits ruby::params {
$ensure = pick ($sources
, $verbose
, $update_sources
, $backtrace
, $gempath
, $disable_default_gem_server
, $gem_command
, 'No need for gemrc.'
) ? {
'No need for gemrc.' => 'absent',
default => 'file',
}
file { 'gemrc':
ensure => $ensure,
path => $::ruby::params::gemrc,
mode => $mode,
owner => $owner,
group => $group,
content => template('ruby/gemrc.yaml.erb'),
}
}

View File

@@ -0,0 +1,307 @@
# Class: ruby
#
# This class installs Ruby and manages rubygems
#
# Parameters:
#
# version: (default installed)
# Set the version of Ruby to install
#
# gems_version: (default installed)
# Set the version of Rubygems to be installed
#
# rubygems_update: (default false)
# If set to true, the module will ensure that the rubygems package is
# installed but will use rubygems-update (same as gem update --system
# but versionable) to update Rubygems to the version defined in
# $gems_version. If set to false then the rubygems package resource
# will be versioned from $gems_version
#
# ruby_package: (default ruby)
# Set the package name for ruby
#
# rubygems_package: (default rubygems)
# Set the package name for rubygems
#
# Actions:
# - Install Ruby
# - Install Rubygems
# - Optionally Update Rubygems
#
# Requires:
#
# Sample Usage:
#
# For a standard install using the latest Rubygems provided by
# rubygems *without update* on Redhat use:
#
# class { 'ruby':
# gems_version => 'latest',
# }
#
# On Redhat this is equivalent to
# $ yum install ruby rubygems
#
# To install a specific version of ruby and then call
# gem update, use:
#
# class { 'ruby':
# version => '1.8.7',
# rubygems_update => true,
# }
#
# On RedHat this is equivalent to
# $ yum install ruby-1.8.7 rubygems
# $ gem update --system
#
# To install a specific version of ruby and rubygems
# use:
#
# class { 'ruby':
# version => '1.8.7',
# gems_version => '1.8.24',
# rubygems_update => true,
# }
#
# On Redhat this is equivalent to
# $ yum install ruby-1.8.7 rubygems-1.8.24
# $ gem update --system
#
# If you need to use different packages for either ruby or rubygems you
# can. This could be for different versions or custom packages. For instance
# the following installs ruby 1.9 on Ubuntu 12.04.
#
# class { 'ruby':
# ruby_package => 'ruby1.9.1-full',
# rubygems_package => 'rubygems1.9.1',
# gems_version => 'latest',
# }
#
# Ruby package names are not straightforward. Especially in Debian
# osfamily Linux distributions
# ruby is a virtual package that points to ruby1.8
# ruby1.8 installs Ruby 1.8.7 (and earlier versions), requires a PPA for 14.04 or later
# ruby1.9.1 installs Ruby 1.9.x
# ruby1.9.1-full installs Ruby 1.9.x
# ruby1.9.3 installs Ruby 1.9.x
# Ruby 2.0.0 is availible from a PPA or Ubuntu 13.10 or later.
# Ruby 2.1.0 is availible from a PPA.
# ...and this should all be overridden if a package is specified
#
class ruby (
$version = $ruby::params::version,
$latest_release = undef,
$gems_version = $ruby::params::gems_version,
$rubygems_update = $ruby::params::rubygems_update,
$ruby_package = $ruby::params::ruby_package,
$ruby_dev_packages = $ruby::params::ruby_dev,
$rubygems_package = $ruby::params::rubygems_package,
$suppress_warnings = false,
$set_system_default = false,
$system_default_bin = undef,
$system_default_gem = undef,
$gem_integration = false,
$gem_integration_package = $ruby::params::gem_integration_package,
$switch = undef
) inherits ruby::params {
if $latest_release {
$ruby_package_ensure = 'latest'
} else {
$ruby_package_ensure = 'installed'
}
case $::osfamily {
'Debian': {
case $ruby_package {
'installed': {
$real_ruby_package = $ruby_package
}
default:{
case $version {
/^1\.8.*$/:{
$real_ruby_package = "${ruby::params::ruby_package}1.8"
if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '14.04') >= 0 {
warning('Packages for Ruby 1.8 are not available from default repositories.')
}
}
/^1\.9.*$/:{
$real_ruby_package = "${ruby::params::ruby_package}1.9.1"
}
/^2\.0.*$/:{
$real_ruby_package = "${ruby::params::ruby_package}2.0"
if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '13.10') < 0 {
warning('Packages for Ruby 2.0 are not available from default repositories.')
}
}
/^2\.1.*$/:{
$real_ruby_package = "${ruby::params::ruby_package}2.1"
if ! $suppress_warnings {
warning('Packages for Ruby 2.1 are not available from default repositories.')
}
}
default: {
$real_ruby_package = $ruby_package
}
}
}
}
}
default: {
$real_ruby_package = $ruby_package
}
}
# The "version" switch seems to do nothing on a non-Debian distro. This is
# probably the safest behavior for the moment, since RedHat doesn't change
# the ruby package name the way Debian does when new versions become
# available. It's a bit misleading for the user, though, since they can
# specify a version and it will just silently continue installing the
# default version.
package { 'ruby':
ensure => $ruby_package_ensure,
name => $real_ruby_package,
}
# if rubygems_update is set to true then we only need to make the package
# resource for rubygems ensure to installed, we'll let rubygems-update
# take care of the versioning.
if $rubygems_update == true {
$rubygems_ensure = 'installed'
} else {
$rubygems_ensure = $gems_version
}
if $rubygems_package {
package { 'rubygems':
ensure => $rubygems_ensure,
name => $rubygems_package,
require => Package['ruby'],
}
}
if $rubygems_update {
package { 'rubygems-update':
ensure => $gems_version,
provider => 'gem',
require => Package['rubygems'],
notify => Exec['ruby::update_rubygems'],
}
exec { 'ruby::update_rubygems':
path => '/usr/local/bin:/usr/bin:/bin',
command => 'update_rubygems',
refreshonly => true,
}
}
if $set_system_default or $switch {
case $::osfamily {
'Debian': {
if $system_default_bin {
$real_default_bin = $system_default_bin
} else {
case $version {
/^1\.8.*$/:{
$real_default_bin = "${ruby::params::ruby_bin_base}1.8"
if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '14.04') >= 0 {
warning('No binary for Ruby 1.8.x available from default repositories')
}
}
/^1\.9.*$/:{
$real_default_bin = "${ruby::params::ruby_bin_base}1.9.1"
}
/^2\.0.*$/:{
$real_default_bin = "${ruby::params::ruby_bin_base}2.0"
if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '13.10') < 0 {
warning('No binary for Ruby 2.0.x available from default repositories')
}
}
/^2\.1.*$/:{
$real_default_bin = "${ruby::params::ruby_bin_base}2.1"
if ! $suppress_warnings {
warning('No binary for Ruby 2.1.x available from default repositories')
}
}
default: {
fail('Unable to resolve default ruby binary')
}
}
}
if $system_default_gem {
$real_default_gem = $system_default_gem
} else {
case $version {
/^1\.8.*$/:{
$real_default_gem = "${ruby::params::ruby_gem_base}1.8"
if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '14.04') >= 0 {
warning('No binary package for Ruby 1.8.x available from default repositories')
}
}
/^1\.9.*$/:{
$real_default_gem = "${ruby::params::ruby_gem_base}1.9.1"
}
/^2\.0.*$/:{
$real_default_gem = "${ruby::params::ruby_gem_base}2.0"
if ! $suppress_warnings and versioncmp($::operatingsystemrelease, '13.10') < 0 {
warning('No binary package for Ruby 2.0.x available from default repositories')
}
}
/^2\.1.*$/:{
$real_default_gem = "${ruby::params::ruby_gem_base}2.1"
if ! $suppress_warnings {
warning('No binary package for Ruby 2.1.x available from default repositories')
}
}
default: {
fail('Unable to resolve default gem binary')
}
}
}
# update-alternatives does not support ruby in 14.04!
file{'ruby_bin':
ensure => link,
path => $::ruby::params::ruby_bin_base,
target => $real_default_bin,
require => Package['ruby'],
}
# This should notify Exec['ruby::update_rubygems'] but if rubygems_update is false
# it doesn't exist.
file{'gem_bin':
ensure => link,
path => $::ruby::params::ruby_gem_base,
target => $real_default_gem,
require => Package['rubygems'],
}
}
default: {
if $switch {
warning('The switch parameter is depreciated, use set_system_default')
notice("The switch parameter for the ruby class does not work for ${::operatingsystem}, no action taken.")
}
if $set_system_default {
notice("The set_system_default parameter for the ruby class does not work for ${::operatingsystem}, no action taken.")
}
}
}
}
if $gem_integration {
case $::osfamily {
'Debian': {
if ! $suppress_warnings and $::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '13.04') < 0 {
warning('No package for rubygems_integration available from default repositories')
}
package{'rubygems_integration':
ensure => $ruby_package_ensure,
name => $gem_integration_package,
require => Package['rubygems'],
}
}
default: {
notice("The gem_integration parameter for the ruby class does not work for ${::operatingsystem}, no action taken.")
}
}
}
}

View File

@@ -0,0 +1,101 @@
# Class: ruby::params
#
# This class handles the Ruby module parameters
#
class ruby::params {
$version = 'installed'
$gems_version = 'installed'
$ruby_switch_package = 'ruby-switch'
$rails_env = 'production'
$minimum_path = ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
$gem_integration_package = false
$ruby_dev_gems = false
case $::osfamily {
'redhat', 'amazon': {
$ruby_package = 'ruby'
$rubygems_package = 'rubygems'
$ruby_dev = 'ruby-devel'
$rubygems_update = false
if $::operatingsystemmajrelease and versioncmp($::operatingsystemmajrelease, '5') == 0 {
$rake_ensure = '10.3.2'
$rake_package = 'rake'
$rake_provider = 'gem'
} else {
$rake_ensure = 'installed'
$rake_package = 'rubygem-rake'
$rake_provider = 'yum'
}
$bundler_ensure = 'installed'
$bundler_package = 'bundler'
$bundler_provider = 'gem'
}
'Archlinux': {
$ruby_package = 'ruby'
$rubygems_package = undef
$ruby_dev = undef
$rubygems_update = false
$rake_ensure = 'installed'
$rake_package = undef
$rake_provider = 'pacman'
$bundler_ensure = 'installed'
$bundler_package = 'ruby-bundler'
$bundler_provider = 'pacman'
}
'debian': {
$ruby_dev = [
'ruby-dev',
'ri',
'pkg-config',
]
$rake_ensure = 'installed'
$rake_package = 'rake'
$rake_provider = 'apt'
$rubygems_update = false
$ruby_gem_base = '/usr/bin/gem'
$ruby_bin_base = '/usr/bin/ruby'
$bundler_provider = 'gem'
$bundler_package = 'bundler'
case $::operatingsystemrelease {
'10.04': {
$bundler_ensure = '0.9.9'
$ruby_package = 'ruby'
$rubygems_package = 'rubygems'
}
'14.04': {
#Ubuntu 14.04 changed ruby/rubygems to be all in one package. Specifying these as defaults will permit the module to behave as anticipated.
$bundler_ensure = 'installed'
$ruby_package = 'ruby'
$rubygems_package = 'ruby1.9.1-full'
}
default: {
$bundler_ensure = 'installed'
$ruby_package = 'ruby'
$rubygems_package = 'rubygems'
}
}
}
'FreeBSD': {
$ruby_dev = [
'ruby-build',
]
$rake_ensure = 'installed'
$rake_package = 'rake'
$rake_provider = 'gem'
$rubygems_update = false
$ruby_gem_base = '/usr/local/bin/gem'
$ruby_bin_base = '/usr/local/bin/ruby'
$bundler_package = 'bundler'
$bundler_provider = 'gem'
$bundler_ensure = 'installed'
$ruby_package = 'ruby'
$rubygems_package = 'ruby20-gems'
}
default: {
fail("Unsupported OS family: ${::osfamily}")
}
}
$ruby_environment_file = '/etc/profile.d/ruby.sh'
$gemrc = '/etc/gemrc'
}

View File

@@ -0,0 +1,154 @@
# == Define: ruby::rake
#
# This resource runs [Rake](http://docs.seattlerb.org/rake/) tasks. This resource was created to be sure that Rake tasks would only be executed once their requirements were met by the `ruby::dev` class.
#
# As running rake under bundle is a common scenario, the `bundle` parameter will automatically wrap a rake task as a `bundle exec rake` command. This ensures that the rake command passes through the sanity checking in the `ruby::rake` resource, and meets the dependency requirements needed for both rake and bundler tasks.
#
# === Parameters
#
# Most of the parameters for this resource are passed through to the underlying `exec` resource that runs the Rake task. Check the Puppetlabs documentation on the [exec resource](http://docs.puppetlabs.com/references/latest/type.html#exec) for more details. Some parameters are not available.
#
# [*task]
# (this parameter is required) This parameter is the Ruby task to be performed as a string with command line options. e.g. `db:setup`.
# [*rails_env]
# (default is `production`) This parameter is used to set the `RAILS_ENV` environment variable, the default is to set it to production. This parameter is combined with the `environment` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the rake task.
# [*bundle]
# (default is false) If set to true, the Rake task is automatically run under a `ruby::bundler` resource.
# [*creates]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*cwd]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*environment]
# (default is undefined) This parameter is combined with the `rails_env` parameter to be passed to the `environment` parameter of the underlying `exec` resource that runs the rake task.
# [*user]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*group]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*logoutput]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*onlyif]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*path]
# (default is `['/usr/bin','/bin','/usr/sbin','/sbin']`) The rake executable has a minimum path requirement, if this parameter is left undefined, the default minimum path will be used. If a list of paths is provided, this list will be modified to be sure that it still meets the minimum path requirements for the rake executable. This is then passed to the underlying `exec` resource that runs the rake task.
# [*refresh]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*refreshonly]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*timeout]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*tries]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*try_sleep]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
# [*unless]
# (default is undefined) Passed through to the underlying `exec` resource that runs the rake task.
#
# === Examples
#
# An example on setting up an application's database:
#
# ruby::rake { 'setup_app_db':
# task => 'db:setup',
# cwd => '/path/to/app',
# }
#
# An example on setting up an application's database, with bundler:
#
# ruby::rake { 'setup_app_db':
# task => 'db:setup',
# bundle => true,
# cwd => '/path/to/app',
# }
#
define ruby::rake
(
$task,
$rails_env = undef,
$bundle = false,
$creates = undef,
$cwd = undef,
$environment = undef,
$user = undef,
$group = undef,
$logoutput = undef,
$onlyif = undef,
$path = undef,
$refresh = undef,
$refreshonly = undef,
$timeout = undef,
$tries = undef,
$try_sleep = undef,
$unless = undef,
) {
require ::ruby
if $rails_env == undef {
$rails_env_real = $ruby::params::rails_env
} else {
$rails_env_real = $rails_env
}
# Hmm this works on http://rubular.com/
# validate_re($task, '^[a-z][a-z0-9]*((:[a-z][a-z0-9]*)?)*$', "The rake task '${task}' does not conform to an expected format.")
# ensure minimum path requirements for bundler
if $path {
$real_path = unique(flatten([$path, $ruby::params::minimum_path]))
} else {
$real_path = $ruby::params::minimum_path
}
# merge the environment and rails_env parameters
if $environment {
$real_environment = unique(flatten([$environment, ["RAILS_ENV=${rails_env_real}"]]))
} else {
$real_environment = "RAILS_ENV=${rails_env_real}"
}
$real_command = join(['rake', $task],' ')
# wrapping rake tasks in bundler is a common practice, this makes sure
# dependencies and requirements are met.
if $bundle {
ruby::bundle{"ruby_rake_${name}":
command => 'exec',
option => $real_command,
rails_env => $rails_env_real,
creates => $creates,
cwd => $cwd,
environment => $environment,
user => $user,
group => $group,
logoutput => $logoutput,
onlyif => $onlyif,
path => $path,
refresh => $refresh,
refreshonly => $refreshonly,
timeout => $timeout,
tries => $tries,
try_sleep => $try_sleep,
unless => $unless,
require => Package['rake'],
}
} else {
exec{"ruby_rake_${name}":
command => $real_command,
creates => $creates,
cwd => $cwd,
environment => $real_environment,
user => $user,
group => $group,
logoutput => $logoutput,
onlyif => $onlyif,
path => $real_path,
refresh => $refresh,
refreshonly => $refreshonly,
timeout => $timeout,
tries => $tries,
try_sleep => $try_sleep,
unless => $unless,
require => Package['rake'],
}
}
}

View File

@@ -0,0 +1,82 @@
{
"name": "puppetlabs-ruby",
"version": "1.0.0",
"author": "Puppet Labs",
"summary": "Manages Ruby and Rubygems.",
"license": "Apache-2.0",
"source": "git@github.com:puppetlabs/puppetlabs-ruby.git",
"project_page": "https://github.com/puppetlabs/puppetlabs-ruby",
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
"dependencies": [
{"name":"puppetlabs/stdlib","version_requirement":">= 4.13.1 < 6.0.0"}
],
"data_provider": null,
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "OracleLinux",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "Scientific",
"operatingsystemrelease": [
"5",
"6",
"7"
]
},
{
"operatingsystem": "FreeBSD",
"operatingsystemrelease": [
"10"
]
},
{
"operatingsystem": "SLES",
"operatingsystemrelease": [
"11 SP1"
]
},
{
"operatingsystem": "Debian",
"operatingsystemrelease": [
"6",
"7",
"8"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"10.04",
"12.04",
"14.04"
]
}
],
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 4.7.0 < 5.0.0"
}
]
}

View File

@@ -0,0 +1,3 @@
class { '::ruby':
gems_version => 'latest',
}

View File

@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<utility xmlns="http://www.github/cliffe/SecGen/utility"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.github/cliffe/SecGen/utility">
<name>Ruby programming language</name>
<author>Thomas Shaw</author>
<author>puppetlabs</author>
<module_license>Apache v2</module_license>
<description>An installation of Ruby</description>
<type>language</type>
<type>ruby</type>
<platform>linux</platform>
<!--optional details-->
<reference>https://forge.puppet.com/puppetlabs/ruby</reference>
<software_name>ruby</software_name>
<software_license>Apache v2</software_license>
<requires>
<type>update</type>
</requires>
</utility>

View File

@@ -0,0 +1,89 @@
# Only testing on RedHat because the outcome is the same on Debian.
require 'spec_helper'
describe 'ruby::config', :type => :class do
describe 'when called with no parameters' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
it {
should contain_file('ruby_environment').with({
'ensure' => 'absent',
})
}
end
describe 'when called setting gc_malloc_limit parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :gc_malloc_limit => '10000' } }
it {
should contain_file('ruby_environment').with({
'ensure' => 'file',
'path' => '/etc/profile.d/ruby.sh'
})
}
it {
should contain_file('ruby_environment').with_content(/^export RUBY_GC_MALLOC_LIMIT=10000$/)
}
end
describe 'when called setting heap_free_min parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :heap_free_min => '10000' } }
it {
should contain_file('ruby_environment').with({
'ensure' => 'file',
'path' => '/etc/profile.d/ruby.sh'
})
}
it {
should contain_file('ruby_environment').with_content(/^export RUBY_HEAP_FREE_MIN=10000$/)
}
end
describe 'when called setting heap_slots_growth_factor parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :heap_slots_growth_factor => '10000' } }
it {
should contain_file('ruby_environment').with({
'ensure' => 'file',
'path' => '/etc/profile.d/ruby.sh'
})
}
it {
should contain_file('ruby_environment').with_content(/^export RUBY_HEAP_SLOTS_GROWTH_FACTOR=10000$/)
}
end
describe 'when called setting heap_min_slots parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :heap_min_slots => '10000' } }
it {
should contain_file('ruby_environment').with({
'ensure' => 'file',
'path' => '/etc/profile.d/ruby.sh'
})
}
it {
should contain_file('ruby_environment').with_content(/^export RUBY_HEAP_MIN_SLOTS=10000$/)
}
end
describe 'when called setting heap_slots_increment parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :heap_slots_increment => '10000' } }
it {
should contain_file('ruby_environment').with({
'ensure' => 'file',
'path' => '/etc/profile.d/ruby.sh'
})
}
it {
should contain_file('ruby_environment').with_content(/^export RUBY_HEAP_SLOTS_INCREMENT=10000$/)
}
end
end

View File

@@ -0,0 +1,860 @@
require 'spec_helper'
describe 'ruby::dev', :type => :class do
describe 'with default ruby' do
let :pre_condition do
'include ruby'
end
describe 'when called on an unsupported osfamily' do
let (:facts) do
{
:osfamily => 'Unsupported',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
it 'should fail' do
expect {
should contain_class('ruby::dev')
}.to raise_error(Puppet::Error, /Unsupported/)
end
end
describe 'when called on Redhat' do
let (:facts) do
{
:osfamily => 'RedHat',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby-devel').with({
'ensure' => 'installed',
})
}
context 'if on el 5 release' do
let(:facts) do
{
:osfamily => 'RedHat',
:operatingsystemmajrelease => '5',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
it {
should contain_package('rake').with({
'ensure' => '10.3.2',
'name' => 'rake',
'provider' => 'gem',
})
}
end
context 'if on non-el5 release' do
let (:facts) do
{
:osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rubygem-rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
end
context 'when using latest version' do
let :params do
{
:ensure => 'latest',
:rake_ensure => 'latest',
:bundler_ensure => 'latest'
}
end
it {
should contain_package('ruby-devel').with_ensure('latest')
}
it {
should contain_package('rake').with_ensure('latest')
}
it {
should contain_package('bundler').with_ensure('latest')
}
end
context 'when using custom packages' do
let :params do
{
:ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'],
:rake_package => 'magic-rake',
:bundler_package => 'sparkly-bundler'
}
end
it {
should contain_package('magic-ruby-dev')
}
it {
should contain_package('sparkly-ruby-dev')
}
it {
should contain_package('rake').with_name('magic-rake')
}
it {
should contain_package('bundler').with_name('sparkly-bundler')
}
it {
should_not contain_package('ruby-devel')
}
end
end
describe 'when called on Amazon' do
let (:facts) do
{
:osfamily => 'Amazon',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby-devel').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rubygem-rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
context 'when using latest version' do
let :params do
{
:ensure => 'latest',
:rake_ensure => 'latest',
:bundler_ensure => 'latest'
}
end
it {
should contain_package('ruby-devel').with_ensure('latest')
}
it {
should contain_package('rake').with_ensure('latest')
}
it {
should contain_package('bundler').with_ensure('latest')
}
end
context 'when using custom packages' do
let :params do
{
:ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'],
:rake_package => 'magic-rake',
:bundler_package => 'sparkly-bundler'
}
end
it {
should contain_package('magic-ruby-dev')
}
it {
should contain_package('sparkly-ruby-dev')
}
it {
should contain_package('rake').with_name('magic-rake')
}
it {
should contain_package('bundler').with_name('sparkly-bundler')
}
it {
should_not contain_package('ruby-devel')
}
end
end
describe 'when called on Debian' do
let (:facts) do
{
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby-dev').with({
'ensure' => 'installed',
})
}
it {
should contain_package('ri').with({
'ensure' => 'installed',
})
}
it {
should contain_package('pkg-config').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rake',
'require' => 'Package[ruby]',
})
}
context 'when on Ubuntu 10.04' do
let (:facts) do
{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:operatingsystemrelease => '10.04',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
it {
should contain_package('bundler').with({
'ensure' => '0.9.9',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]'
})
}
end
context 'when on Ubuntu 12.04' do
let (:facts) do
{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:operatingsystemrelease => '12.04',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]'
})
}
end
context 'when on Ubuntu 14.04' do
let (:facts) do
{
:osfamily => 'Debian',
:operatingsystemrelease => '14.04',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]'
})
}
end
context 'when on other Debian or Ubuntu' do
let (:facts) do
{
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:operatingsystemrelease => '14.04',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
end
context 'when using latest version' do
let :params do
{
:ensure => 'latest',
:rake_ensure => 'latest',
:bundler_ensure => 'latest'
}
end
it {
should contain_package('ruby-dev').with_ensure('latest')
}
it {
should contain_package('ri').with_ensure('latest')
}
it {
should contain_package('pkg-config').with_ensure('latest')
}
it {
should contain_package('rake').with_ensure('latest')
}
it {
should contain_package('bundler').with_ensure('latest')
}
end
context 'when using custom packages' do
let :params do
{
:ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'],
:rake_package => 'magic-rake',
:bundler_package => 'sparkly-bundler'
}
end
it {
should contain_package('magic-ruby-dev')
}
it {
should contain_package('sparkly-ruby-dev')
}
it {
should contain_package('rake').with_name('magic-rake')
}
it {
should contain_package('bundler').with_name('sparkly-bundler')
}
it {
should_not contain_package('ruby-dev')
}
it {
should_not contain_package('ri')
}
it {
should_not contain_package('pkg-config')
}
end
end
describe 'when called on Arch Linux' do
let (:facts) do
{
:osfamily => 'Archlinux',
:path => '/usr/bin'
}
end
context 'with no parameters' do
it { should_not contain_package('ruby-dev') }
it { should_not contain_package('rake') }
it do
should contain_package('bundler').with(
{
'ensure' => 'installed',
'name' => 'ruby-bundler',
'provider' => 'pacman',
'require' => 'Package[ruby]',
}
)
end
end
end
end
describe 'with ruby 1.9.1' do
let :pre_condition do
'class { \'ruby\': version => \'1.9.1\' }'
end
describe 'when called on Redhat' do
let (:facts) do
{
:osfamily => 'RedHat',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby-devel').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rubygem-rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
end
describe 'when called on Amazon' do
let (:facts) do
{
:osfamily => 'Amazon',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby-devel').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rubygem-rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
end
describe 'when called on Debian' do
let (:facts) do
{
:osfamily => 'Debian',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby1.9.1-dev').with({
'ensure' => 'installed',
})
}
it {
should contain_package('ri1.9.1').with({
'ensure' => 'installed',
})
}
it {
should contain_package('pkg-config').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
context 'when using latest version' do
let :params do
{
:ensure => 'latest',
:rake_ensure => 'latest',
:bundler_ensure => 'latest'
}
end
it {
should contain_package('ruby1.9.1-dev').with_ensure('latest')
}
it {
should contain_package('ri1.9.1').with_ensure('latest')
}
it {
should contain_package('pkg-config').with_ensure('latest')
}
it {
should contain_package('rake').with_ensure('latest')
}
it {
should contain_package('bundler').with_ensure('latest')
}
end
context 'when using custom packages' do
let :params do
{
:ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'],
:rake_package => 'magic-rake',
:bundler_package => 'sparkly-bundler'
}
end
it {
should contain_package('magic-ruby-dev')
}
it {
should contain_package('sparkly-ruby-dev')
}
it {
should contain_package('rake').with_name('magic-rake')
}
it {
should contain_package('bundler').with_name('sparkly-bundler')
}
it {
should_not contain_package('ruby1.9.1-dev')
}
it {
should_not contain_package('ri1.9.1')
}
it {
should_not contain_package('pkg-config')
}
end
end
end
describe 'with ruby 2.0.0' do
let :pre_condition do
'class { \'ruby\': version => \'2.0.0\' }'
end
describe 'when called on Redhat' do
let (:facts) do
{
:osfamily => 'RedHat',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby-devel').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rubygem-rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
end
describe 'when called on Amazon' do
let (:facts) do
{
:osfamily => 'Amazon',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby-devel').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rubygem-rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
end
describe 'when called on Debian' do
let (:facts) do
{
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby2.0-dev').with({
'ensure' => 'installed',
})
}
it {
should contain_package('ri').with({
'ensure' => 'installed',
})
}
it {
should contain_package('pkg-config').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
context 'when using latest version' do
let :params do
{
:ensure => 'latest',
:rake_ensure => 'latest',
:bundler_ensure => 'latest'
}
end
it {
should contain_package('ruby2.0-dev').with_ensure('latest')
}
it {
should contain_package('ri').with_ensure('latest')
}
it {
should contain_package('pkg-config').with_ensure('latest')
}
it {
should contain_package('rake').with_ensure('latest')
}
it {
should contain_package('bundler').with_ensure('latest')
}
end
context 'when using custom packages' do
let :params do
{
:ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'],
:rake_package => 'magic-rake',
:bundler_package => 'sparkly-bundler'
}
end
it {
should contain_package('magic-ruby-dev')
}
it {
should contain_package('sparkly-ruby-dev')
}
it {
should contain_package('rake').with_name('magic-rake')
}
it {
should contain_package('bundler').with_name('sparkly-bundler')
}
it {
should_not contain_package('ruby2.0-dev')
}
it {
should_not contain_package('ri')
}
it {
should_not contain_package('pkg-config')
}
end
end
end
describe 'with ruby 2.1.1' do
let :pre_condition do
'class { \'ruby\': version => \'2.1.1\' }'
end
describe 'when called on Redhat' do
let (:facts) do
{
:osfamily => 'RedHat',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby-devel').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rubygem-rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
end
describe 'when called on Amazon' do
let (:facts) do
{
:osfamily => 'Amazon',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby-devel').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rubygem-rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
end
describe 'when called on Debian' do
let (:facts) do
{
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:path => '/usr/local/bin:/usr/bin:/bin'
}
end
context 'with no parameters' do
it {
should contain_package('ruby2.1-dev').with({
'ensure' => 'installed',
})
}
it {
should contain_package('ri').with({
'ensure' => 'installed',
})
}
it {
should contain_package('pkg-config').with({
'ensure' => 'installed',
})
}
it {
should contain_package('rake').with({
'ensure' => 'installed',
'name' => 'rake',
'require' => 'Package[ruby]',
})
}
it {
should contain_package('bundler').with({
'ensure' => 'installed',
'name' => 'bundler',
'provider' => 'gem',
'require' => 'Package[ruby]',
})
}
end
context 'when using latest version' do
let :params do
{
:ensure => 'latest',
:rake_ensure => 'latest',
:bundler_ensure => 'latest'
}
end
it {
should contain_package('ruby2.1-dev').with_ensure('latest')
}
it {
should contain_package('ri').with_ensure('latest')
}
it {
should contain_package('pkg-config').with_ensure('latest')
}
it {
should contain_package('rake').with_ensure('latest')
}
it {
should contain_package('bundler').with_ensure('latest')
}
end
context 'when using custom packages' do
let :params do
{
:ruby_dev_packages => ['magic-ruby-dev','sparkly-ruby-dev'],
:rake_package => 'magic-rake',
:bundler_package => 'sparkly-bundler'
}
end
it {
should contain_package('magic-ruby-dev')
}
it {
should contain_package('sparkly-ruby-dev')
}
it {
should contain_package('rake').with_name('magic-rake')
}
it {
should contain_package('bundler').with_name('sparkly-bundler')
}
it {
should_not contain_package('ruby2.1-dev')
}
it {
should_not contain_package('ri')
}
it {
should_not contain_package('pkg-config')
}
end
end
end
end

View File

@@ -0,0 +1,119 @@
# Only testing on RedHat because the outcome is the same on Debian.
require 'spec_helper'
describe 'ruby::gemrc', :type => :class do
describe 'when called with no parameters' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
it {
should contain_file('gemrc').with({
'ensure' => 'absent',
})
}
end
describe 'when called setting verbose parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :verbose => ':really' } }
it {
should contain_file('gemrc').with({
'ensure' => 'file',
'path' => '/etc/gemrc'
})
}
it {
should contain_file('gemrc').with_content(/^:verbose: :really$/)
}
end
describe 'when called setting sources parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :sources => [ 'https://rubygems.org', 'https://ourgems.org' ] } }
it {
should contain_file('gemrc').with({
'ensure' => 'file',
'path' => '/etc/gemrc'
})
}
it {
should contain_file('gemrc').with_content(/:sources:\n\s{2}-\shttps:\/\/rubygems.org\n\s{2}-\shttps:\/\/ourgems.org/)
}
end
describe 'when called setting update_sources parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :update_sources => false } }
it {
should contain_file('gemrc').with({
'ensure' => 'file',
'path' => '/etc/gemrc'
})
}
it {
should contain_file('gemrc').with_content(/^:update_sources: false$/)
}
end
describe 'when called setting backtrace parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :backtrace => true } }
it {
should contain_file('gemrc').with({
'ensure' => 'file',
'path' => '/etc/gemrc'
})
}
it {
should contain_file('gemrc').with_content(/^:backtrace: true$/)
}
end
describe 'when called setting gempath parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :gempath => [ '/usr/local/share/gems', '/var/lib/gems' ] } }
it {
should contain_file('gemrc').with({
'ensure' => 'file',
'path' => '/etc/gemrc'
})
}
it {
should contain_file('gemrc').with_content(%r{^:gempath: /usr/local/share/gems:/var/lib/gems$})
}
end
describe 'when called setting disable_default_gem_server parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :disable_default_gem_server => true } }
it {
should contain_file('gemrc').with({
'ensure' => 'file',
'path' => '/etc/gemrc'
})
}
it {
should contain_file('gemrc').with_content(%r{^:disable_default_gem_server: true$})
}
end
describe 'when called setting gem_command parameter' do
let (:facts) { { :osfamily => 'Redhat',
:path => '/usr/local/bin:/usr/bin:/bin' } }
let (:params) { { :gem_command => { 'push' => [ 'host=https://gemshost.internal', 'quiet' ]} } }
it {
should contain_file('gemrc').with({
'ensure' => 'file',
'path' => '/etc/gemrc'
})
}
it {
should contain_file('gemrc').with_content(%r{^push: --host=https:..gemshost.internal --quiet$})
}
end
end

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,530 @@
require 'spec_helper'
describe 'ruby::bundle', :type => :define do
describe 'on RedHat based systems' do
let (:facts) do
{
:osfamily => 'RedHat',
:processorcount => '4'
}
end
let :pre_condition do
"include ruby\ninclude ruby::dev"
end
context 'with no parameters' do
let :title do
'install'
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
context 'with the install command' do
let :title do
'install'
end
let :params do
{
:command => 'install',
}
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
context 'with the update command' do
let :title do
'update'
end
let :params do
{
:command => 'update',
}
end
it {
should contain_exec('ruby_bundle_update').with({
'command' => 'bundle update',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle outdated',
'require' => 'Package[bundler]'
})
}
end
context 'with the install command with multicore 0' do
let :title do
'install'
end
let :params do
{
:command => 'install',
:multicore => '0'
}
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install --jobs 4',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
context 'with the install command with multicore less than max' do
let :title do
'install'
end
let :params do
{
:command => 'install',
:multicore => '3'
}
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install --jobs 3',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
context 'with the install command with multicore greater than max' do
let :title do
'install'
end
let :params do
{
:command => 'install',
:multicore => '17'
}
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install --jobs 4',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
context 'with the update command with multicore 0' do
let :title do
'update'
end
let :params do
{
:command => 'update',
:multicore => '0'
}
end
it {
should contain_exec('ruby_bundle_update').with({
'command' => 'bundle update --jobs 4',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle outdated',
'require' => 'Package[bundler]'
})
}
end
context 'with the update command with multicore less than max' do
let :title do
'update'
end
let :params do
{
:command => 'update',
:multicore => '3'
}
end
it {
should contain_exec('ruby_bundle_update').with({
'command' => 'bundle update --jobs 3',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle outdated',
'require' => 'Package[bundler]'
})
}
end
context 'with the update command with multicore greater than max' do
let :title do
'update'
end
let :params do
{
:command => 'update',
:multicore => '17'
}
end
it {
should contain_exec('ruby_bundle_update').with({
'command' => 'bundle update --jobs 4',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle outdated',
'require' => 'Package[bundler]'
})
}
end
context 'with the install command with multicore 0' do
let :title do
'install'
end
let :params do
{
:command => 'install',
:multicore => '0'
}
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install --jobs 4',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
context 'with the install command with multicore less than max' do
let :title do
'install'
end
let :params do
{
:command => 'install',
:multicore => '3'
}
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install --jobs 3',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
context 'with the install command with multicore greater than max' do
let :title do
'install'
end
let :params do
{
:command => 'install',
:multicore => '17'
}
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install --jobs 4',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
context 'with the update command with multicore 0' do
let :title do
'update'
end
let :params do
{
:command => 'update',
:multicore => '0'
}
end
it {
should contain_exec('ruby_bundle_update').with({
'command' => 'bundle update --jobs 4',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle outdated',
'require' => 'Package[bundler]'
})
}
end
context 'with the update command with multicore less than max' do
let :title do
'update'
end
let :params do
{
:command => 'update',
:multicore => '3'
}
end
it {
should contain_exec('ruby_bundle_update').with({
'command' => 'bundle update --jobs 3',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle outdated',
'require' => 'Package[bundler]'
})
}
end
context 'with the update command with multicore greater than max' do
let :title do
'update'
end
let :params do
{
:command => 'update',
:multicore => '17'
}
end
it {
should contain_exec('ruby_bundle_update').with({
'command' => 'bundle update --jobs 4',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle outdated',
'require' => 'Package[bundler]'
})
}
end
context 'when using the install command with options' do
let :title do
'install_with_options'
end
let :params do
{
:command => 'install',
:option => '--clean --deployment --gemfile=magical --path=/path/to/wherever --no-prune --without test development foo baa'
}
end
it {
should contain_exec('ruby_bundle_install_with_options').with({
'command' => 'bundle install --clean --deployment --gemfile=magical --path=/path/to/wherever --no-prune --without test development foo baa',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
context 'when using the update command with options' do
let :title do
'update_with_options'
end
let :params do
{
:command => 'update',
:option => '--local --source=http://some.gem.repo.org'
}
end
it {
should contain_exec('ruby_bundle_update_with_options').with({
'command' => 'bundle update --local --source=http://some.gem.repo.org',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle outdated --local --source=http://some.gem.repo.org',
'require' => 'Package[bundler]'
})
}
end
context 'when using the exec command with options' do
let :title do
'exec_with_options'
end
let :params do
{
:command => 'exec',
:option => 'echo foo >> test',
:unless => 'grep foo test'
}
end
it {
should contain_exec('ruby_bundle_exec_with_options').with({
'command' => 'bundle exec echo foo >> test',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'grep foo test',
'require' => 'Package[bundler]'
})
}
end
context 'when using the exec command without options' do
let :title do
'exec_without_options'
end
let :params do
{
:command => 'exec',
}
end
it do
expect {
should contain_exec('ruby_bundle_exec_without_options')
}.to raise_error(Puppet::Error, /When given the exec command the ruby::bundle resource requires the command to be executed to be passed to the option parameter/)
end
end
context 'with more paths' do
let :title do
'install'
end
let :params do
{
:command => 'install',
:path => ['/usr/share/foo/bin','/path/to/sbin']
}
end
it {
should contain_exec('ruby_bundle_install').with({
'path' => ['/usr/share/foo/bin', '/path/to/sbin', '/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
})
}
end
context 'with more environment variables' do
let :title do
'install'
end
let :params do
{
:command => 'install',
:environment => ['SHIELDS=up','PHASERS=stun']
}
end
it {
should contain_exec('ruby_bundle_install').with({
'environment' => ['SHIELDS=up', 'PHASERS=stun', 'RAILS_ENV=production'],
})
}
end
context 'with a custom Rails environment' do
let :title do
'install'
end
let :params do
{
:command => 'install',
:rails_env => 'test'
}
end
it {
should contain_exec('ruby_bundle_install').with({
'environment' => 'RAILS_ENV=test',
})
}
end
context 'that all parameters pass through' do
let :title do
'install'
end
let :params do
{
:command => 'install',
:creates => '/path/to/file',
:cwd => '/path/to/dir',
:user => 'nobody',
:group => 'anyone',
:logoutput => true,
:onlyif => 'confused',
:refresh => true,
:refreshonly => true,
:timeout => '300',
:tries => '2',
:try_sleep => '30'
}
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install',
'creates' => '/path/to/file',
'cwd' => '/path/to/dir',
'user' => 'nobody',
'group' => 'anyone',
'logoutput' => true,
'onlyif' => 'confused',
'refresh' => true,
'refreshonly' => true,
'timeout' => '300',
'tries' => '2',
'try_sleep' => '30'
})
}
end
end
describe 'on Amazon based systems' do
let (:facts) do
{
:osfamily => 'Amazon'
}
end
let :pre_condition do
"include ruby\ninclude ruby::dev"
end
context 'with no parameters' do
let :title do
'install'
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
end
describe 'on Debian based systems' do
let (:facts) do
{
:osfamily => 'Debian'
}
end
let :pre_condition do
"include ruby\ninclude ruby::dev"
end
context 'with no parameters' do
let :title do
'install'
end
it {
should contain_exec('ruby_bundle_install').with({
'command' => 'bundle install',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'unless' => 'bundle check',
'require' => 'Package[bundler]'
})
}
end
end
describe 'on an Unknown OS' do
let :facts do
{
:osfamily => 'Unknown'
}
end
let :title do
'test'
end
it do
expect {
should contain_class('puppet::params')
}.to raise_error(Puppet::Error, /Unsupported OS family: Unknown/)
end
end
end

View File

@@ -0,0 +1,247 @@
require 'spec_helper'
describe 'ruby::rake', :type => :define do
describe 'on RedHat based systems' do
let (:facts) do
{
:osfamily => 'RedHat',
}
end
let :pre_condition do
"include ruby\ninclude ruby::dev"
end
context 'with minimum parameters' do
let :title do
'db_setup'
end
let :params do
{
:task => 'db:setup'
}
end
it {
should contain_exec('ruby_rake_db_setup').with({
'command' => 'rake db:setup',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'require' => 'Package[rake]'
})
}
end
context 'with more paths' do
let :title do
'db_setup'
end
let :params do
{
:task => 'db:setup',
:path => ['/usr/share/foo/bin','/path/to/sbin']
}
end
it {
should contain_exec('ruby_rake_db_setup').with({
'path' => ['/usr/share/foo/bin', '/path/to/sbin', '/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
})
}
end
context 'with more environment variables' do
let :title do
'db_setup'
end
let :params do
{
:task => 'db:setup',
:environment => ['SHIELDS=up','PHASERS=stun']
}
end
it {
should contain_exec('ruby_rake_db_setup').with({
'environment' => ['SHIELDS=up', 'PHASERS=stun', 'RAILS_ENV=production'],
})
}
end
context 'with a custom Rails environment' do
let :title do
'db_setup'
end
let :params do
{
:task => 'db:setup',
:rails_env => 'test'
}
end
it {
should contain_exec('ruby_rake_db_setup').with({
'environment' => 'RAILS_ENV=test',
})
}
end
context 'checking parameter passthrough' do
let :title do
'db_setup'
end
let :params do
{
:task => 'db:setup',
:creates => '/path/to/file',
:cwd => '/path/to/dir',
:user => 'nobody',
:group => 'anybody',
:logoutput => true,
:onlyif => 'confused',
:refresh => true,
:refreshonly => true,
:timeout => '300',
:tries => '2',
:try_sleep => '30',
:unless => 'not true'
}
end
it {
should_not contain_ruby__bundle('ruby_rake_db_setup')
}
it {
should contain_exec('ruby_rake_db_setup').with({
'command' => 'rake db:setup',
'creates' => '/path/to/file',
'cwd' => '/path/to/dir',
'user' => 'nobody',
'group' => 'anybody',
'logoutput' => true,
'onlyif' => 'confused',
'refresh' => true,
'refreshonly' => true,
'timeout' => '300',
'tries' => '2',
'try_sleep' => '30',
'unless' => 'not true'
})
}
end
context 'checking parameter passthrough when using the bundler wrapper' do
let :title do
'db_setup'
end
let :params do
{
:task => 'db:setup',
:bundle => true,
:rails_env => 'test',
:creates => '/path/to/file',
:cwd => '/path/to/dir',
:environment => 'test',
:user => 'nobody',
:group => 'anybody',
:logoutput => true,
:onlyif => 'confused',
:path => ['/opt/app/bin','/usr/share/path'],
:refresh => true,
:refreshonly => true,
:timeout => '300',
:tries => '2',
:try_sleep => '30',
:unless => 'not true'
}
end
it {
should_not contain_exec('ruby_rake_db_setup')
}
it {
should contain_ruby__bundle('ruby_rake_db_setup').with({
'command' => 'exec',
'option' => 'rake db:setup',
'rails_env' => 'test',
'creates' => '/path/to/file',
'cwd' => '/path/to/dir',
'environment' => 'test',
'user' => 'nobody',
'group' => 'anybody',
'logoutput' => true,
'onlyif' => 'confused',
'path' => ['/opt/app/bin','/usr/share/path'],
'refresh' => true,
'refreshonly' => true,
'timeout' => '300',
'tries' => '2',
'try_sleep' => '30',
'unless' => 'not true'
})
}
end
end
describe 'on Amazon based systems' do
let (:facts) do
{
:osfamily => 'Amazon',
}
end
let :pre_condition do
"include ruby\ninclude ruby::dev"
end
context 'with minimum parameters' do
let :title do
'db_setup'
end
let :params do
{
:task => 'db:setup'
}
end
it {
should contain_exec('ruby_rake_db_setup').with({
'command' => 'rake db:setup',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'require' => 'Package[rake]'
})
}
end
end
describe 'on Debian based systems' do
let (:facts) do
{
:osfamily => 'Debian',
}
end
let :pre_condition do
"include ruby\ninclude ruby::dev"
end
context 'with no parameters' do
let :title do
'db_setup'
end
let :params do
{
:task => 'db:setup'
}
end
it {
should contain_exec('ruby_rake_db_setup').with({
'command' => 'rake db:setup',
'environment' => 'RAILS_ENV=production',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
'require' => 'Package[rake]'
})
}
end
end
describe 'on an Unknown OS' do
let :facts do
{
:osfamily => 'Unknown',
}
end
let :title do
'test'
end
let :params do
{
:task => 'db:setup'
}
end
it do
expect {
should contain_class('puppet::params')
}.to raise_error(Puppet::Error, /Unsupported OS family: Unknown/)
end
end
end

View File

@@ -0,0 +1,4 @@
--format s
--colour
--loadby mtime
--backtrace

View File

@@ -0,0 +1,19 @@
require 'puppetlabs_spec_helper/module_spec_helper'
RSpec.configure do |config|
config.hiera_config = 'spec/fixtures/hiera/hiera.yaml'
config.before :each do
# Ensure that we don't accidentally cache facts and environment between
# test cases. This requires each example group to explicitly load the
# facts being exercised with something like
# Facter.collection.loader.load(:ipaddress)
Facter.clear
Facter.clear_messages
end
config.default_facts = {
:environment => 'rp_env',
:operatingsystemmajrelease => '6',
:operatingsystemrelease => '6.1',
:operatingsystem => 'RedHat',
}
end

View File

@@ -0,0 +1,30 @@
require 'rspec-system/spec_helper'
require 'rspec-system-puppet/helpers'
require 'rspec-system-serverspec/helpers'
include Serverspec::Helper::RSpecSystem
include Serverspec::Helper::DetectOS
include RSpecSystemPuppet::Helpers
RSpec.configure do |c|
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
# Enable colour
c.tty = true
c.include RSpecSystemPuppet::Helpers
# This is where we 'setup' the nodes before running our tests
c.before :suite do
# Install puppet
puppet_install
# Install modules and dependencies
puppet_module_install(:source => proj_root, :module_name => 'ruby')
# Install the appropriate version of puppetlabs-stdlib
stdlib_ver = '4.6.0'
shell("puppet module install puppetlabs-stdlib --version #{stdlib_ver}")
end
end

View File

@@ -0,0 +1,26 @@
# This file is managed by Puppet
# Any modifications will be overwritten on the next run
<%- if @sources and ! @sources.empty? -%>
:sources:
- <%= Array(@sources).join("\n - ") %>
<%- end -%>
<%- unless @update_sources.nil? -%>
:update_sources: <%= @update_sources %>
<%- end -%>
<%- unless @verbose.nil? -%>
:verbose: <%= @verbose %>
<%- end -%>
<%- unless @backtrace.nil? -%>
:backtrace: <%= @backtrace %>
<%- end -%>
<%- if @gempath -%>
:gempath: <%= Array(@gempath).join(':') %>
<%- end -%>
<%- unless @disable_default_gem_server.nil? -%>
:disable_default_gem_server: <%= @disable_default_gem_server %>
<%- end -%>
<%- if @gem_command and ! @gem_command.empty? -%>
<%- @gem_command.each do |command,options| -%>
<%= command %>: --<%= Array(options).join(' --') %>
<%- end -%>
<%- end -%>

View File

@@ -0,0 +1,18 @@
# Set environemnt variables for Ruby as per
# http://www.rubyenterpriseedition.com/documentation.html#_garbage_collector_performance_tuning
# This file is managed by Puppet, any changes may be overwritten
<% if @gc_malloc_limit -%>
export RUBY_GC_MALLOC_LIMIT=<%= @gc_malloc_limit %>
<% end -%>
<% if @heap_free_min -%>
export RUBY_HEAP_FREE_MIN=<%= @heap_free_min %>
<% end -%>
<% if @heap_slots_growth_factor -%>
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=<%= @heap_slots_growth_factor %>
<% end -%>
<% if @heap_min_slots -%>
export RUBY_HEAP_MIN_SLOTS=<%= @heap_min_slots %>
<% end -%>
<% if @heap_slots_increment -%>
export RUBY_HEAP_SLOTS_INCREMENT=<%= @heap_slots_increment %>
<% end -%>

View File

@@ -0,0 +1,2 @@
include ::ruby
include ::ruby::dev

View File

@@ -0,0 +1 @@
include ::ruby

View File

@@ -0,0 +1 @@
include ::ruby::params

View File

@@ -0,0 +1,3 @@
class { '::ruby':
version => '1.8',
}

View File

@@ -0,0 +1,4 @@
class { '::ruby':
version => '1.9',
set_system_default => true,
}

View File

@@ -0,0 +1,6 @@
class { '::ruby':
version => '1.9.3',
latest_release => true,
rubygems_update => true,
}
include ::ruby::dev

View File

@@ -0,0 +1,4 @@
class { '::ruby':
version => '2.0',
set_system_default => true,
}

View File

@@ -0,0 +1,4 @@
class { '::ruby':
version => '2.1',
set_system_default => true,
}

View File

@@ -0,0 +1,6 @@
class { '::ruby':
version => '2.0.0',
latest_release => true,
rubygems_update => true,
}
include ::ruby::dev