diff --git a/README.markdown b/README.markdown index 2d8cafa..93e5c7e 100644 --- a/README.markdown +++ b/README.markdown @@ -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: ## diff --git a/manifests/get.pp b/manifests/get.pp index fd02134..7494a6c 100644 --- a/manifests/get.pp +++ b/manifests/get.pp @@ -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 @@ -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, ) { @@ -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]), ' ') @@ -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" diff --git a/spec/defines/get_spec.rb b/spec/defines/get_spec.rb index 60067be..4eb7b59 100644 --- a/spec/defines/get_spec.rb +++ b/spec/defines/get_spec.rb @@ -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