diff --git a/.gemfile b/.gemfile deleted file mode 100644 index 9aad840..0000000 --- a/.gemfile +++ /dev/null @@ -1,5 +0,0 @@ -source :rubygems - -puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7'] -gem 'puppet', puppetversion -gem 'puppetlabs_spec_helper', '>= 0.1.0' diff --git a/.gitignore b/.gitignore index 2907100..06c5b88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ metadata.json pkg/ +Gemfile.lock +.rspec diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..97475e3 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "https://rubygems.org" + +gem 'puppetlabs_spec_helper' +gem 'puppet' diff --git a/README.markdown b/README.markdown index 9157db1..f6678b5 100644 --- a/README.markdown +++ b/README.markdown @@ -8,13 +8,14 @@ providing defines to easily grab data via rsync. 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 to be excluded - $keyfile - ssh key used to connect to remote host - $timeout - timeout in seconds, defaults to 900 + $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 to be excluded + $keyfile - ssh key used to connect to remote host + $timeout - timeout in seconds, defaults to 900 + $execuser - user to run the command (passed to exec) ## Actions: ## get files via rsync diff --git a/manifests/get.pp b/manifests/get.pp index 1f3ff28..39766e4 100644 --- a/manifests/get.pp +++ b/manifests/get.pp @@ -31,7 +31,8 @@ $purge = undef, $exclude = undef, $keyfile = undef, - $timeout = '900' + $timeout = '900', + $execuser = 'root', ) { if $keyfile { @@ -63,6 +64,7 @@ exec { "rsync ${name}": command => "rsync -q ${rsync_options}", path => [ '/bin', '/usr/bin' ], + user => $execuser, # perform a dry-run to determine if anything needs to be updated # this ensures that we only actually create a Puppet event if something needs to # be updated diff --git a/spec/defines/get_spec.rb b/spec/defines/get_spec.rb index 6e9681d..0137df1 100644 --- a/spec/defines/get_spec.rb +++ b/spec/defines/get_spec.rb @@ -19,11 +19,20 @@ should contain_exec("rsync foobar").with({ 'command' => 'rsync -q -a example.com foobar', 'onlyif' => "test `rsync --dry-run --itemize-changes -a example.com foobar | wc -l` -gt 0", - 'timeout' => '900' + 'timeout' => '900', + 'user' => 'root' }) } end + describe "when setting the execuser" do + let :params do + common_params.merge( { :execuser => 'username' } ) + end + + it{ should contain_exec("rsync foobar").with({ 'user' => 'username' }) } + end + describe "when setting the timeout" do let :params do common_params.merge( { :timeout => '200' } ) diff --git a/spec/defines/server_module_spec.rb b/spec/defines/server_module_spec.rb index 6df8054..ae2b23f 100644 --- a/spec/defines/server_module_spec.rb +++ b/spec/defines/server_module_spec.rb @@ -64,7 +64,7 @@ let :params do mandatory_params.merge({ k => v }) end - it { should contain_file(fragment_file).with_content(/^#{k.to_s.gsub('_', ' ')}\s*=\s*#{v.to_a.join(' ')}$/)} + it { should contain_file(fragment_file).with_content(/^#{k.to_s.gsub('_', ' ')}\s*=\s*#{Array(v).join(' ')}$/)} end end