-
Notifications
You must be signed in to change notification settings - Fork 566
/
slave.pp
284 lines (265 loc) · 8.67 KB
/
slave.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# == Class: jenkins::slave
#
# This module setups up a swarm client for a jenkins server. It requires the swarm plugin on the Jenkins master.
#
# https://wiki.jenkins-ci.org/display/JENKINS/Swarm+Plugin
#
# It allows users to add more workers to Jenkins without having to specifically add them on the Jenkins master.
#
# === Parameters
#
# [*slave_name*]
# Specify the name of the slave. Not required, by default it will use the fqdn.
#
# [*masterurl*]
# Specify the URL of the master server. Not required, the plugin will do a UDP autodiscovery. If specified, the autodiscovery will be skipped.
#
# [*autodiscoveryaddress*]
# Use this addresss for udp-based auto-discovery (default: 255.255.255.255)
#
# [*ui_user*] & [*ui_pass*]
# User name & password for the Jenkins UI. Not required, but may be ncessary for your config, depending on your security model.
#
# [*version*]
# The version of the swarm client code. Must match the pluging version on the master. Typically it's the latest available.
#
# [*executors*]
# Number of executors for this slave. (How many jenkins jobs can run simultaneously on this host.)
#
# [*manage_slave_user*]
# Should the class add a user to run the slave code? 1 is currently true
# TODO: should be updated to use boolean.
#
# [*slave_user*]
# Defaults to 'jenkins-slave'. Change it if you'd like..
#
# [*slave_uid*]
# Not required. Puppet will let your system add the user, with the new UID if necessary.
#
# [*slave_home*]
# Defaults to '/home/jenkins-slave'. This is where the code will be installed, and the workspace will end up.
#
# [*slave_mode*]
# Defaults to 'normal'. Can be either 'normal' (utilize this slave as much as possible) or 'exclusive' (leave this machine for tied jobs only).
#
# [*disable_ssl_verification*]
# Disable SSL certificate verification on Swarm clients. Not required, but is necessary if you're using a self-signed SSL cert. Defaults to false.
#
# [*labels*]
# Not required. Single string of whitespace-separated list of labels to be assigned for this slave.
#
# [*tool_locations*]
# Not required. Single string of whitespace-separated list of tool locations to be defined on this slave. A tool location is specified as 'toolName:location'.
#
# [*java_version*]
# Specified which version of java will be used.
#
# [*description*]
# Not required. Description which will appear on the jenkins master UI.
#
# [*manage_client_jar*]
# Should the class download the client jar file from the web? Defaults to true.
#
# [*ensure*]
# Service ensure control for jenkins-slave service. Default running
#
# [*enable*]
# Service enable control for jenkins-slave service. Default true.
#
# [*source*]
# File source for jenkins slave jar. Default pulls from http://maven.jenkins-ci.org
#
# [*java_args*]
# Java arguments to add to slave command line. Allows configuration of heap, etc.
#
# === Examples
#
# class { 'jenkins::slave':
# masterurl => 'http://jenkins-master1.example.com:8080',
# ui_user => 'adminuser',
# ui_pass => 'adminpass',
# }
#
# === Authors
#
# Matthew Barr <[email protected]>
#
# === Copyright
#
# Copyright 2013 Matthew Barr , but can be used for anything by anyone..
class jenkins::slave (
$slave_name = undef,
$description = undef,
$masterurl = undef,
$autodiscoveryaddress = undef,
$ui_user = undef,
$ui_pass = undef,
$version = $jenkins::params::swarm_version,
$executors = 2,
$manage_slave_user = true,
$slave_user = 'jenkins-slave',
$slave_uid = undef,
$slave_home = '/home/jenkins-slave',
$slave_mode = 'normal',
$disable_ssl_verification = false,
$labels = undef,
$tool_locations = undef,
$install_java = $jenkins::params::install_java,
$manage_client_jar = true,
$ensure = 'running',
$enable = true,
$source = undef,
$java_args = undef,
) inherits jenkins::params {
validate_string($slave_name)
validate_string($description)
validate_string($masterurl)
validate_string($autodiscoveryaddress)
validate_string($ui_user)
validate_string($ui_pass)
validate_string($version)
validate_integer($executors)
validate_bool($manage_slave_user)
validate_string($slave_user)
if $slave_uid { validate_integer($slave_uid) }
validate_absolute_path($slave_home)
validate_re($slave_mode, '^normal$|^exclusive$')
validate_bool($disable_ssl_verification)
validate_string($labels)
validate_string($tool_locations)
validate_bool($install_java)
validate_bool($manage_client_jar)
validate_re($ensure, '^running$|^stopped$')
validate_bool($enable)
validate_string($source)
validate_string($java_args)
$client_jar = "swarm-client-${version}-jar-with-dependencies.jar"
$client_url = $source ? {
undef => "http://maven.jenkins-ci.org/content/repositories/releases/org/jenkins-ci/plugins/swarm-client/${version}/",
default => $source,
}
$quoted_ui_user = shellquote($ui_user)
$quoted_ui_pass = shellquote($ui_pass)
if $install_java and ($::osfamily != 'Darwin') {
# Currently the puppetlabs/java module doesn't support installing Java on
# Darwin
class { 'java':
distribution => 'jdk',
}
}
# customizations based on the OS family
case $::osfamily {
'Debian': {
$defaults_location = '/etc/default'
ensure_packages(['daemon'])
Package['daemon'] -> Service['jenkins-slave']
}
'Darwin': {
$defaults_location = $slave_home
}
default: {
$defaults_location = '/etc/sysconfig'
}
}
case $::kernel {
'Linux': {
$service_name = 'jenkins-slave'
$defaults_user = 'root'
$defaults_group = 'root'
$manage_user_home = true
file { '/etc/init.d/jenkins-slave':
ensure => 'file',
mode => '0755',
owner => 'root',
group => 'root',
source => "puppet:///modules/${module_name}/jenkins-slave.${::osfamily}",
notify => Service['jenkins-slave'],
}
}
'Darwin': {
$service_name = 'org.jenkins-ci.slave.jnlp'
$defaults_user = 'jenkins'
$defaults_group = 'wheel'
$manage_user_home = false
file { "${slave_home}/start-slave.sh":
ensure => 'file',
content => template("${module_name}/start-slave.sh.erb"),
mode => '0755',
owner => 'root',
group => 'wheel',
}
file { '/Library/LaunchDaemons/org.jenkins-ci.slave.jnlp.plist':
ensure => 'file',
content => template("${module_name}/org.jenkins-ci.slave.jnlp.plist.erb"),
mode => '0644',
owner => 'root',
group => 'wheel',
}
file { '/var/log/jenkins':
ensure => 'directory',
owner => $slave_user,
}
if $manage_slave_user {
# osx doesn't have managehome support, so create directory
file { $slave_home:
ensure => directory,
mode => '0755',
owner => $slave_user,
require => User['jenkins-slave_user'],
}
}
File['/var/log/jenkins'] ->
File['/Library/LaunchDaemons/org.jenkins-ci.slave.jnlp.plist'] ->
Service['jenkins-slave']
}
default: { }
}
#a Add jenkins slave user if necessary.
if $manage_slave_user {
user { 'jenkins-slave_user':
ensure => present,
name => $slave_user,
comment => 'Jenkins Slave user',
home => $slave_home,
managehome => $manage_user_home,
system => true,
uid => $slave_uid,
}
}
file { "${defaults_location}/jenkins-slave":
ensure => 'file',
mode => '0600',
owner => $defaults_user,
group => $defaults_group,
content => template("${module_name}/jenkins-slave-defaults.erb"),
notify => Service['jenkins-slave'],
}
if ($manage_client_jar) {
archive { 'get_swarm_client':
source => "${client_url}/${client_jar}",
path => "${slave_home}/${client_jar}",
proxy_server => $::jenkins::proxy_server,
cleanup => false,
extract => false,
}
}
service { 'jenkins-slave':
ensure => $ensure,
name => $service_name,
enable => $enable,
hasstatus => true,
hasrestart => true,
}
if ($manage_client_jar) {
Archive['get_swarm_client'] ->
Service['jenkins-slave']
}
if $manage_slave_user and $manage_client_jar {
User['jenkins-slave_user']->
Archive['get_swarm_client']
}
if $install_java and ($::osfamily != 'Darwin') {
Class['java'] ->
Service['jenkins-slave']
}
}