Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) add chmod and log-file options #90

Merged
merged 2 commits into from
May 26, 2017
Merged
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
8 changes: 4 additions & 4 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
fixtures:
forge_modules:
repositories:
xinetd:
repo: 'puppetlabs/xinetd'
repo: 'https://www.github.com/puppetlabs/puppetlabs-xinetd'
concat:
repo: 'puppetlabs/concat'
repo: 'https://www.github.com/puppetlabs/puppetlabs-concat'
stdlib:
repo: 'puppetlabs/stdlib'
repo: 'https://www.github.com/puppetlabs/puppetlabs-stdlib'
symlinks:
"rsync": "#{source_dir}"
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 @@ -127,7 +144,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
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"project_page": "https://github.com/puppetlabs/puppetlabs-rsync",
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
"dependencies": [
{"name":"puppetlabs/stdlib","version_requirement":">=4.2.0"},
{"name":"puppetlabs/stdlib","version_requirement":">=4.2.0 <5.0.0"},
{"name":"puppetlabs/xinetd","version_requirement":">=1.1.0"},
{"name":"puppetlabs/concat","version_requirement":">= 1.1.1"}
{"name":"puppetlabs/concat","version_requirement":">= 1.1.1 <5.0.0"}
]
}
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 example.com foobar',
'onlyif' => "test `rsync --dry-run --itemize-changes -a --chown=user:group example.com 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 example.com foobar',
'onlyif' => "test `rsync --dry-run --itemize-changes -a --chmod=Dg-s,u+w,go-w,+X,+x example.com 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 example.com foobar',
'onlyif' => "test `rsync --dry-run --itemize-changes -a --log-file=/tmp/logfile.out example.com foobar | wc -l` -gt 0"
})
}
end

end