Skip to content

Commit b67b4dd

Browse files
author
Ashley Penney
committed
Merge pull request #23 from juanibiapina/execuser
Add execuser param to run exec as that user
2 parents 357d51f + 1a7a0a6 commit b67b4dd

File tree

7 files changed

+28
-15
lines changed

7 files changed

+28
-15
lines changed

.gemfile

Lines changed: 0 additions & 5 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
metadata.json
22
pkg/
3+
Gemfile.lock
4+
.rspec

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source "https://rubygems.org"
2+
3+
gem 'puppetlabs_spec_helper'
4+
gem 'puppet'

README.markdown

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ providing defines to easily grab data via rsync.
88
get files via rsync
99

1010
## Parameters: ##
11-
$source - source to copy from
12-
$path - path to copy to, defaults to $name
13-
$user - username on remote system
14-
$purge - if set, rsync will use '--delete'
15-
$exlude - string to be excluded
16-
$keyfile - ssh key used to connect to remote host
17-
$timeout - timeout in seconds, defaults to 900
11+
$source - source to copy from
12+
$path - path to copy to, defaults to $name
13+
$user - username on remote system
14+
$purge - if set, rsync will use '--delete'
15+
$exlude - string to be excluded
16+
$keyfile - ssh key used to connect to remote host
17+
$timeout - timeout in seconds, defaults to 900
18+
$execuser - user to run the command (passed to exec)
1819

1920
## Actions: ##
2021
get files via rsync

manifests/get.pp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
$purge = undef,
3232
$exclude = undef,
3333
$keyfile = undef,
34-
$timeout = '900'
34+
$timeout = '900',
35+
$execuser = 'root',
3536
) {
3637

3738
if $keyfile {
@@ -63,6 +64,7 @@
6364
exec { "rsync ${name}":
6465
command => "rsync -q ${rsync_options}",
6566
path => [ '/bin', '/usr/bin' ],
67+
user => $execuser,
6668
# perform a dry-run to determine if anything needs to be updated
6769
# this ensures that we only actually create a Puppet event if something needs to
6870
# be updated

spec/defines/get_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,20 @@
1919
should contain_exec("rsync foobar").with({
2020
'command' => 'rsync -q -a example.com foobar',
2121
'onlyif' => "test `rsync --dry-run --itemize-changes -a example.com foobar | wc -l` -gt 0",
22-
'timeout' => '900'
22+
'timeout' => '900',
23+
'user' => 'root'
2324
})
2425
}
2526
end
2627

28+
describe "when setting the execuser" do
29+
let :params do
30+
common_params.merge( { :execuser => 'username' } )
31+
end
32+
33+
it{ should contain_exec("rsync foobar").with({ 'user' => 'username' }) }
34+
end
35+
2736
describe "when setting the timeout" do
2837
let :params do
2938
common_params.merge( { :timeout => '200' } )

spec/defines/server_module_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
let :params do
6565
mandatory_params.merge({ k => v })
6666
end
67-
it { should contain_file(fragment_file).with_content(/^#{k.to_s.gsub('_', ' ')}\s*=\s*#{v.to_a.join(' ')}$/)}
67+
it { should contain_file(fragment_file).with_content(/^#{k.to_s.gsub('_', ' ')}\s*=\s*#{Array(v).join(' ')}$/)}
6868
end
6969
end
7070

0 commit comments

Comments
 (0)