This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpuppetserver-bootstrap.pp
246 lines (218 loc) · 7 KB
/
puppetserver-bootstrap.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
# https://github.com/chrisongthb/puppetserver-bootstrap
# puppetserver-bootstrap
# configure a single node puppetserver
##############################
# adjust the installation and configuration
$configure_lvm = false # see below for details
$r10k_git_control_repo_url = 'git@myGitlabInstance.myDomain:myGitGroup/control-repo.git'
$git_ssh_hostkey_aliases = [ 'myGitlabInstance', 'myGitlabInstance.myDomain', '1.2.3.4', 'fe80::1:2:3:4' ]
$git_ssh_hostkey_string = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # see e.g. /etc/ssh/ssh_host_ecdsa_key.pub on myGitlabInstance
$git_ssh_hostkey_type = 'ecdsa-sha2-nistp256'
$puppetdb_postgres_version = '11'
$puppetserver_jvm_heap = '2g'
$puppetdb_jvm_heap = '2g'
##############################
# configure puppetserver
class { 'puppetserver':
before => Class['puppetdb'],
require => Class['lvm'],
config => {
'java_args' => {
'xms' => $puppetserver_jvm_heap,
'xmx' => $puppetserver_jvm_heap,
'tmpdir' => '/tmp/',
},
},
}
##############################
# configure hiera
class { 'hiera':
require => Class['puppetserver'],
eyaml => true,
hierarchy => [
'nodes/%{::clientcert}',
'locations/%{::domain}',
'common',
],
}
##############################
# configure puppetdb
file { '/etc/cron.allow':
ensure => file,
mode => '0644',
owner => 'root',
group => 'root',
}
file_line { 'cron.allow puppetdb':
ensure => present,
path => '/etc/cron.allow',
line => 'puppetdb',
before => Class['puppetdb'],
}
class { 'puppetdb':
require => Class['lvm'],
postgres_version => $puppetdb_postgres_version,
manage_package_repo => false, # do not touch apt sources
java_args => {
'-Xms' => $puppetdb_jvm_heap,
'-Xmx' => $puppetdb_jvm_heap,
},
}
# configure puppetdb on the same (local)host as puppetserver
class { 'puppetdb::master::config':
require => Class['lvm'],
}
##############################
# configure r10k webhook
file { '/root/.ssh':
ensure => 'directory',
mode => '0700',
group => 'root',
owner => 'root',
}
sshkey { 'git_host_key':
ensure => present,
host_aliases => $git_ssh_hostkey_aliases,
key => $git_ssh_hostkey_string,
type => $git_ssh_hostkey_type,
target => '/root/.ssh/known_hosts',
require => File['/root/.ssh'],
}
exec { 'generate_ssh_keypair':
onlyif => '! [ -f /root/.ssh/id_rsa -a -f /root/.ssh/id_rsa.pub ]',
command => 'ssh-keygen -q -t rsa -b 8192 -f /root/.ssh/id_rsa -N ""',
provider => 'shell',
}
# https://github.com/puppetlabs/r10k/blob/master/doc/dynamic-environments/configuration.mkd#postrun
class { 'r10k':
manage_modulepath => false,
postrun => ['/usr/local/sbin/puppet_flush_environment_cache', '$modifiedenvs' ],
sources => {
'puppet' => {
'remote' => $r10k_git_control_repo_url,
'basedir' => "/etc/puppetlabs/code/environments",
'prefix' => false,
},
},
}
puppet_authorization::rule { 'enable clearing environment cache':
path => '/etc/puppetlabs/puppetserver/conf.d/auth.conf',
match_request_path => '/puppet-admin-api/v1/environment-cache',
match_request_type => 'path',
match_request_method => 'delete',
allow => $::fqdn,
allow_unauthenticated => false,
sort_order => 200,
notify => Service['puppetserver'],
}
ini_setting { 'enable environment caching':
ensure => 'present',
path => '/etc/puppetlabs/puppet/puppet.conf',
section => 'master',
setting => 'environment_timeout',
value => 'unlimited',
notify => Service['puppetserver'],
}
ini_setting { 'store reports in puppetdb':
ensure => 'present',
path => '/etc/puppetlabs/puppet/puppet.conf',
section => 'master',
setting => 'reports',
value => 'puppetdb',
notify => Service['puppetserver'],
}
file { '/usr/local/sbin/puppet_flush_environment_cache':
ensure => file,
mode => '0755',
owner => 'root',
group => 'root',
content => '#!/usr/bin/env bash
# This file is managed by Puppet. Do not edit.
# https://www.example42.com/2017/03/27/environment_caching/
# https://github.com/example42/psick/blob/production/bin/puppet_flush_environment_cache.sh
# https://puppet.com/docs/puppetserver/latest/admin-api/v1/environment-cache.html
# https://puppet.com/docs/puppetserver/6.1/config_file_auth.html
hostcert="$(puppet config print hostcert)"
key="$(puppet config print hostprivkey)"
cacert="$(puppet config print cacert)"
ppserver="$(puppet config print server)"
if [ $# -eq 0 ]; then
puppet generate types
curl --cert ${hostcert} --key ${key} --cacert ${cacert} -X DELETE https://${ppserver}:8140/puppet-admin-api/v1/environment-cache
else
for environment in $*; do
puppet generate types --environment ${environment}
curl --cert ${hostcert} --key ${key} --cacert ${cacert} -X DELETE https://${ppserver}:8140/puppet-admin-api/v1/environment-cache?environment=${environment}
done
fi
',
}
class {'r10k::webhook':
user => 'root',
group => 'root',
}
class {'r10k::webhook::config':
generate_types => true,
use_mcollective => false,
bind_address => '::',
public_key_path => "/etc/puppetlabs/puppet/ssl/ca/signed/${::fqdn}.pem",
private_key_path => "/etc/puppetlabs/puppet/ssl/private_keys/${::fqdn}.pem",
}
##############################
# configure lvms
if $configure_lvm {
class { 'lvm':
volume_groups => {
'datavg' => {
physical_volumes => [ '/dev/sdb', ],
logical_volumes => {
'puppetcode' => {
'size' => '100G',
'fs_type' => 'ext4',
'mountpath' => '/var/puppetcode', # autorequire to mountpoints
'mountpath_require' => true,
},
'puppetdb' => {
'size' => '20G',
'fs_type' => 'ext4',
'mountpath' => '/var/puppetdb', # autorequire to mountpoints
'mountpath_require' => true,
},
},
},
},
}
##############################
# manage directories and links
file { '/var/puppetcode':
ensure => 'directory',
group => 'root',
owner => 'root',
mode => '0755',
}
file { '/var/puppetdb':
ensure => 'directory',
group => 'postgres',
owner => 'postfix',
mode => '0755',
}
file { '/etc/puppetlabs/code':
require => Package['puppetserver'],
ensure => 'link',
group => 'root',
owner => 'root',
target => '/var/puppetcode',
force => true, # replace existing directory with link
}
file { '/etc/puppetlabs/puppetdb/postgresql/':
require => Package['puppetserver'],
ensure => 'link',
group => 'root',
owner => 'root',
target => '/var/puppetdb',
force => true, # replace existing directory with link
}
}
else {
class { 'lvm': } # to satisfy dependencies
}