From dd242530b8df2e844e7622a65692a30828be5d1a Mon Sep 17 00:00:00 2001 From: Lukas Bezdicka Date: Tue, 2 Dec 2014 18:31:32 +0100 Subject: [PATCH] Update rsync to e5198135a005cd397342957c3e7a0a564e367e33 e5198135a005cd397342957c3e7a0a564e367e33 Merge pull request #36 from Mylezeem/param_onlyif 9aa468d508e6b5f529f393ea4f7cc7a28b0a53f7 get: Parametrize the onlyif condition of the rsync command 3902c1ac705236b84c82bbe6ce6f3dd146c1548b Merge pull request #39 from apenney/031-release 76aeb5ac4018b5ccf8497fcfeeb15e44ba0b6cd8 Prepare 0.3.1 release. 4b9206d40a357b3fddf2385f883d09d16ba76547 Merge pull request #37 from notanisp/master 11b82e070946f3159054ba56db37a16c68ae4930 Fix variable name capitalization. 566366b6aefcc879185ccce115ba7cdd1eafe9d8 Merge pull request #38 from mhaskel/PR32-cleanup 58af256145ecaa6bd02cc47345ed8e04f7c55c7d Slight documentation and style updates. ed2b36d4d38e7705980474c61a9f2dd5995f805f Update init.pp e29faca873a3ab7573452edfd49700ab2eb738b7 Update README.markdown ccd1b1321a56b6bbd21644ccaf815adb68a628aa Update get.pp 9830d0f25111be77a7ae2adc49e23a72ab60723f Update init.pp 946d279fe5967815456058e1fd4321f84206dd7a Merge pull request #35 from mhaskel/0.3.0-prep d0707c4ae3674b63c2193c0012ceb9fa90ed41b6 Prepare 0.3.0 release. 4fdfefe4a627a31fb55381d1666c6c9aaeec7c9e Merge pull request #33 from stefanandres/uid_gid_as_variables 7a9bc9c3cda2952f8e165efaa52669a76e84d4c3 Implement rspec tests for uid/gid variables 596cd575a15819388867df0e2eec4ca9e45c4280 Implement uid/gid in header.erb as variables to be used in rsync::server ff6452216291e4ddabf1363f2fef25a33d529079 Merge pull request #24 from pall-valmundsson/rsync-put b01bc6079600231c86ead78f5bbae597c5e9f31f Add rsync::put usage to README f8e17e6c16e8ebcb0c5c9c289fc1014cededc6b7 Merge branch 'Aethylred-more_options' 951e80cf4699fe8b01e2254c33a78238d80ed865 Merge branch 'more_options' of github.com:Aethylred/puppetlabs-rsync into Aethylred-more_options fdf0f9621281e9703d420cf632f2c2f5d16e2d30 Merge pull request #30 from mckern/exclude_all_the_things 0592f1ff837ef3fbe5d02268b153020cec2358b6 Merge pull request #31 from HarryWeppner/master e89a3ff6f2af186560f97b2acc59fdb7d974e95b /usr/local/bin included in search path for rsync 5759c3acf704e8021b43aad237edc03f6039fd37 (maint) Remove use of str2bool 7cf04d1b6757c89b9109742623a10e1701240e0e Merge pull request #29 from mckern/exclude_all_the_things ba00e18e99685f948c02a43a84b4253e9c233cdd Clean up Debian patches 8633dc308c416d685b628e95cd2e99f528de1c64 Add Debian support (based on PR 22, by splebel) 8d8b04fa36bae3226d914c50bb0630209d452882 Fix missing newline-chomp in rsync::server::module template 818fe078da1b60bb54b9c0e037c41a5ae50b1707 Add 'exclude' as an option for rsync::server::module 86e475914260c150a22c3901558d1a3304359663 Merge pull request #28 from hogepodge/0.2.0 63fea0d2711791a99de3638fcd2af4f362e7598c 0.2.0 Release ad37382286622cc5b5ab1dfb7e229facc1d5c252 bugfix and tests added c962422eb17a530689d584d49d5bdff3ba0f1aeb Adding missing travis config, and rationalise extra spaces in commands and tests c18cc79d874e6f534a86cc39dbf109321c226ee3 Allow setting more rsync options 7122983d89bf68bc4170415cc03212f6a8a4636e Merge pull request #25 from blkperl/fix_puppet32x_dep 45e5d75fe223244471772f9757e92d9f9b2537ae Simplify module template logic 9e7f6c0ddd8090ebfa9f66814a5cf21f6a38c815 Add template uses comment ba468dcc31e921e22af2b4ccc6a51a5c89bd9eab Fix puppet 3.2.x deprecation warnings b67b4dd189fd6b3bb4e273458a21d3d11e1e2186 Merge pull request #23 from juanibiapina/execuser dc2a92a7980ea8f9e94aaba35260f3adb2f899f9 implement rsync::put, a reversal of rsync::get 1a7a0a6fc668b1f0193d91e8eb2c657104262254 Update README. cd7246ae0efe1e771152723dd28468839b86dea6 Add .rspec to gitignore. 5ba843eaf7dcb118a77648a2082f0e85aa8fe015 Add execuser param to run command as that user. 265eb9fc52742ad1f7a84e78149ac508295a2b8b Ruby 2.0.0-p195 compatibility changes. --- Puppetfile | 2 +- rsync/.gemfile | 5 - rsync/.gitignore | 3 +- rsync/.travis.yml | 28 +++++ rsync/CHANGELOG | 27 +++++ rsync/Gemfile | 8 ++ rsync/Modulefile | 9 -- rsync/README.markdown | 56 ++++++++-- rsync/files/defaults | 43 ++++++++ rsync/manifests/get.pp | 76 ++++++++++--- rsync/manifests/init.pp | 4 +- rsync/manifests/put.pp | 76 +++++++++++++ rsync/manifests/server.pp | 40 +++++-- rsync/manifests/server/module.pp | 1 + rsync/metadata.json | 24 +++++ rsync/spec/classes/server_spec.rb | 20 ++++ rsync/spec/defines/get_spec.rb | 131 ++++++++++++++++++++--- rsync/spec/defines/put_spec.rb | 117 ++++++++++++++++++++ rsync/spec/defines/server_module_spec.rb | 2 +- rsync/templates/header.erb | 12 ++- rsync/templates/module.erb | 49 +++++---- 21 files changed, 645 insertions(+), 88 deletions(-) delete mode 100644 rsync/.gemfile create mode 100644 rsync/.travis.yml create mode 100644 rsync/Gemfile delete mode 100644 rsync/Modulefile mode change 100644 => 100755 rsync/README.markdown create mode 100644 rsync/files/defaults mode change 100644 => 100755 rsync/manifests/get.pp mode change 100644 => 100755 rsync/manifests/init.pp create mode 100644 rsync/manifests/put.pp create mode 100644 rsync/metadata.json create mode 100644 rsync/spec/defines/put_spec.rb diff --git a/Puppetfile b/Puppetfile index 616ca5d91..c61208278 100644 --- a/Puppetfile +++ b/Puppetfile @@ -131,7 +131,7 @@ mod 'redis', :git => 'https://github.com/arioch/puppet-redis.git' mod 'rsync', - :commit => '357d51f3a6a22bc3da842736176c3510e507b4fb', + :commit => 'e5198135a005cd397342957c3e7a0a564e367e33', :git => 'https://github.com/puppetlabs/puppetlabs-rsync.git' mod 'sahara', diff --git a/rsync/.gemfile b/rsync/.gemfile deleted file mode 100644 index 9aad840c0..000000000 --- a/rsync/.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/rsync/.gitignore b/rsync/.gitignore index 2907100b3..7847ae4f8 100644 --- a/rsync/.gitignore +++ b/rsync/.gitignore @@ -1,2 +1,3 @@ -metadata.json pkg/ +Gemfile.lock +.rspec diff --git a/rsync/.travis.yml b/rsync/.travis.yml new file mode 100644 index 000000000..076adfd16 --- /dev/null +++ b/rsync/.travis.yml @@ -0,0 +1,28 @@ +--- +branches: + only: + - master +language: ruby +bundler_args: --without development +script: "bundle exec rake spec SPEC_OPTS='--format documentation'" + +rvm: + - 1.8.7 + - 1.9.3 + - 2.0.0 +env: + matrix: + - PUPPET_GEM_VERSION="~> 2.7.0" + - PUPPET_GEM_VERSION="~> 3.0" + - PUPPET_GEM_VERSION="~> 3.2.0" + +matrix: + exclude: + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 2.7.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 2.7.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 3.2.0" +notifications: + email: false diff --git a/rsync/CHANGELOG b/rsync/CHANGELOG index ec90e775c..9581dcdce 100644 --- a/rsync/CHANGELOG +++ b/rsync/CHANGELOG @@ -1,2 +1,29 @@ +2014-07-15 Release 0.3.1 + +Summary: + +This release merely updates metadata.json so the module can be uninstalled and +upgraded via the puppet module command. + +* 2014-06-18 0.3.0 +Features: +- Added rsync::put defined type. +- Added 'recursive', 'links', 'hardlinks', 'copylinks', 'times' and 'include' +parameters to rsync::get. +- Added 'uid' and 'gid' parameters to rsync::server +- Improved support for Debian +- Added 'exclude' parameter to rsync::server::module + +Fixes: +- Added /usr/local/bin to path for the rsync command exec. + + +* 2013-01-31 0.2.0 +- Added use_chroot parameter. +- Ensure rsync package is installed. +- Compatability changes for Ruby 2.0. +- Added execuser parameter to run command as specified user. +- Various typo and bug fixes. + * 2012-06-07 0.1.0 - Initial release diff --git a/rsync/Gemfile b/rsync/Gemfile new file mode 100644 index 000000000..265d3108f --- /dev/null +++ b/rsync/Gemfile @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gem 'puppetlabs_spec_helper' +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end diff --git a/rsync/Modulefile b/rsync/Modulefile deleted file mode 100644 index d00c916d4..000000000 --- a/rsync/Modulefile +++ /dev/null @@ -1,9 +0,0 @@ -name 'puppetlabs-rsync' -version '0.1.0' -source 'https://github.com/puppetlabs/puppetlabs-rsync' -author 'Puppet Labs' -license 'Apache License 2.0' -summary 'Puppet module to install and configure rsync' -project_page 'https://github.com/puppetlabs/puppetlabs-rsync' - -dependency 'puppetlabs/xinetd', '>= 1.1.0' diff --git a/rsync/README.markdown b/rsync/README.markdown old mode 100644 new mode 100755 index 9157db116..f6d1fb6f0 --- a/rsync/README.markdown +++ b/rsync/README.markdown @@ -3,30 +3,74 @@ puppetlabs-rsync manages rsync clients, repositories, and servers as well as providing defines to easily grab data via rsync. +# Class: rsync # + +Manage rsync package + +## Parameters: ## + $package_ensure - any of the valid values for the package resource: present, absent, purged, held, latest + +## Sample Usage: ## + class { 'rsync': package_ensure => 'latest' } + # Definition: rsync::get # 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' + $recursive - if set, rsync will use '-r' + $links - if set, rsync will use '--links' + $hardlinks - if set, rsync will use '--hard-links' + $copylinks - if set, rsync will use '--copy-links' + $times - if set, rsycn will use '--times' + $include - string to be included + $exclude - 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) + $chown - USER:GROUP simple username/groupname mapping + $onlyif - condition to run the rsync command + +## Actions: ## + get files via rsync + +## Requires: ## + $source must be set + +## Sample Usage: ## + # get file 'foo' via rsync + rsync::get { '/foo': + source => "rsync://${rsyncServer}/repo/foo/", + require => File['/foo'], + } + +# Definition: rsync::put # + +put 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 + $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 ## Actions: ## - get files via rsync + put files via rsync ## Requires: ## $source must be set ## Sample Usage: ## - # get file 'foo' via rsync - rsync::get { '/foo': - source => "rsync://${rsyncServer}/repo/foo/", - require => File['/foo'], + rsync::put { '${rsyncDestHost}:/repo/foo': + user => 'user', + source => "/repo/foo/", } # Definition: rsync::server::module # diff --git a/rsync/files/defaults b/rsync/files/defaults new file mode 100644 index 000000000..83b668e7b --- /dev/null +++ b/rsync/files/defaults @@ -0,0 +1,43 @@ +# Debian defaults file for rsync daemon mode. +#### This file is being maintained by Puppet. +#### DO NOT EDIT! + +# start rsync in daemon mode from init.d script? +# only allowed values are "true", "false", and "inetd" +# Use "inetd" if you want to start the rsyncd from inetd, +# all this does is prevent the init.d script from printing a message +# about not starting rsyncd (you still need to modify inetd's config yourself). +RSYNC_ENABLE=true + +# which file should be used as the configuration file for rsync. +# This file is used instead of the default /etc/rsyncd.conf +# Warning: This option has no effect if the daemon is accessed +# using a remote shell. When using a different file for +# rsync you might want to symlink /etc/rsyncd.conf to +# that file. +# RSYNC_CONFIG_FILE= + +# what extra options to give rsync --daemon? +# that excludes the --daemon; that's always done in the init.d script +# Possibilities are: +# --address=123.45.67.89 (bind to a specific IP address) +# --port=8730 (bind to specified port; default 873) +RSYNC_OPTS='' + +# run rsyncd at a nice level? +# the rsync daemon can impact performance due to much I/O and CPU usage, +# so you may want to run it at a nicer priority than the default priority. +# Allowed values are 0 - 19 inclusive; 10 is a reasonable value. +RSYNC_NICE='' + +# run rsyncd with ionice? +# "ionice" does for IO load what "nice" does for CPU load. +# As rsync is often used for backups which aren't all that time-critical, +# reducing the rsync IO priority will benefit the rest of the system. +# See the manpage for ionice for allowed options. +# -c3 is recommended, this will run rsync IO at "idle" priority. Uncomment +# the next line to activate this. +# RSYNC_IONICE='-c3' + +# Don't forget to create an appropriate config file, +# else the daemon will not start. diff --git a/rsync/manifests/get.pp b/rsync/manifests/get.pp old mode 100644 new mode 100755 index 1f3ff28be..d7c9723bb --- a/rsync/manifests/get.pp +++ b/rsync/manifests/get.pp @@ -10,6 +10,7 @@ # $exlude - string to be excluded # $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 +# $onlyif - Condition to run the rsync command # # Actions: # get files via rsync @@ -26,50 +27,91 @@ # define rsync::get ( $source, - $path = undef, - $user = undef, - $purge = undef, - $exclude = undef, - $keyfile = undef, - $timeout = '900' + $path = $name, + $user = undef, + $purge = undef, + $recursive = undef, + $links = undef, + $hardlinks = undef, + $copylinks = undef, + $times = undef, + $include = undef, + $exclude = undef, + $keyfile = undef, + $timeout = '900', + $execuser = 'root', + $chown = undef, + $onlyif = undef, ) { if $keyfile { - $Mykeyfile = $keyfile + $mykeyfile = $keyfile } else { - $Mykeyfile = "/home/${user}/.ssh/id_rsa" + $mykeyfile = "/home/${user}/.ssh/id_rsa" } if $user { - $MyUser = "-e 'ssh -i ${Mykeyfile} -l ${user}' ${user}@" + $myUser = "-e 'ssh -i ${mykeyfile} -l ${user}' ${user}@" } if $purge { - $MyPurge = '--delete' + $myPurge = ' --delete' } + # Not currently correct, there can be multiple --exclude arguments if $exclude { - $MyExclude = "--exclude=${exclude}" + $myExclude = " --exclude=${exclude}" } - if $path { - $MyPath = $path + # Not currently correct, there can be multiple --include arguments + if $include { + $myInclude = " --include=${include}" + } + + if $recursive { + $myRecursive = ' -r' + } + + if $links { + $myLinks = ' --links' + } + + if $hardlinks { + $myHardLinks = ' --hard-links' + } + + if $copylinks { + $myCopyLinks = ' --copy-links' + } + + if $times { + $myTimes = ' --times' + } + + if $chown { + $myChown = " --chown=${chown}" + } + + $rsync_options = "-a${myPurge}${myExclude}${myInclude}${myLinks}${myHardLinks}${myCopyLinks}${myTimes}${myRecursive}${myChown} ${myUser}${source} ${path}" + + if !$onlyif { + $onlyif_real = "test `rsync --dry-run --itemize-changes ${rsync_options} | wc -l` -gt 0" } else { - $MyPath = $name + $onlyif_real = $onlyif } - $rsync_options = "-a ${MyPurge} ${MyExclude} ${MyUser}${source} ${MyPath}" exec { "rsync ${name}": command => "rsync -q ${rsync_options}", - path => [ '/bin', '/usr/bin' ], + path => [ '/bin', '/usr/bin', '/usr/local/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 # TODO - it may make senes to do an actual run here (instead of a dry run) # and relace the command with an echo statement or something to ensure # that we only actually run rsync once - onlyif => "test `rsync --dry-run --itemize-changes ${rsync_options} | wc -l` -gt 0", + onlyif => $onlyif_real, timeout => $timeout, } } diff --git a/rsync/manifests/init.pp b/rsync/manifests/init.pp old mode 100644 new mode 100755 index 2f205c2fa..0b03f19ae --- a/rsync/manifests/init.pp +++ b/rsync/manifests/init.pp @@ -2,9 +2,9 @@ # # This module manages rsync # -class rsync { +class rsync($package_ensure = 'installed') { package { 'rsync': - ensure => installed, + ensure => $package_ensure, } -> Rsync::Get<| |> } diff --git a/rsync/manifests/put.pp b/rsync/manifests/put.pp new file mode 100644 index 000000000..7f3d461ef --- /dev/null +++ b/rsync/manifests/put.pp @@ -0,0 +1,76 @@ +# Definition: rsync::put +# +# put 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 - path to ssh key used to connect to remote host, defaults to /home/${user}/.ssh/id_rsa +# $timeout - timeout in seconds, defaults to 900 +# +# Actions: +# put files via rsync +# +# Requires: +# $source must be set +# +# Sample Usage: +# +# rsync::put { '${rsyncDestHost}:/repo/foo': +# user => 'user', +# source => "/repo/foo/", +# } # rsync +# +define rsync::put ( + $source, + $path = undef, + $user = undef, + $purge = undef, + $exclude = undef, + $keyfile = undef, + $timeout = '900' +) { + + if $keyfile { + $Mykeyfile = $keyfile + } else { + $Mykeyfile = "/home/${user}/.ssh/id_rsa" + } + + if $user { + $MyUserOpt = "-e 'ssh -i ${Mykeyfile} -l ${user}' " + $MyUser = "${user}@" + } + + if $purge { + $MyPurge = '--delete' + } + + if $exclude { + $MyExclude = "--exclude=${exclude}" + } + + if $path { + $MyPath = $path + } else { + $MyPath = $name + } + + $rsync_options = "-a ${MyPurge} ${MyExclude} ${MyUserOpt}${source} ${MyUser}${MyPath}" + + exec { "rsync ${name}": + command => "rsync -q ${rsync_options}", + path => [ '/bin', '/usr/bin' ], + # 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 + # TODO - it may make senes to do an actual run here (instead of a dry run) + # and relace the command with an echo statement or something to ensure + # that we only actually run rsync once + onlyif => "test `rsync --dry-run --itemize-changes ${rsync_options} | wc -l` -gt 0", + timeout => $timeout, + } +} diff --git a/rsync/manifests/server.pp b/rsync/manifests/server.pp index 9ce1cfef0..6a0496e4c 100644 --- a/rsync/manifests/server.pp +++ b/rsync/manifests/server.pp @@ -10,25 +10,41 @@ $use_xinetd = true, $address = '0.0.0.0', $motd_file = 'UNSET', - $use_chroot = 'yes' + $use_chroot = 'yes', + $uid = 'nobody', + $gid = 'nobody' ) inherits rsync { + $conf_file = $::osfamily ? { + 'Debian' => '/etc/rsyncd.conf', + default => '/etc/rsync.conf', + } + $rsync_fragments = '/etc/rsync.d' - if($use_xinetd) { + if $use_xinetd { include xinetd xinetd::service { 'rsync': bind => $address, port => '873', server => '/usr/bin/rsync', - server_args => '--daemon --config /etc/rsync.conf', + server_args => "--daemon --config ${conf_file}", require => Package['rsync'], } } else { service { 'rsync': - ensure => running, - enable => true, - subscribe => Exec['compile fragments'], + ensure => running, + enable => true, + hasstatus => true, + hasrestart => true, + subscribe => Exec['compile fragments'], + } + + if ( $::osfamily == 'Debian' ) { + file { '/etc/default/rsync': + source => 'puppet:///modules/rsync/defaults', + notify => Service['rsync'], + } } } @@ -42,18 +58,26 @@ ensure => directory, } + # Template uses: + # - $use_chroot + # - $address + # - $motd_file file { "${rsync_fragments}/header": content => template('rsync/header.erb'), } + file { $conf_file: + ensure => present, + } ~> Exec['compile fragments'] + # perhaps this should be a script # this allows you to only have a header and no fragments, which happens # by default if you have an rsync::server but not an rsync::repo on a host # which happens with cobbler systems by default exec { 'compile fragments': refreshonly => true, - command => "ls ${rsync_fragments}/frag-* 1>/dev/null 2>/dev/null && if [ $? -eq 0 ]; then cat ${rsync_fragments}/header ${rsync_fragments}/frag-* > /etc/rsync.conf; else cat ${rsync_fragments}/header > /etc/rsync.conf; fi; $(exit 0)", + command => "ls ${rsync_fragments}/frag-* 1>/dev/null 2>/dev/null && if [ $? -eq 0 ]; then cat ${rsync_fragments}/header ${rsync_fragments}/frag-* > ${conf_file}; else cat ${rsync_fragments}/header > ${conf_file}; fi; $(exit 0)", subscribe => File["${rsync_fragments}/header"], - path => '/bin:/usr/bin', + path => '/bin:/usr/bin:/usr/local/bin', } } diff --git a/rsync/manifests/server/module.pp b/rsync/manifests/server/module.pp index 241a55150..b7f0ded2b 100644 --- a/rsync/manifests/server/module.pp +++ b/rsync/manifests/server/module.pp @@ -45,6 +45,7 @@ $max_connections = '0', $lock_file = '/var/run/rsyncd.lock', $secrets_file = undef, + $exclude = undef, $auth_users = undef, $hosts_allow = undef, $hosts_deny = undef) { diff --git a/rsync/metadata.json b/rsync/metadata.json new file mode 100644 index 000000000..6d5e3a5dd --- /dev/null +++ b/rsync/metadata.json @@ -0,0 +1,24 @@ +{ + "name": "puppetlabs-rsync", + "version": "0.3.1", + "author": "puppetlabs", + "summary": "RSync puppet module", + "license": "Apache License, Version 2.0", + "source": "https://github.com/puppetlabs/puppetlabs-rsync", + "project_page": "https://github.com/puppetlabs/puppetlabs-rsync", + "issues_url": "https://github.com/puppetlabs/puppetlabs-rsync/issues", + "types": [ + + ], + "description": "Module to install and configure RSync", + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": ">=2.2.1" + }, + { + "name": "puppetlabs/xinetd", + "version_requirement": ">=1.1.0" + } + ] +} diff --git a/rsync/spec/classes/server_spec.rb b/rsync/spec/classes/server_spec.rb index a7b1105c3..2bbf7d712 100644 --- a/rsync/spec/classes/server_spec.rb +++ b/rsync/spec/classes/server_spec.rb @@ -58,4 +58,24 @@ } end + describe 'when overriding uid' do + let :params do + { :uid => 'testuser' } + end + + it { + should contain_file(fragment_file).with_content(/^uid\s*=\s*testuser$/) + } + end + + describe 'when overriding gid' do + let :params do + { :gid => 'testgroup' } + end + + it { + should contain_file(fragment_file).with_content(/^gid\s*=\s*testgroup$/) + } + end + end diff --git a/rsync/spec/defines/get_spec.rb b/rsync/spec/defines/get_spec.rb index 6e9681d01..5b5e51cdb 100644 --- a/rsync/spec/defines/get_spec.rb +++ b/rsync/spec/defines/get_spec.rb @@ -17,13 +17,22 @@ it { 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' + 'command' => 'rsync -q -a example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a example.com foobar | wc -l` -gt 0", + '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' } ) @@ -41,8 +50,8 @@ it { should contain_exec("rsync foobar").with({ - 'command' => 'rsync -q -a -e \'ssh -i /home/mr_baz/.ssh/id_rsa -l mr_baz\' mr_baz@example.com foobar', - 'onlyif' => "test `rsync --dry-run --itemize-changes -a -e \'ssh -i /home/mr_baz/.ssh/id_rsa -l mr_baz\' mr_baz@example.com foobar | wc -l` -gt 0", + 'command' => 'rsync -q -a -e \'ssh -i /home/mr_baz/.ssh/id_rsa -l mr_baz\' mr_baz@example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a -e \'ssh -i /home/mr_baz/.ssh/id_rsa -l mr_baz\' mr_baz@example.com foobar | wc -l` -gt 0", }) } end @@ -54,8 +63,8 @@ it { 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", + 'command' => 'rsync -q -a example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a example.com foobar | wc -l` -gt 0", }) } end @@ -70,8 +79,8 @@ it { should contain_exec("rsync foobar").with({ - 'command' => 'rsync -q -a -e \'ssh -i /path/to/keyfile -l mr_baz\' mr_baz@example.com foobar', - 'onlyif' => "test `rsync --dry-run --itemize-changes -a -e \'ssh -i /path/to/keyfile -l mr_baz\' mr_baz@example.com foobar | wc -l` -gt 0", + 'command' => 'rsync -q -a -e \'ssh -i /path/to/keyfile -l mr_baz\' mr_baz@example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a -e \'ssh -i /path/to/keyfile -l mr_baz\' mr_baz@example.com foobar | wc -l` -gt 0", }) } end @@ -83,8 +92,21 @@ it { should contain_exec("rsync foobar").with({ - 'command' => 'rsync -q -a --exclude=/path/to/exclude/ example.com foobar', - 'onlyif' => "test `rsync --dry-run --itemize-changes -a --exclude=/path/to/exclude/ example.com foobar | wc -l` -gt 0", + 'command' => 'rsync -q -a --exclude=/path/to/exclude/ example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a --exclude=/path/to/exclude/ example.com foobar | wc -l` -gt 0", + }) + } + end + + describe "when setting an include path" do + let :params do + common_params.merge({ :include => '/path/to/include/' }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a --include=/path/to/include/ example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a --include=/path/to/include/ example.com foobar | wc -l` -gt 0", }) } end @@ -96,8 +118,73 @@ it { should contain_exec("rsync foobar").with({ - 'command' => 'rsync -q -a --delete example.com foobar', - 'onlyif' => "test `rsync --dry-run --itemize-changes -a --delete example.com foobar | wc -l` -gt 0" + 'command' => 'rsync -q -a --delete example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a --delete example.com foobar | wc -l` -gt 0" + }) + } + end + + describe "when enabling recursive" do + let :params do + common_params.merge({ :recursive => true }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a -r example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a -r example.com foobar | wc -l` -gt 0" + }) + } + end + + describe "when enabling links" do + let :params do + common_params.merge({ :links => true }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a --links example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a --links example.com foobar | wc -l` -gt 0" + }) + } + end + + describe "when enabling hardlinks" do + let :params do + common_params.merge({ :hardlinks => true }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a --hard-links example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a --hard-links example.com foobar | wc -l` -gt 0" + }) + } + end + + describe "when enabling copylinks" do + let :params do + common_params.merge({ :copylinks => true }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a --copy-links example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a --copy-links example.com foobar | wc -l` -gt 0" + }) + } + end + + describe "when enabling times" do + let :params do + common_params.merge({ :times => true }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a --times example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a --times example.com foobar | wc -l` -gt 0" }) } end @@ -109,9 +196,23 @@ it { should contain_exec("rsync foobar").with({ - 'command' => 'rsync -q -a example.com barfoo', - 'onlyif' => "test `rsync --dry-run --itemize-changes -a example.com barfoo | wc -l` -gt 0" + 'command' => 'rsync -q -a example.com barfoo', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a example.com barfoo | wc -l` -gt 0" }) } end + + describe "when setting a custom onlyif condition" do + let :params do + common_params.merge({ :onlyif => 'false' }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a example.com foobar', + 'onlyif' => "false" + }) + } + end + end diff --git a/rsync/spec/defines/put_spec.rb b/rsync/spec/defines/put_spec.rb new file mode 100644 index 000000000..4c723d2c1 --- /dev/null +++ b/rsync/spec/defines/put_spec.rb @@ -0,0 +1,117 @@ +require 'spec_helper' +describe 'rsync::put', :type => :define do + let :title do + 'foobar' + end + + let :common_params do + { + :source => 'example.com' + } + end + + describe "when using default class paramaters" do + let :params do + common_params + end + + it { + 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' + }) + } + end + + describe "when setting the timeout" do + let :params do + common_params.merge( { :timeout => '200' } ) + end + + it { + should contain_exec("rsync foobar").with({ 'timeout' => '200' }) + } + end + + describe "when setting a user but not a keyfile" do + let :params do + common_params.merge({ :user => 'mr_baz' }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a -e \'ssh -i /home/mr_baz/.ssh/id_rsa -l mr_baz\' example.com mr_baz@foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a -e \'ssh -i /home/mr_baz/.ssh/id_rsa -l mr_baz\' example.com mr_baz@foobar | wc -l` -gt 0", + }) + } + end + + describe "when setting a keyfile but not a user" do + let :params do + common_params.merge( { :keyfile => "/path/to/keyfile" } ) + end + + it { + 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", + }) + } + end + + describe "when setting a user and a keyfile" do + let :params do + common_params.merge({ + :user => 'mr_baz', + :keyfile => '/path/to/keyfile' + }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a -e \'ssh -i /path/to/keyfile -l mr_baz\' example.com mr_baz@foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a -e \'ssh -i /path/to/keyfile -l mr_baz\' example.com mr_baz@foobar | wc -l` -gt 0", + }) + } + end + + describe "when setting an exclude path" do + let :params do + common_params.merge({ :exclude => '/path/to/exclude/' }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a --exclude=/path/to/exclude/ example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a --exclude=/path/to/exclude/ example.com foobar | wc -l` -gt 0", + }) + } + end + + describe "when enabling purge" do + let :params do + common_params.merge({ :purge => true }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a --delete example.com foobar', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a --delete example.com foobar | wc -l` -gt 0" + }) + } + end + + describe "when setting a custom path" do + let :params do + common_params.merge({ :path => 'barfoo' }) + end + + it { + should contain_exec("rsync foobar").with({ + 'command' => 'rsync -q -a example.com barfoo', + 'onlyif' => "test `rsync --dry-run --itemize-changes -a example.com barfoo | wc -l` -gt 0" + }) + } + end +end diff --git a/rsync/spec/defines/server_module_spec.rb b/rsync/spec/defines/server_module_spec.rb index 6df8054c1..ae2b23f50 100644 --- a/rsync/spec/defines/server_module_spec.rb +++ b/rsync/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 diff --git a/rsync/templates/header.erb b/rsync/templates/header.erb index 51e75269a..90688472f 100644 --- a/rsync/templates/header.erb +++ b/rsync/templates/header.erb @@ -2,11 +2,13 @@ # DO NOT EDIT pid file = /var/run/rsyncd.pid -uid = nobody -gid = nobody -use chroot = <%= use_chroot %> +uid = <%= @uid %> +gid = <%= @gid %> +use chroot = <%= @use_chroot %> log format = %t %a %m %f %b syslog facility = local3 timeout = 300 -address = <%= address %> -<% if motd_file != 'UNSET' %>motd file = <%= motd_file %><% end %> +address = <%= @address %> +<% if @motd_file != 'UNSET' -%> +motd file = <%= @motd_file %> +<% end -%> diff --git a/rsync/templates/module.erb b/rsync/templates/module.erb index 0ccc34c6a..bd6c2dd7b 100644 --- a/rsync/templates/module.erb +++ b/rsync/templates/module.erb @@ -1,21 +1,34 @@ # This file is being maintained by Puppet. # DO NOT EDIT -[ <%= name %> ] -path = <%= path %> -read only = <%= read_only %> -write only = <%= write_only %> -list = <%= list %> -uid = <%= uid %> -gid = <%= gid %> -incoming chmod = <%= incoming_chmod %> -outgoing chmod = <%= outgoing_chmod %> -max connections = <%= max_connections %> -<% if Integer(max_connections) > 0 %>lock file = <%= lock_file %><% end %> -<% if comment != :undef %>comment = <%= comment %><% end %> -<% if secrets_file != :undef %>secrets file = <%= secrets_file %><% end %> -<% if auth_users != :undef %>auth users = <%= auth_users.to_a.join(', ')%><% end %> -<% if hosts_allow != :undef %>hosts allow = <%= hosts_allow.to_a.join(' ')%><% end %> -<% if hosts_deny != :undef %>hosts deny = <%= hosts_deny.to_a.join(' ')%><% end %> - - +[ <%= @name %> ] +path = <%= @path %> +read only = <%= @read_only %> +write only = <%= @write_only %> +list = <%= @list %> +uid = <%= @uid %> +gid = <%= @gid %> +incoming chmod = <%= @incoming_chmod %> +outgoing chmod = <%= @outgoing_chmod %> +max connections = <%= @max_connections %> +<% if Integer(@max_connections) > 0 -%> +lock file = <%= @lock_file %> +<% end -%> +<% if @comment -%> +comment = <%= @comment %> +<% end -%> +<% if @secrets_file -%> +secrets file = <%= @secrets_file %> +<% end -%> +<% if @auth_users -%> +auth users = <%= @auth_users.to_a.join(', ')%> +<% end -%> +<% if @hosts_allow -%> +hosts allow = <%= @hosts_allow.to_a.join(' ')%> +<% end -%> +<% if @hosts_deny -%> +hosts deny = <%= @hosts_deny.to_a.join(' ')%> +<% end -%> +<% if @exclude -%> +exclude = <%= @exclude.to_a.join(' ')%> +<% end -%>