Skip to content

Commit

Permalink
Add new package_name parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-mueller committed Apr 17, 2016
1 parent d393c8a commit 638ccf5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ If you want to use Hiera to configure your cronjobs, you must declare the `cron`

You can disable the managment of the cron package by setting the `manage_package` parameter to `false`.

You can also specify a different cron package name via `package_name`.
By default we try to select the right one for your distribution.
But in some cases (e.g. Gentoo) you might want to overwrite it here.

This class allows specifiying the following parameter:

* `manage_package` - optional - defaults to "true"
* `package_ensure` - optional - defaults to "installed"
* `package_name` - optional - defaults to "undef"


Examples:
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# 'present'.
# Default: installed
#
# package_name - Can be set to install a different cron package.
# Default: undef
#
# Actions:
#
Expand All @@ -26,11 +28,13 @@
class cron (
$manage_package = true,
$package_ensure = 'installed',
$package_name = undef,
) {

if $manage_package {
class { '::cron::install':
package_ensure => $package_ensure,
package_name => $package_name,
}
}

Expand Down
47 changes: 28 additions & 19 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# Parameters:
# package_ensure - Can be set to a package version, 'latest', 'installed' or
# 'present'.
# Default: installed
#
# package_name - Can be used to install a different cron package.
# Default: undef
#
# Actions:
#
Expand All @@ -16,33 +20,38 @@
#
class cron::install (
$package_ensure = 'installed',
$package_name = undef,
) {

case $::operatingsystem {
/^(RedHat|CentOS|Amazon|OracleLinux)/: {
if versioncmp($::operatingsystemmajrelease, '5') <= 0 {
$package_name = 'vixie-cron'
} else {
$package_name = 'cronie'
if $package_name {
$real_package_name = $package_name
} else {
case $::operatingsystem {
/^(RedHat|CentOS|Amazon|OracleLinux)/: {
if versioncmp($::operatingsystemmajrelease, '5') <= 0 {
$real_package_name = 'vixie-cron'
} else {
$real_package_name = 'cronie'
}
}
'Gentoo': {
$real_package_name = 'virtual/cron'
}
'Ubuntu': {
$real_package_name = 'cron'
}
'Debian': {
$real_package_name = 'cron'
}
default: {
$real_package_name = 'cron'
}
}
'Gentoo': {
$package_name = 'virtual/cron'
}
'Ubuntu': {
$package_name = 'cron'
}
'Debian': {
$package_name = 'cron'
}
default: {
$package_name = 'cron'
}
}

package { 'cron':
ensure => $package_ensure,
name => $package_name,
name => $real_package_name,
}

}
Expand Down
17 changes: 17 additions & 0 deletions spec/classes/cron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,21 @@
)
}
end

context 'package_name => sys-process/cronie' do
let :facts do
{
:operatingsystem => 'Gentoo',
}
end
let( :params ) {{ :package_name => 'sys-process/cronie', }}

it { should contain_class( 'cron::install' ) }
it { should contain_package( 'cron' ).with(
'name' => 'sys-process/cronie',
'ensure' => 'installed'
)
}
end

end

0 comments on commit 638ccf5

Please sign in to comment.