Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ get files via rsync
$execuser - user to run the command (passed to exec)
$options - default options to pass to rsync (-a)
$chown - USER:GROUP simple username/groupname mapping
$chmod - file and/or directory permissions
$logfile - log file name
$onlyif - condition to run the rsync command

## Actions: ##
Expand Down
41 changes: 29 additions & 12 deletions manifests/get.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
# get files via rsync
#
# Parameters:
# $source - source to copy from
# $path - path to copy to, defaults to $name
# $user - username on remote system
# $purge - if set, rsync will use '--delete'
# $exlude - string (or array) to be excluded
# $include - string (or array) to be included
# $source - source to copy from
# $path - path to copy to, defaults to $name
# $user - username on remote system
# $purge - if set, rsync will use '--delete'
# $exlude - string (or array) to be excluded
# $include - string (or array) to be included
# $exclude_first - if 'true' (default) then first exclude and then include; the other way around if 'false'
# $keyfile - path to ssh key used to connect to remote host, defaults to /home/${user}/.ssh/id_rsa
# $timeout - timeout in seconds, defaults to 900
# $options - default options to pass to rsync (-a)
# $onlyif - Condition to run the rsync command
# $keyfile - path to ssh key used to connect to remote host, defaults to /home/${user}/.ssh/id_rsa
# $timeout - timeout in seconds, defaults to 900
# $options - default options to pass to rsync (-a)
# $chown - ownership to pass to rsync (optional; requires rsync 3.1.0+)
# $chmod - permissions to pass to rsync (optional)
# $logfile - logname to pass to rsync (optional)
# $onlyif - Condition to run the rsync command
#
# Actions:
# get files via rsync
Expand All @@ -38,14 +41,16 @@
$hardlinks = undef,
$copylinks = undef,
$times = undef,
$exclude = undef,
$include = undef,
$exclude = undef,
$exclude_first = true,
$keyfile = undef,
$timeout = '900',
$execuser = 'root',
$options = '-a',
$chown = undef,
$chmod = undef,
$logfile = undef,
$onlyif = undef,
) {

Expand Down Expand Up @@ -115,6 +120,18 @@
$myChown = undef
}

if $chmod {
$mychmod = "--chmod=${chmod}"
} else {
$mychmod = undef
}

if $logfile {
$mylogfile = "--log-file=${logfile}"
} else {
$mylogfile = undef
}

if $include or $exclude {
if $exclude_first {
$excludeAndInclude = join(delete_undef_values([$myExclude, $myInclude]), ' ')
Expand All @@ -125,7 +142,7 @@

$rsync_options = join(
delete_undef_values([$options, $myPurge, $excludeAndInclude, $myLinks, $myHardLinks, $myCopyLinks, $myTimes,
$myRecursive, $myChown, "${myUser}${source}", $path]), ' ')
$myRecursive, $myChown, $mychmod, $mylogfile, "${myUser}${source}", $path]), ' ')

if !$onlyif {
$onlyif_real = "test `rsync --dry-run --itemize-changes ${rsync_options} | wc -l` -gt 0"
Expand Down
39 changes: 39 additions & 0 deletions spec/defines/get_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,43 @@
}
end

describe "when setting chown" do
let :params do
common_params.merge({ :chown => 'user:group' })
end

it {
is_expected.to contain_exec("rsync foobar").with({
'command' => 'rsync -q -a --chown=user:group foobar',
'onlyif' => "test `rsync --dry-run --itemize-changes -a --chown=user:group foobar | wc -l` -gt 0"
})
}
end

describe "when setting chmod" do
let :params do
common_params.merge({ :chmod => 'Dg-s,u+w,go-w,+X,+x' })
end

it {
is_expected.to contain_exec("rsync foobar").with({
'command' => 'rsync -q -a --chmod=Dg-s,u+w,go-w,+X,+x foobar',
'onlyif' => "test `rsync --dry-run --itemize-changes -a --chmod=Dg-s,u+w,go-w,+X,+x foobar | wc -l` -gt 0"
})
}
end

describe "when setting logfile" do
let :params do
common_params.merge({ :logfile => '/tmp/logfile.out' })
end

it {
is_expected.to contain_exec("rsync foobar").with({
'command' => 'rsync -q -a --log-file=/tmp/logfile.out foobar',
'onlyif' => "test `rsync --dry-run --itemize-changes -a --log-file=/tmp/logfile.out foobar | wc -l` -gt 0"
})
}
end

end