diff --git a/manifests/init.pp b/manifests/init.pp index fd90c5b..50b014a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -48,6 +48,7 @@ $nexus_manage_user = $nexus::params::nexus_manage_user, $nexus_data_folder = $nexus::params::nexus_data_folder, $download_folder = $nexus::params::download_folder, + $download_provider = $nexus::params::download_provider, $manage_config = $nexus::params::manage_config, $md5sum = $nexus::params::md5sum, ) inherits nexus::params { @@ -106,6 +107,7 @@ revision => $revision, deploy_pro => $deploy_pro, download_site => $real_download_site, + download_provider => $download_provider, nexus_root => $nexus_root, nexus_home_dir => $nexus_home_dir, nexus_user => $nexus_user, diff --git a/manifests/package.pp b/manifests/package.pp index 80296bc..2f5dc96 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -42,6 +42,7 @@ $nexus_work_recurse = $::nexus::nexus_work_recurse, $nexus_selinux_ignore_defaults = $::nexus::nexus_selinux_ignore_defaults, $download_folder = $::nexus::download_folder, + $download_provider = $::nexus::download_provider, $md5sum = $::nexus::md5sum, ) { @@ -60,25 +61,64 @@ $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'], - } + case $download_provider { + 'wget::fetch': { + # 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'], + before => File[$nexus_home_real] + } - exec{ 'nexus-untar': - command => "tar zxf ${download_folder}/${nexus_archive} --directory ${nexus_root}", - creates => $nexus_home_real, - path => ['/bin','/usr/bin'], + if $nexus_work_dir_manage == true { + Wget::Fetch[$nexus_archive] -> File[$nexus_work_dir] + } + } + 'archive': { + case $md5sum { + undef: { + $md5sum_real = undef + $md5sum_type = undef + } + default: { + $md5sum_real = $md5sum + $md5sum_type = 'md5' + } + } + + archive{ $dl_file: + ensure => present, + extract => true, + extract_path => $nexus_root, + source => $download_url, + checksum => $md5sum_real, + checksum_type => $md5sum_type, + creates => $nexus_home_real, + before => File[$nexus_home_real] + } + + if $nexus_work_dir_manage == true { + Archive[$dl_file] -> File[$nexus_work_dir] + } + } + default: { + fail("Download_provider ${download_provider} not supported.") + } } # NOTE: $nexus_work_dir in later releases was moved to a directory not @@ -89,8 +129,7 @@ owner => $nexus_user, group => $nexus_group, recurse => true, - selinux_ignore_defaults => $nexus_selinux_ignore_defaults, - require => Exec[ 'nexus-untar'] + selinux_ignore_defaults => $nexus_selinux_ignore_defaults } @@ -103,7 +142,7 @@ group => $nexus_group, recurse => $nexus_work_recurse, selinux_ignore_defaults => $nexus_selinux_ignore_defaults, - require => Exec[ 'nexus-untar'] + # require => Exec[ 'nexus-untar'] } # Nexus 3 needs to have a nexus_work_dir/etc for the properties file @@ -121,6 +160,6 @@ file{ $nexus_home: ensure => link, target => $nexus_home_real, - require => Exec['nexus-untar'] + require => File[$nexus_home_real] } } diff --git a/manifests/params.pp b/manifests/params.pp index e27739f..582300f 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -40,6 +40,7 @@ $pro_download_site = 'http://download.sonatype.com/nexus/professional-bundle' $nexus_data_folder = undef $download_folder = '/srv' + $download_provider = 'wget::fetch' $manage_config = true $md5sum = undef } diff --git a/spec/classes/package_spec.rb b/spec/classes/package_spec.rb index e2f1a23..be42974 100644 --- a/spec/classes/package_spec.rb +++ b/spec/classes/package_spec.rb @@ -11,6 +11,7 @@ { 'deploy_pro' => false, 'download_site' => 'http://download.sonatype.com/nexus/oss', + 'download_provider' => 'wget::fetch', 'nexus_root' => '/srv', 'nexus_home_dir' => 'nexus', 'nexus_user' => 'nexus', @@ -42,6 +43,7 @@ 'command' => 'tar zxf /srv/nexus-2.11.2-01-bundle.tar.gz --directory /srv', 'creates' => '/srv/nexus-2.11.2-01', 'path' => [ '/bin', '/usr/bin' ], + 'before' => 'File[/srv/nexus/2.11.2-01]' ) } it { should contain_file('/srv/nexus-2.11.2-01').with( @@ -49,7 +51,7 @@ 'owner' => 'nexus', 'group' => 'nexus', 'recurse' => true, - 'require' => 'Exec[nexus-untar]', + # 'require' => 'Exec[nexus-untar]', ) } it { should contain_file('/srv/sonatype-work/nexus').with( @@ -63,7 +65,7 @@ it { should contain_file('/srv/nexus').with( 'ensure' => 'link', 'target' => '/srv/nexus-2.11.2-01', - 'require' => 'Exec[nexus-untar]', + 'require' => 'File[/srv/nexus-2.11.2-01]', ) } it 'should handle deploy_pro' do