diff --git a/manifests/init.pp b/manifests/init.pp index fd90c5b..5b0a1c9 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -50,6 +50,9 @@ $download_folder = $nexus::params::download_folder, $manage_config = $nexus::params::manage_config, $md5sum = $nexus::params::md5sum, + $package_name = $nexus::params::package_name, + $package_version = $nexus::params::package_version, + $package_install = $nexus::params::package_install, ) inherits nexus::params { include stdlib @@ -101,20 +104,46 @@ } } - class{ 'nexus::package': - version => $version, - revision => $revision, - deploy_pro => $deploy_pro, - download_site => $real_download_site, - nexus_root => $nexus_root, - nexus_home_dir => $nexus_home_dir, - nexus_user => $nexus_user, - nexus_group => $nexus_group, - nexus_work_dir => $real_nexus_work_dir, - nexus_work_dir_manage => $nexus_work_dir_manage, - nexus_work_recurse => $nexus_work_recurse, - md5sum => $md5sum, - notify => Class['nexus::service'] + + if ($package_install and $package_name != undef) { + class{ 'nexus::package': + version => $version, + revision => $revision, + deploy_pro => $deploy_pro, + download_site => $real_download_site, + nexus_root => $nexus_root, + nexus_home_dir => $nexus_home_dir, + nexus_user => $nexus_user, + nexus_group => $nexus_group, + nexus_work_dir => $real_nexus_work_dir, + nexus_work_dir_manage => $nexus_work_dir_manage, + nexus_work_recurse => $nexus_work_recurse, + md5sum => $md5sum, + notify => Class['nexus::service'], + package_name => $package_name, + package_version => $package_version, + } + + anchor{ 'nexus::setup': } -> Class['nexus::package'] -> Class['nexus::config'] -> Class['nexus::Service'] -> anchor { 'nexus::done': } + } + else { + class{ 'nexus::wget': + version => $version, + revision => $revision, + deploy_pro => $deploy_pro, + download_site => $real_download_site, + nexus_root => $nexus_root, + nexus_home_dir => $nexus_home_dir, + nexus_user => $nexus_user, + nexus_group => $nexus_group, + nexus_work_dir => $real_nexus_work_dir, + nexus_work_dir_manage => $nexus_work_dir_manage, + nexus_work_recurse => $nexus_work_recurse, + md5sum => $md5sum, + notify => Class['nexus::service'] + } + + anchor{ 'nexus::setup': } -> Class['nexus::wget'] -> Class['nexus::config'] -> Class['nexus::Service'] -> anchor { 'nexus::done': } } if $manage_config { @@ -137,5 +166,5 @@ version => $version, } - anchor{ 'nexus::setup': } -> Class['nexus::package'] -> Class['nexus::config'] -> Class['nexus::Service'] -> anchor { 'nexus::done': } + # anchor{ 'nexus::setup': } -> Class['nexus::package'] -> Class['nexus::config'] -> Class['nexus::Service'] -> anchor { 'nexus::done': } } diff --git a/manifests/package.pp b/manifests/package.pp index 80296bc..8842230 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -43,6 +43,8 @@ $nexus_selinux_ignore_defaults = $::nexus::nexus_selinux_ignore_defaults, $download_folder = $::nexus::download_folder, $md5sum = $::nexus::md5sum, + $package_name = $::nexus::package_name, + $package_version = $::nexus::package_version, ) { $nexus_home = "${nexus_root}/${nexus_home_dir}" @@ -68,17 +70,8 @@ # NOTE: I *think* this won't repeatedly download the file because it's # linked to an exec resource which won't be realized if a directory # already exists. - wget::fetch{ $nexus_archive: - source => $download_url, - destination => $dl_file, - source_hash => $md5sum, - before => Exec['nexus-untar'], - } - - exec{ 'nexus-untar': - command => "tar zxf ${download_folder}/${nexus_archive} --directory ${nexus_root}", - creates => $nexus_home_real, - path => ['/bin','/usr/bin'], + package { $package_name: + ensure => $package_version, } # NOTE: $nexus_work_dir in later releases was moved to a directory not @@ -90,7 +83,7 @@ group => $nexus_group, recurse => true, selinux_ignore_defaults => $nexus_selinux_ignore_defaults, - require => Exec[ 'nexus-untar'] + require => Package[$package_name], } @@ -103,7 +96,7 @@ group => $nexus_group, recurse => $nexus_work_recurse, selinux_ignore_defaults => $nexus_selinux_ignore_defaults, - require => Exec[ 'nexus-untar'] + require => Package[$package_name], } # Nexus 3 needs to have a nexus_work_dir/etc for the properties file @@ -121,6 +114,6 @@ file{ $nexus_home: ensure => link, target => $nexus_home_real, - require => Exec['nexus-untar'] + require => Package[$package_name], } } diff --git a/manifests/params.pp b/manifests/params.pp index e27739f..4eadd7d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -42,4 +42,7 @@ $download_folder = '/srv' $manage_config = true $md5sum = undef + $package_install = false + $package_name = undef + $package_version = undef } diff --git a/manifests/service.pp b/manifests/service.pp index 0d65d71..c524eb8 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -43,7 +43,7 @@ if ($::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '8.0') > 0) or ($::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '15.04') > 0) or - (($::operatingsystem == 'CentOS' or $::operatingsystem == 'RedHat') and versioncmp($::operatingsystemmajrelease, '7') >= 0) { + (($::operatingsystem == 'CentOS' or $::operatingsystem == 'RedHat' or $::osfamily == 'RedHat') and versioncmp($::operatingsystemmajrelease, '7') >= 0) { file { '/lib/systemd/system/nexus.service': mode => '0644', owner => 'root', diff --git a/manifests/wget.pp b/manifests/wget.pp new file mode 100644 index 0000000..ab511c5 --- /dev/null +++ b/manifests/wget.pp @@ -0,0 +1,127 @@ +# === Class: nexus::wget +# +# Install the Nexus package using wget +# +# === Parameters +# +# [*version*] +# The version to download. +# +# [*revision*] +# The revision of the archive. This is needed for the name of the +# directory the archive is extracted to. The default should suffice. +# +# [*nexus_root*] +# The root directory where the nexus application will live and tarballs +# will be downloaded to. +# +# === Examples +# +# class{ 'nexus::wget': } +# +# === Authors +# +# Tom McLaughlin +# +# === Copyright +# +# Copyright 2013 Hubspot +# +class nexus::wget ( + $version = $::nexus::version, + $revision = $::nexus::revision, + $deploy_pro = $::nexus::deploy_pro, + $download_site = $::nexus::download_site, + $nexus_type = $::nexus::nexus_type, + $nexus_root = $::nexus::nexus_root, + $nexus_home_dir = $::nexus::nexus_home_dir, + $nexus_user = $::nexus::nexus_user, + $nexus_group = $::nexus::nexus_group, + $nexus_work_dir = $::nexus::nexus_work_dir, + $nexus_work_dir_manage = $::nexus::nexus_work_dir_manage, + $nexus_work_recurse = $::nexus::nexus_work_recurse, + $nexus_selinux_ignore_defaults = $::nexus::nexus_selinux_ignore_defaults, + $download_folder = $::nexus::download_folder, + $md5sum = $::nexus::md5sum, +) { + + $nexus_home = "${nexus_root}/${nexus_home_dir}" + + $full_version = "${version}-${revision}" + + if ($deploy_pro) { + $bundle_type = '-professional' + } else { + $bundle_type = '' + } + + $nexus_archive = "nexus${bundle_type}-${full_version}-${nexus_type}.tar.gz" + $download_url = "${download_site}/${nexus_archive}" + $dl_file = "${download_folder}/${nexus_archive}" + $nexus_home_real = "${nexus_root}/nexus${bundle_type}-${full_version}" + + # NOTE: When setting version to 'latest' the site redirects to the latest + # release. But, nexus-latest-bundle.tar.gz will already exist and + # therefore the exec will never be triggered. In reality 'latest' will + # lock you to a version. + # + # NOTE: I *think* this won't repeatedly download the file because it's + # linked to an exec resource which won't be realized if a directory + # already exists. + + wget::fetch{ $nexus_archive: + source => $download_url, + destination => $dl_file, + source_hash => $md5sum, + before => Exec['nexus-untar'], + } + + exec{ 'nexus-untar': + command => "tar zxf ${download_folder}/${nexus_archive} --directory ${nexus_root}", + creates => $nexus_home_real, + path => ['/bin','/usr/bin'], + } + + # NOTE: $nexus_work_dir in later releases was moved to a directory not + # under the application. This is why we do not make recursing optional + # for this resource but do for $nexus_work_dir. + file{ $nexus_home_real: + ensure => directory, + owner => $nexus_user, + group => $nexus_group, + recurse => true, + selinux_ignore_defaults => $nexus_selinux_ignore_defaults, + require => Exec[ 'nexus-untar'] + } + + + # I have an EBS volume for $nexus_work_dir and mounting code in our tree + # creates this and results in a duplicate resource. -tmclaughlin + if $nexus_work_dir_manage == true { + file{ $nexus_work_dir: + ensure => directory, + owner => $nexus_user, + group => $nexus_group, + recurse => $nexus_work_recurse, + selinux_ignore_defaults => $nexus_selinux_ignore_defaults, + require => Exec[ 'nexus-untar'] + } + + # Nexus 3 needs to have a nexus_work_dir/etc for the properties file + if $version !~ /\d.*/ or versioncmp($version, '3.1.0') >= 0 { + file { "${nexus_work_dir}/etc": + ensure => directory, + owner => $nexus_user, + group => $nexus_group, + recurse => $nexus_work_recurse, + selinux_ignore_defaults => $nexus_selinux_ignore_defaults, + } + } + } + + file{ $nexus_home: + ensure => link, + target => $nexus_home_real, + require => Exec['nexus-untar'] + } +} diff --git a/metadata.json b/metadata.json index 13934a6..347d166 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "hubspot-nexus", - "version": "1.7.3", + "version": "1.7.6", "source": "http://github.com/hubspotdevops/puppet-nexus", "author": "Tom McLaughlin ", "license": "MIT",