Skip to content

Commit 8c60157

Browse files
ekohlkajinamit
authored andcommitted
Add parameter descriptions and data types
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]>
1 parent f2a9f11 commit 8c60157

File tree

10 files changed

+309
-283
lines changed

10 files changed

+309
-283
lines changed

manifests/get.pp

Lines changed: 84 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,62 @@
1-
# Definition: rsync::get
2-
#
3-
# get files via rsync
4-
#
5-
# Parameters:
6-
# $source - source to copy from
7-
# $path - path to copy to, defaults to $name
8-
# $user - username on remote system
9-
# $purge - if set, rsync will use '--delete'
10-
# $exlude - string (or array) to be excluded
11-
# $include - string (or array) to be included
12-
# $exclude_first - if 'true' (default) then first exclude and then include; the other way around if 'false'
13-
# $keyfile - path to ssh key used to connect to remote host, defaults to /home/${user}/.ssh/id_rsa
14-
# $timeout - timeout in seconds, defaults to 900
15-
# $options - default options to pass to rsync (-a)
16-
# $chown - ownership to pass to rsync (optional; requires rsync 3.1.0+)
17-
# $chmod - permissions to pass to rsync (optional)
18-
# $logfile - logname to pass to rsync (optional)
19-
# $onlyif - Condition to run the rsync command
20-
#
21-
# Actions:
1+
# @summary
222
# get files via rsync
233
#
24-
# Requires:
25-
# $source must be set
26-
#
27-
# Sample Usage:
4+
# @param source
5+
# source to copy from
6+
# @param path
7+
# path to copy to, defaults to $name
8+
# @param user
9+
# username on remote system
10+
# @param purge
11+
# if set, rsync will use '--delete'
12+
# @param exclude
13+
# Path or paths to be exclude
14+
# @param include
15+
# Path or paths to include
16+
# @param exclude_first
17+
# if 'true' (default) then first exclude and then include; the other way around if 'false'
18+
# @param keyfile
19+
# path to ssh key used to connect to remote host, defaults to /home/${user}/.ssh/id_rsa
20+
# @param timeout
21+
# timeout in seconds, defaults to 900
22+
# @param options
23+
# default options to pass to rsync (-a)
24+
# @param chown
25+
# ownership to pass to rsync (requires rsync 3.1.0+)
26+
# @param chmod
27+
# permissions to pass to rsync
28+
# @param logfile
29+
# logname to pass to rsync
30+
# @param onlyif
31+
# Condition to run the rsync command
2832
#
33+
# @example Sync from a source
2934
# rsync::get { '/foo':
3035
# source => "rsync://${rsyncServer}/repo/foo/",
3136
# require => File['/foo'],
32-
# } # rsync
37+
# }
3338
#
3439
define rsync::get (
35-
$source,
36-
$path = $name,
37-
$user = undef,
38-
$purge = undef,
39-
$recursive = undef,
40-
$links = undef,
41-
$hardlinks = undef,
42-
$copylinks = undef,
43-
$times = undef,
44-
$include = undef,
45-
$exclude = undef,
46-
$exclude_first = true,
47-
$keyfile = undef,
48-
$timeout = '900',
49-
$execuser = 'root',
50-
$options = '-a',
51-
$chown = undef,
52-
$chmod = undef,
53-
$logfile = undef,
54-
$onlyif = undef,
40+
String[1] $source,
41+
String[1] $path = $name,
42+
Optional[String[1]] $user = undef,
43+
Boolean $purge = false,
44+
Boolean $recursive = false,
45+
Boolean $links = false,
46+
Boolean $hardlinks = false,
47+
Boolean $copylinks = false,
48+
Boolean $times = false,
49+
Variant[Array[String[1]], String[1]] $include = [],
50+
Variant[Array[String[1]], String[1]] $exclude = [],
51+
Boolean $exclude_first = true,
52+
Optional[String[1]] $keyfile = undef,
53+
Integer[0] $timeout = 900,
54+
String[1] $execuser = 'root',
55+
Array[String[1]] $options = ['-a'],
56+
Optional[String[1]] $chown = undef,
57+
Optional[String[1]] $chmod = undef,
58+
Optional[String[1]] $logfile = undef,
59+
Variant[Undef, String[1], Array[String[1]]] $onlyif = undef,
5560
) {
5661
if $keyfile {
5762
$mykeyfile = $keyfile
@@ -60,100 +65,87 @@
6065
}
6166

6267
if $user {
63-
$myuser = "-e 'ssh -i ${mykeyfile} -l ${user}' ${user}@"
68+
$myuseropt = ['-e', "'ssh -i ${mykeyfile} -l ${user}'"]
69+
$myuser = "${user}@"
6470
} else {
65-
$myuser = undef
71+
$myuseropt = []
72+
$myuser = ''
6673
}
6774

6875
if $purge {
69-
$mypurge = '--delete'
70-
} else {
71-
$mypurge = undef
72-
}
73-
74-
if $exclude {
75-
$myexclude = join(prefix(flatten([$exclude]), '--exclude='), ' ')
76+
$mypurge = ['--delete']
7677
} else {
77-
$myexclude = undef
78+
$mypurge = []
7879
}
7980

80-
if $include {
81-
$myinclude = join(prefix(flatten([$include]), '--include='), ' ')
82-
} else {
83-
$myinclude = undef
84-
}
81+
$myexclude = prefix(any2array($exclude), '--exclude=')
82+
$myinclude = prefix(any2array($include), '--include=')
8583

8684
if $recursive {
87-
$myrecursive = '-r'
85+
$myrecursive = ['-r']
8886
} else {
89-
$myrecursive = undef
87+
$myrecursive = []
9088
}
9189

9290
if $links {
93-
$mylinks = '--links'
91+
$mylinks = ['--links']
9492
} else {
95-
$mylinks = undef
93+
$mylinks = []
9694
}
9795

9896
if $hardlinks {
99-
$myhardlinks = '--hard-links'
97+
$myhardlinks = ['--hard-links']
10098
} else {
101-
$myhardlinks = undef
99+
$myhardlinks = []
102100
}
103101

104102
if $copylinks {
105-
$mycopylinks = '--copy-links'
103+
$mycopylinks = ['--copy-links']
106104
} else {
107-
$mycopylinks = undef
105+
$mycopylinks = []
108106
}
109107

110108
if $times {
111-
$mytimes = '--times'
109+
$mytimes = ['--times']
112110
} else {
113-
$mytimes = undef
111+
$mytimes = []
114112
}
115113

116114
if $chown {
117-
$mychown = "--chown=${chown}"
115+
$mychown = ["--chown=${chown}"]
118116
} else {
119-
$mychown = undef
117+
$mychown = []
120118
}
121119

122120
if $chmod {
123-
$mychmod = "--chmod=${chmod}"
121+
$mychmod = ["--chmod=${chmod}"]
124122
} else {
125-
$mychmod = undef
123+
$mychmod = []
126124
}
127125

128126
if $logfile {
129-
$mylogfile = "--log-file=${logfile}"
127+
$mylogfile = ["--log-file=${logfile}"]
130128
} else {
131-
$mylogfile = undef
129+
$mylogfile = []
132130
}
133131

134-
if $include or $exclude {
135-
if $exclude_first {
136-
$excludeandinclude = join(delete_undef_values([$myexclude, $myinclude]), ' ')
137-
} else {
138-
$excludeandinclude = join(delete_undef_values([$myinclude, $myexclude]), ' ')
139-
}
132+
if $exclude_first {
133+
$excludeandinclude = $myexclude + $myinclude
140134
} else {
141-
$excludeandinclude = undef
135+
$excludeandinclude = $myinclude + $myexclude
142136
}
143137

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

148-
if !$onlyif {
149-
$onlyif_real = "test `rsync --dry-run --itemize-changes ${rsync_options} | wc -l` -gt 0"
150-
} else {
140+
if $onlyif {
151141
$onlyif_real = $onlyif
142+
} else {
143+
# TODO: add dry run to $command?
144+
$onlyif_real = "test `rsync --dry-run --itemize-changes ${rsync_options} | wc -l` -gt 0"
152145
}
153146

154-
155147
exec { "rsync ${name}":
156-
command => "rsync -q ${rsync_options}",
148+
command => $command,
157149
path => ['/bin', '/usr/bin', '/usr/local/bin'],
158150
user => $execuser,
159151
# perform a dry-run to determine if anything needs to be updated

manifests/init.pp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
# Class: rsync
1+
# @summary manage rsync
22
#
3-
# This module manages rsync
3+
# @param package_ensure
4+
# ensure state of the rsync package
5+
# @param manage_package
6+
# if true, manage the rsync package
7+
# @param puts
8+
# create rsync::puts defined type resources
9+
# @param gets
10+
# create rsync::gets defined type resources
411
#
512
class rsync (
6-
$package_ensure = 'installed',
7-
$manage_package = true,
8-
$puts = {},
9-
$gets = {},
13+
String $package_ensure = 'installed',
14+
Boolean $manage_package = true,
15+
Hash $puts = {},
16+
Hash $gets = {},
1017
) {
1118
if $manage_package {
1219
package { 'rsync':

0 commit comments

Comments
 (0)