Skip to content

Commit

Permalink
breakdown install_method case into separate classes/files
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierig Le Saux committed Mar 6, 2016
1 parent 7a6fc7b commit fb621f7
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 108 deletions.
115 changes: 7 additions & 108 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,119 +4,18 @@
#
class kibana4::install {

if $kibana4::install_method == 'archive' {
$package_name = $kibana4::package_name
$version = $kibana4::package_ensure
case $kibana4::install_method {

$download_url = $kibana4::package_download_url ? {
undef => "${kibana4::params::es_download_site_url}/kibana/kibana/${package_name}-${version}.tar.gz",
default => $kibana4::package_download_url,
'archive': {
contain kibana4::install::archive
}

case $kibana4::archive_provider {
'nanliu','puppet': {

if $kibana4::package_proxy_server {
fail("Setting a proxy server for archive download is not supported when \$archive_provider is '${kibana4::archive_provider}'")
}

archive { "${kibana4::install_dir}/kibana-${version}.tar.gz":
ensure => present,
user => 'root',
group => 'root',
source => $download_url,
extract_path => $kibana4::install_dir,
# Extract files as the user doing the extracting, which is the user
# that runs Puppet, usually root
extract_flags => '-x --no-same-owner -f',
creates => "${kibana4::install_dir}/kibana-${version}",
extract => true,
cleanup => true,
notify => Exec['chown_kibana_directory'],
}

$symlink_require = Archive["${kibana4::install_dir}/kibana-${version}.tar.gz"]
}
'camptocamp': {
archive { "kibana-${version}":
ensure => present,
checksum => false,
verbose => false,
target => $kibana4::install_dir,
url => $download_url,
proxy_server => $kibana4::package_proxy_server,
timeout => $kibana4::package_dl_timeout,
notify => Exec['chown_kibana_directory'],
}

$symlink_require = Archive["kibana-${version}"]
}
default: {
fail("Unsupported \$archive_provider '${kibana4::archive_provider}'. Should be 'camptocamp' or 'nanliu' (aka 'puppet').")
}
}

exec { 'chown_kibana_directory':
command => "chown -R ${kibana4::kibana4_user}:${kibana4::kibana4_group} ${kibana4::install_dir}/kibana-${version}",
path => ['/bin','/sbin'],
refreshonly => true,
require => $symlink_require,
}

if $kibana4::symlink {
file { $kibana4::symlink_name:
ensure => link,
require => $symlink_require,
target => "${kibana4::install_dir}/kibana-${version}",
owner => $kibana4::kibana4_user,
group => $kibana4::kibana4_group,
}
}
}

if $kibana4::install_method == 'package' {

if $kibana4::use_official_repo {

case $::osfamily {
'RedHat': {
yumrepo { "kibana-${kibana4::repo_version}":
baseurl => "http://packages.elastic.co/kibana/${kibana4::repo_version}/centos",
enabled => '1',
gpgcheck => '1',
gpgkey => 'https://packages.elastic.co/GPG-KEY-elasticsearch',
descr => "Kibana repository for ${kibana4::repo_version}.x packages",
before => Package['kibana4'],
}
}
'Debian': {
if !defined(Class['apt']) {
class { 'apt': }
}
apt::source { "kibana-${kibana4::repo_version}":
location => "http://packages.elastic.co/kibana/${kibana4::repo_version}/debian",
release => 'stable',
repos => 'main',
key => {
'source' => 'http://packages.elastic.co/GPG-KEY-elasticsearch',
'id' => '46095ACC8548582C1A2699A9D27D666CD88E42B4',
},
include => {
'src' => false,
},
before => Package['kibana4'],
}
}
default: {
fail("${::operatingsystem} not supported")
}
}

'package': {
contain kibana4::install::package
}

package { 'kibana4':
ensure => $kibana4::package_ensure,
name => $kibana4::package_name,
default: {
fail("Valid installation methods are `package` or `archive`")
}

}
Expand Down
82 changes: 82 additions & 0 deletions manifests/install/archive.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# == Class: kibana4
#
# Archive Installation Method
#
class kibana4::install::archive {

$package_name = $kibana4::package_name
$version = $kibana4::package_ensure

$download_url = $kibana4::package_download_url ? {
undef => "${kibana4::params::es_download_site_url}/kibana/kibana/${package_name}-${version}.tar.gz",
default => $kibana4::package_download_url,
}

case $kibana4::archive_provider {
'nanliu','puppet': {

if $kibana4::package_proxy_server {
fail("Setting a proxy server for archive download is not supported when \$archive_provider is '${kibana4::archive_provider}'")
}

archive { "${kibana4::install_dir}/kibana-${version}.tar.gz":
ensure => present,
user => 'root',
group => 'root',
source => $download_url,
extract_path => $kibana4::install_dir,
# Extract files as the user doing the extracting, which is the user
# that runs Puppet, usually root
extract_flags => '-x --no-same-owner -f',
creates => "${kibana4::install_dir}/kibana-${version}",
extract => true,
cleanup => true,
notify => Exec['chown_kibana_directory'],
}

$symlink_require = Archive["${kibana4::install_dir}/kibana-${version}.tar.gz"]

}

'camptocamp': {
archive { "kibana-${version}":
ensure => present,
checksum => false,
verbose => false,
target => $kibana4::install_dir,
url => $download_url,
proxy_server => $kibana4::package_proxy_server,
timeout => $kibana4::package_dl_timeout,
notify => Exec['chown_kibana_directory'],
}

$symlink_require = Archive["kibana-${version}"]

}

default: {
fail("Unsupported \$archive_provider '${kibana4::archive_provider}'. Should be 'camptocamp' or 'nanliu' (aka 'puppet').")
}

}

exec { 'chown_kibana_directory':
command => "chown -R ${kibana4::kibana4_user}:${kibana4::kibana4_group} ${kibana4::install_dir}/kibana-${version}",
path => ['/bin','/sbin'],
refreshonly => true,
require => $symlink_require,
}

if $kibana4::symlink {

file { $kibana4::symlink_name:
ensure => link,
require => $symlink_require,
target => "${kibana4::install_dir}/kibana-${version}",
owner => $kibana4::kibana4_user,
group => $kibana4::kibana4_group,
}

}

}
54 changes: 54 additions & 0 deletions manifests/install/package.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# == Class: kibana4
#
# Package Installation Method
#
class kibana4::install::package {

if $kibana4::use_official_repo {

case $::osfamily {

'RedHat': {
yumrepo { "kibana-${kibana4::repo_version}":
baseurl => "http://packages.elastic.co/kibana/${kibana4::repo_version}/centos",
enabled => '1',
gpgcheck => '1',
gpgkey => 'https://packages.elastic.co/GPG-KEY-elasticsearch',
descr => "Kibana repository for ${kibana4::repo_version}.x packages",
before => Package['kibana4'],
}
}

'Debian': {
if !defined(Class['apt']) {
class { 'apt': }
}
apt::source { "kibana-${kibana4::repo_version}":
location => "http://packages.elastic.co/kibana/${kibana4::repo_version}/debian",
release => 'stable',
repos => 'main',
key => {
'source' => 'http://packages.elastic.co/GPG-KEY-elasticsearch',
'id' => '46095ACC8548582C1A2699A9D27D666CD88E42B4',
},
include => {
'src' => false,
},
before => Package['kibana4'],
}
}

default: {
fail("${::operatingsystem} not supported")
}

}

}

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

}

0 comments on commit fb621f7

Please sign in to comment.