Skip to content

Commit

Permalink
properly handle version for archive/package install methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bfraser committed Apr 30, 2016
1 parent 774f8a6 commit acc8075
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
14 changes: 5 additions & 9 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
# }
#
class grafana (
$version = $::grafana::params::version,
$rpm_iteration = $::grafana::params::rpm_iteration,
$archive_source = "https://grafanarel.s3.amazonaws.com/builds/grafana-${version}.linux-x64.tar.gz",
$archive_source = $::grafana::params::archive_source,
$cfg_location = $::grafana::params::cfg_location,
$cfg = $::grafana::params::cfg,
$ldap_cfg = $::grafana::params::ldap_cfg,
Expand All @@ -76,12 +74,10 @@
$install_method = $::grafana::params::install_method,
$manage_package_repo = $::grafana::params::manage_package_repo,
$package_name = $::grafana::params::package_name,
$package_source = $::osfamily ? {
/(RedHat|Amazon)/ => "https://grafanarel.s3.amazonaws.com/builds/grafana-${version}-${rpm_iteration}.x86_64.rpm",
'Debian' => "https://grafanarel.s3.amazonaws.com/builds/grafana_${version}_amd64.deb",
default => $archive_source,
},
$service_name = $::grafana::params::service_name
$package_source = $::grafana::params::package_source,
$rpm_iteration = $::grafana::params::rpm_iteration,
$service_name = $::grafana::params::service_name,
$version = $::grafana::params::version
) inherits grafana::params {

# validate parameters here
Expand Down
24 changes: 21 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# == Class grafana::install
#
class grafana::install {
if $::grafana::archive_source != undef {
$real_archive_source = $::grafana::archive_source
}
else {
$real_archive_source = "https://grafanarel.s3.amazonaws.com/builds/grafana-${::grafana::version}.linux-x64.tar.gz"
}

if $::grafana::package_source != undef {
$real_package_source = $::grafana::package_source
}
else {
$real_package_source = $::osfamily ? {
/(RedHat|Amazon)/ => "https://grafanarel.s3.amazonaws.com/builds/grafana-${::grafana::version}-${::grafana::rpm_iteration}.x86_64.rpm",
'Debian' => "https://grafanarel.s3.amazonaws.com/builds/grafana_${::grafana::version}_amd64.deb",
default => $real_archive_source,
}
}

case $::grafana::install_method {
'docker': {
docker::image { 'grafana/grafana':
Expand All @@ -16,7 +34,7 @@
}

wget::fetch { 'grafana':
source => $::grafana::package_source,
source => $real_package_source,
destination => '/tmp/grafana.deb'
}

Expand All @@ -35,7 +53,7 @@
package { $::grafana::package_name:
ensure => present,
provider => 'rpm',
source => $::grafana::package_source,
source => $real_package_source,
require => Package['fontconfig']
}
}
Expand Down Expand Up @@ -121,7 +139,7 @@
extract => true,
extract_command => 'tar xfz %s --strip-components=1',
extract_path => $::grafana::install_dir,
source => $::grafana::archive_source,
source => $real_archive_source,
user => 'grafana',
group => 'grafana',
cleanup => true,
Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# It sets variables according to platform
#
class grafana::params {
$archive_source = undef

This comment has been minimized.

Copy link
@walterheck

walterheck May 2, 2016

Isn't it a bit of an anti-pattern to specify undef variables in the params class?

$cfg_location = '/etc/grafana/grafana.ini'
$cfg = {}
$container_cfg = false
Expand All @@ -16,6 +17,7 @@
$ldap_cfg = false
$manage_package_repo = true
$package_name = 'grafana'
$package_source = undef
$rpm_iteration = '1'
$service_name = 'grafana-server'
$version = '2.5.0'
Expand Down

0 comments on commit acc8075

Please sign in to comment.