Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
FunFR authored Dec 19, 2017
2 parents 469bf79 + 35219c2 commit 65674d9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
2 changes: 2 additions & 0 deletions manifests/deploy.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$environment = undef, #: environment variable for settings such as http_proxy
$strip = undef, #: extract file with the --strip=X option. Only works with GNU tar.
$use_7zip = false, #: alternative to unzip command on Windows
$untar_opts = '', #: additional options to pass to tar.
$unzip_opts = '', #: additional options to pass the unzip command.
$timeout = undef, #: the time to wait for the file transfer to complete
$user = undef, #: extract file as this user
Expand Down Expand Up @@ -51,6 +52,7 @@
strip => $strip,
use_7zip => $use_7zip,
unzip_opts => $unzip_opts,
untar_opts => $untar_opts,
subdir => $caller_module_name,
creates => $creates,
unless => $unless,
Expand Down
15 changes: 11 additions & 4 deletions manifests/extract.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$environment = undef, #: environment variables.
$strip = undef, #: extract file with the --strip=X option. Only works with GNU tar.
$use_7zip = false, #: alternative to unzip command on Windows
$untar_opts = '', #: additional options to pass to tar.
$unzip_opts = '', #: additional options to pass the unzip command.
$subdir = $caller_module_name #: subdir per module in staging directory.
) {
Expand Down Expand Up @@ -79,21 +80,27 @@
$strip_opt = ''
}

if $untar_opts != '' {
$untar_opts_real = " ${untar_opts}"
} else {
$untar_opts_real = ''
}

case $name {
/.tar$/: {
$command = "tar xf ${source_path}${strip_opt}"
$command = "tar xf ${source_path}${strip_opt}${untar_opts_real}"
}

/(.tgz|.tar.gz)$/: {
if $::osfamily == 'Solaris' {
$command = "gunzip -dc < ${source_path} | tar xf - "
$command = "gunzip -dc < ${source_path} | tar xf - ${untar_opts_real}"
} else {
$command = "tar xzf ${source_path}${strip_opt}"
$command = "tar xzf ${source_path}${strip_opt}${untar_opts_real}"
}
}

/(.tbz2|.tar.bz2)$/: {
$command = "tar xjf ${source_path}${strip_opt}"
$command = "tar xjf ${source_path}${strip_opt}${untar_opts_real}"
}

/.zip$/: {
Expand Down
18 changes: 18 additions & 0 deletions spec/defines/staging_deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,23 @@
cwd: '/usr/local',
creates: '/usr/local/sample')
end

describe 'when deploying tar file with untar_opts' do
let(:title) { 'sample.tar' }
let(:params) do
{ source: 'puppet:///modules/staging/sample.tar',
target: '/usr/local',
untar_opts: '--exclude=conf/' }

end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file('/opt/staging') }
it { is_expected.to contain_file('/opt/staging/sample.tar') }
it do
is_expected.to contain_exec('extract sample.tar').with(command: 'tar xf /opt/staging/sample.tar --exclude=conf/',
path: '/usr/local/bin:/usr/bin:/bin',
cwd: '/usr/local',
creates: '/usr/local/sample')
end
end
end
19 changes: 19 additions & 0 deletions spec/defines/staging_extract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@
end
end

describe 'when deploying zip with untar_opts' do
let(:title) { 'sample.tar' }
let(:params) do
{
target: '/opt',
untar_opts: '--exclude=conf/'
}
end

it { is_expected.to compile.with_all_deps }
it do
is_expected.to contain_file('/opt/staging')
is_expected.to contain_exec('extract sample.tar').with(command: 'tar xf /opt/staging/sample.tar --exclude=conf/',
path: '/usr/local/bin:/usr/bin:/bin',
cwd: '/opt',
creates: '/opt/sample')
end
end

describe 'when deploying zip with strip (noop)' do
let(:title) { 'sample.zip' }
let(:params) do
Expand Down

0 comments on commit 65674d9

Please sign in to comment.