Skip to content

Commit

Permalink
Add parameter descriptions and data types
Browse files Browse the repository at this point in the history
This fixes summary/parameter descriptions and also adds data types, to
address the all lint failures detected.

Co-Authored-By: Ewoud Kohl van Wijngaarden <[email protected]>
  • Loading branch information
ekohl authored and kajinamit committed Feb 15, 2024
1 parent f2a9f11 commit 48aa4a0
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 282 deletions.
176 changes: 84 additions & 92 deletions manifests/get.pp
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
# 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'
# $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)
# $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:
# @summary
# get files via rsync
#
# Requires:
# $source must be set
#
# Sample Usage:
# @param source
# source to copy from
# @param path
# path to copy to, defaults to $name
# @param user
# username on remote system
# @param purge
# if set, rsync will use '--delete'
# @param exclude
# Path or paths to be exclude
# @param include
# Path or paths to include
# @param exclude_first
# if 'true' (default) then first exclude and then include; the other way around if 'false'
# @param keyfile
# path to ssh key used to connect to remote host, defaults to /home/${user}/.ssh/id_rsa
# @param timeout
# timeout in seconds, defaults to 900
# @param options
# default options to pass to rsync (-a)
# @param chown
# ownership to pass to rsync (requires rsync 3.1.0+)
# @param chmod
# permissions to pass to rsync
# @param logfile
# logname to pass to rsync
# @param onlyif
# Condition to run the rsync command
#
# @example Sync from a source
# rsync::get { '/foo':
# source => "rsync://${rsyncServer}/repo/foo/",
# require => File['/foo'],
# } # rsync
# }
#
define rsync::get (
$source,
$path = $name,
$user = undef,
$purge = undef,
$recursive = undef,
$links = undef,
$hardlinks = undef,
$copylinks = undef,
$times = undef,
$include = undef,
$exclude = undef,
$exclude_first = true,
$keyfile = undef,
$timeout = '900',
$execuser = 'root',
$options = '-a',
$chown = undef,
$chmod = undef,
$logfile = undef,
$onlyif = undef,
String[1] $source,
String[1] $path = $name,
Optional[String[1]] $user = undef,
Boolean $purge = false,
Boolean $recursive = false,
Boolean $links = false,
Boolean $hardlinks = false,
Boolean $copylinks = false,
Boolean $times = false,
Variant[Array[String[1]], String[1]] $include = [],
Variant[Array[String[1]], String[1]] $exclude = [],
Boolean $exclude_first = true,
Optional[String[1]] $keyfile = undef,
Integer[0] $timeout = 900,
String[1] $execuser = 'root',
Array[String[1]] $options = ['-a'],
Optional[String[1]] $chown = undef,
Optional[String[1]] $chmod = undef,
Optional[String[1]] $logfile = undef,
Variant[Undef, String[1], Array[String[1]]] $onlyif = undef,
) {
if $keyfile {
$mykeyfile = $keyfile
Expand All @@ -60,100 +65,87 @@
}

if $user {
$myuser = "-e 'ssh -i ${mykeyfile} -l ${user}' ${user}@"
$myuseropt = ['-e', "'ssh -i ${mykeyfile} -l ${user}'"]
$myuser = "${user}@"
} else {
$myuser = undef
$myuseropt = []
$myuser = ''
}

if $purge {
$mypurge = '--delete'
} else {
$mypurge = undef
}

if $exclude {
$myexclude = join(prefix(flatten([$exclude]), '--exclude='), ' ')
$mypurge = ['--delete']
} else {
$myexclude = undef
$mypurge = []
}

if $include {
$myinclude = join(prefix(flatten([$include]), '--include='), ' ')
} else {
$myinclude = undef
}
$myexclude = prefix(any2array($exclude), '--exclude=')
$myinclude = prefix(any2array($include), '--include=')

if $recursive {
$myrecursive = '-r'
$myrecursive = ['-r']
} else {
$myrecursive = undef
$myrecursive = []
}

if $links {
$mylinks = '--links'
$mylinks = ['--links']
} else {
$mylinks = undef
$mylinks = []
}

if $hardlinks {
$myhardlinks = '--hard-links'
$myhardlinks = ['--hard-links']
} else {
$myhardlinks = undef
$myhardlinks = []
}

if $copylinks {
$mycopylinks = '--copy-links'
$mycopylinks = ['--copy-links']
} else {
$mycopylinks = undef
$mycopylinks = []
}

if $times {
$mytimes = '--times'
$mytimes = ['--times']
} else {
$mytimes = undef
$mytimes = []
}

if $chown {
$mychown = "--chown=${chown}"
$mychown = ["--chown=${chown}"]
} else {
$mychown = undef
$mychown = []
}

if $chmod {
$mychmod = "--chmod=${chmod}"
$mychmod = ["--chmod=${chmod}"]
} else {
$mychmod = undef
$mychmod = []
}

if $logfile {
$mylogfile = "--log-file=${logfile}"
$mylogfile = ["--log-file=${logfile}"]
} else {
$mylogfile = undef
$mylogfile = []
}

if $include or $exclude {
if $exclude_first {
$excludeandinclude = join(delete_undef_values([$myexclude, $myinclude]), ' ')
} else {
$excludeandinclude = join(delete_undef_values([$myinclude, $myexclude]), ' ')
}
if $exclude_first {
$excludeandinclude = $myexclude + $myinclude
} else {
$excludeandinclude = undef
$excludeandinclude = $myinclude + $myexclude
}

$rsync_options = join(
delete_undef_values([$options, $mypurge, $excludeandinclude, $mylinks, $myhardlinks, $mycopylinks, $mytimes,
$myrecursive, $mychown, $mychmod, $mylogfile, "${myuser}${source}", $path]), ' ')
$command = ['rsync' + '-q'] + $options + $mypurge + $excludeandinclude + $mylinks + $myhardlinks + $mycopylinks + $mytimes + $myrecursive + $mychown + $mychmod + $mylogfile + $myuseropt + ["${myuser}${source}", $path]

if !$onlyif {
$onlyif_real = "test `rsync --dry-run --itemize-changes ${rsync_options} | wc -l` -gt 0"
} else {
if $onlyif {
$onlyif_real = $onlyif
} else {
# TODO: add dry run to $command?
$onlyif_real = "test `rsync --dry-run --itemize-changes ${rsync_options} | wc -l` -gt 0"
}


exec { "rsync ${name}":
command => "rsync -q ${rsync_options}",
command => $command,
path => ['/bin', '/usr/bin', '/usr/local/bin'],
user => $execuser,
# perform a dry-run to determine if anything needs to be updated
Expand Down
19 changes: 13 additions & 6 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Class: rsync
# @summary manage rsync
#
# This module manages rsync
# @param package_ensure
# ensure state of the rsync package
# @param manage_package
# if true, manage the rsync package
# @param puts
# create rsync::puts defined type resources
# @param gets
# create rsync::gets defined type resources
#
class rsync (
$package_ensure = 'installed',
$manage_package = true,
$puts = {},
$gets = {},
String $package_ensure = 'installed',
Boolean $manage_package = true,
Hash $puts = {},
Hash $gets = {},
) {
if $manage_package {
package { 'rsync':
Expand Down
Loading

0 comments on commit 48aa4a0

Please sign in to comment.