-
Notifications
You must be signed in to change notification settings - Fork 39
/
master.pp
285 lines (253 loc) · 8.93 KB
/
master.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
285
class profile::jenkins::master {
include ::jenkins
include ::jenkins::master
include profile::jenkins::rosplugins
include profile::jenkins::agent
# This is a workaround for https://github.com/jenkinsci/puppet-jenkins/pull/821
# Creates a dependency thread from adding the jenkins source repository, updating apt repos,
# and installing the Jenkins package.
# This can get removed when that PR merges and we update to a release that includes it.
Apt::Source['jenkins'] -> Class['Apt::Update'] -> Package<|tag == $::jenkins::package_name|>
include jenkins_files
### Jenkins Plugins
# config for gitscm
file { '/tmp/configure_git_user.groovy':
source => 'puppet:///modules/profile/jenkins/master/configure_git_user.groovy',
} ->
rosjenkins::groovy { '/tmp/configure_git_user.groovy':
require => Jenkins::Plugin['git'],
}
# config for audit-trail
file { '/var/lib/jenkins/audit-trail.xml':
mode => '0640',
owner => jenkins,
group => jenkins,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/audit-trail.xml',
require => Jenkins::Plugin['audit-trail'],
notify => Service['jenkins'],
}
# config for collapsing-console-sections
file { '/var/lib/jenkins/org.jvnet.hudson.plugins.collapsingconsolesections.CollapsingSectionNote.xml':
mode => '0640',
owner => jenkins,
group => jenkins,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/org.jvnet.hudson.plugins.collapsingconsolesections.CollapsingSectionNote.xml',
require => Jenkins::Plugin['collapsing-console-sections'],
notify => Service['jenkins'],
}
# config for auto-managing github web hooks
file { '/var/lib/jenkins/com.cloudbees.jenkins.GitHubPushTrigger.xml':
ensure => 'present',
mode => '0600',
owner => 'jenkins',
group => 'jenkins',
content => template('jenkins_files/com.cloudbees.jenkins.GitHubPushTrigger.xml.erb'),
require => Package['jenkins'],
notify => Service['jenkins'],
}
# config for ghprb
file { '/var/lib/jenkins/org.jenkinsci.plugins.ghprb.GhprbTrigger.xml':
ensure => 'present',
mode => '0600',
owner => 'jenkins',
group => 'jenkins',
content => template('jenkins_files/org.jenkinsci.plugins.ghprb.GhprbTrigger.xml.erb'),
require => Package['jenkins'],
notify => Service['jenkins'],
}
# config for jobConfigHistory
file { '/var/lib/jenkins/jobConfigHistory.xml':
mode => '0640',
owner => jenkins,
group => jenkins,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/jobConfigHistory.xml',
require => Jenkins::Plugin['jobConfigHistory'],
notify => Service['jenkins'],
}
# config for PrioritySorter
file { '/var/lib/jenkins/jenkins.advancedqueue.PrioritySorterConfiguration.xml':
mode => '0640',
owner => jenkins,
group => jenkins,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/jenkins.advancedqueue.PrioritySorterConfiguration.xml',
require => Jenkins::Plugin['PrioritySorter'],
notify => Service['jenkins'],
}
# config for publish-over-ssh
file { '/var/lib/jenkins/jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin.xml':
mode => '0640',
owner => jenkins,
group => jenkins,
content => template('jenkins_files/jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin.xml.erb'),
require => Jenkins::Plugin['publish-over-ssh'],
notify => Service['jenkins'],
}
# config for subversion
file { '/var/lib/jenkins/hudson.scm.SubversionSCM.xml':
mode => '0640',
owner => jenkins,
group => jenkins,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/hudson.scm.SubversionSCM.xml',
require => Jenkins::Plugin['subversion'],
notify => Service['jenkins'],
}
# config for warnings
file { '/var/lib/jenkins/hudson.plugins.warnings.WarningsPublisher.xml':
mode => '0640',
owner => jenkins,
group => jenkins,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/hudson.plugins.warnings.WarningsPublisher.xml',
require => Jenkins::Plugin['warnings'],
notify => Service['jenkins'],
}
# make sure that the config.xml is present.
# It does not get generated initially see https://github.com/ros-infrastructure/buildfarm_deployment/issues/2
# This is too strong, if puppet is rerun it will override any changed configs
file { '/var/lib/jenkins/config.xml':
ensure => 'present',
mode => '0640',
owner => jenkins,
group => jenkins,
replace => false,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/config.xml',
require => Package['jenkins'],
notify => Service['jenkins'],
}
# Use default mercurial, but enable caching.
# Otherwise if the workspace is lost mercurial will trigger a job
# whenever it tries to poll.
file { '/var/lib/jenkins/hudson.plugins.mercurial.MercurialInstallation.xml':
ensure => 'present',
mode => '0640',
owner => jenkins,
group => jenkins,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/hudson.plugins.mercurial.MercurialInstallation.xml',
require => Package['jenkins'],
notify => Service['jenkins'],
}
file { '/var/lib/jenkins/nodeMonitors.xml':
ensure => 'present',
mode => '0640',
owner => jenkins,
group => jenkins,
content => template('jenkins_files/nodeMonitors.xml.erb'),
require => Package['jenkins'],
notify => Service['jenkins'],
}
file { '/var/lib/jenkins/scriptApproval.xml':
ensure => 'present',
mode => '0640',
owner => jenkins,
group => jenkins,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/scriptApproval.xml',
require => Package['jenkins'],
notify => Service['jenkins'],
}
$user_dirs = ['/var/lib/jenkins/users',
'/var/lib/jenkins/users/admin',
'/var/lib/jenkins/secrets',
'/var/lib/jenkins/secrets/filepath-filters.d',
]
file { $user_dirs:
ensure => 'directory',
mode => '0640',
owner => jenkins,
group => jenkins,
}
# enable slave -> master access control
file { '/var/lib/jenkins/secrets/slave-to-master-security-kill-switch':
ensure => 'present',
mode => '0640',
owner => jenkins,
group => jenkins,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/secrets/slave-to-master-security-kill-switch',
require => [Package['jenkins'],
File[$user_dirs],],
notify => Service['jenkins'],
}
# Give access to ssh_id to slaves
file { '/var/lib/jenkins/secrets/filepath-filters.d/60-ssh-id.conf':
ensure => 'present',
mode => '0640',
owner => jenkins,
group => jenkins,
source => 'puppet:///modules/jenkins_files/var/lib/jenkins/secrets/filepath-filters.d/60-ssh-id.conf',
require => [Package['jenkins'],
File[$user_dirs],],
notify => Service['jenkins'],
}
# Create an admin user:
file { '/var/lib/jenkins/users/admin/config.xml':
ensure => 'present',
mode => '0640',
owner => jenkins,
group => jenkins,
content => template('jenkins_files/user_config.xml.erb'),
require => [Package['jenkins'],
File[$user_dirs],],
notify => Service['jenkins'],
}
# For our convenience reading the logs
class { 'timezone':
timezone => hiera('timezone', 'America/Los_Angeles'),
}
# setup apache
class { 'apache':
default_vhost => false,
}
apache::vhost { 'master':
docroot => '/var/www.html',
port => '80',
proxy_pass => [
{ 'path' => '/', 'url' => 'http://localhost:8080/'},
],
}
# required by management jobs to read rosdistro yaml files
package { 'python3-yaml':
ensure => 'installed',
}
### install latest docker
include docker
# Add jenkins user to docker group if not already
# That this needs to be done with a command rather than a resource declaration is a side effect of the 'jenkins'
# user being managed by the jenkins module.
# If future alterations are necessary it may be worth managing the user ourselves.
exec {'jenkins docker membership':
unless => '/bin/bash -c "/usr/bin/id -nG jenkins | /bin/grep -wq docker"',
command => '/usr/sbin/usermod -aG docker jenkins',
require => [Class['docker'], User['jenkins']],
}
## Credentials necessary for 'Publish over SSH'
## Everything else uses the built in credentials
file { '/var/lib/jenkins/.ssh':
ensure => 'directory',
owner => 'jenkins',
group => 'jenkins',
mode => '0700',
require => User['jenkins'],
}
# add ssh key
file { '/var/lib/jenkins/.ssh/id_rsa':
mode => '0600',
owner => 'jenkins',
group => 'jenkins',
content => hiera('jenkins::private_ssh_key'),
require => File['/var/lib/jenkins/.ssh'],
}
# Reference above credentials
file { '/var/lib/jenkins/credentials.xml':
mode => '0600',
owner => 'jenkins',
group => 'jenkins',
content => template('jenkins_files/credentials.xml.erb'),
}
cron {'docker image prune':
command => 'docker image prune -f',
user => root,
month => absent,
monthday => absent,
hour => '0',
minute => '0',
weekday => absent,
}
}