blob: 489856c2744cd39972d24956a8909d42005b3552 (
plain)
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
|
---
- name: generate hawkular-metrics certificates
include: setup_certificate.yaml
vars:
component: hawkular-metrics
hostnames: "hawkular-metrics,{{ openshift_metrics_hawkular_hostname }}"
changed_when: no
- name: generate hawkular-cassandra certificates
include: setup_certificate.yaml
vars:
component: hawkular-cassandra
hostnames: hawkular-cassandra
changed_when: no
- slurp: src={{ openshift_metrics_certs_dir|quote }}/hawkular-cassandra-truststore.pwd
register: cassandra_truststore_password
- name: check existing aliases on the hawkular-cassandra truststore
shell: >
keytool -noprompt -list
-keystore {{ openshift_metrics_certs_dir|quote }}/hawkular-cassandra.truststore
-storepass {{cassandra_truststore_password.content | b64decode }}
| sed -n '7~2s/,.*$//p'
register: hawkular_cassandra_truststore_aliases
changed_when: false
- slurp: src={{ openshift_metrics_certs_dir|quote }}/hawkular-metrics-truststore.pwd
register: hawkular_truststore_password
- name: check existing aliases on the hawkular-metrics truststore
shell: >
keytool -noprompt -list
-keystore {{ openshift_metrics_certs_dir|quote }}/hawkular-metrics.truststore
-storepass {{ hawkular_truststore_password.content | b64decode }}
| sed -n '7~2s/,.*$//p'
register: hawkular_metrics_truststore_aliases
changed_when: false
- name: import the hawkular metrics cert into the cassandra truststore
command: >
keytool -noprompt -import -v -trustcacerts
-alias hawkular-metrics
-file '{{ openshift_metrics_certs_dir }}/hawkular-metrics.crt'
-keystore '{{ openshift_metrics_certs_dir }}/hawkular-cassandra.truststore'
-storepass {{cassandra_truststore_password.content | b64decode }}
when: >
'hawkular-metrics' not in
hawkular_cassandra_truststore_aliases.stdout_lines
- name: import the hawkular cassandra cert into the hawkular metrics truststore
command: >
keytool -noprompt -import -v -trustcacerts
-alias hawkular-cassandra
-file '{{ openshift_metrics_certs_dir }}/hawkular-cassandra.crt'
-keystore '{{ openshift_metrics_certs_dir }}/hawkular-metrics.truststore'
-storepass {{ hawkular_truststore_password.content | b64decode }}
when: >
'hawkular-cassandra' not in
hawkular_metrics_truststore_aliases.stdout_lines
- name: import the hawkular cassandra cert into the cassandra truststore
command: >
keytool -noprompt -import -v -trustcacerts
-alias hawkular-cassandra
-file '{{ openshift_metrics_certs_dir }}/hawkular-cassandra.crt'
-keystore '{{ openshift_metrics_certs_dir }}/hawkular-cassandra.truststore'
-storepass {{cassandra_truststore_password.content | b64decode }}
when: >
'hawkular-cassandra' not in
hawkular_cassandra_truststore_aliases.stdout_lines
- name: import the ca certificate into the cassandra truststore
command: >
keytool -noprompt -import -v -trustcacerts
-alias '{{ item }}'
-file '{{ openshift_metrics_certs_dir }}/ca.crt'
-keystore '{{ openshift_metrics_certs_dir }}/hawkular-cassandra.truststore'
-storepass {{cassandra_truststore_password.content | b64decode }}
with_items:
- ca
- metricca
- cassandraca
when: item not in hawkular_cassandra_truststore_aliases.stdout_lines
- name: import the ca certificate into the hawkular metrics truststore
command: >
keytool -noprompt -import -v -trustcacerts
-alias '{{ item }}'
-file '{{ openshift_metrics_certs_dir }}/ca.crt'
-keystore '{{ openshift_metrics_certs_dir }}/hawkular-metrics.truststore'
-storepass {{ hawkular_truststore_password.content | b64decode }}
with_items:
- ca
- metricca
- cassandraca
when: item not in hawkular_metrics_truststore_aliases.stdout_lines
- name: generate password for hawkular metrics and jgroups
shell: >
tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c15
> '{{ openshift_metrics_certs_dir }}/{{ item }}.pwd'
with_items:
- hawkular-metrics
- hawkular-jgroups-keystore
when: not '{{ openshift_metrics_certs_dir }}/{{ item }}.pwd'|exists
- name: generate htpasswd file for hawkular metrics
shell: >
htpasswd -ci
'{{ openshift_metrics_certs_dir }}/hawkular-metrics.htpasswd' hawkular
< '{{ openshift_metrics_certs_dir }}/hawkular-metrics.pwd'
when: >
not '{{ openshift_metrics_certs_dir }}/hawkular-metrics.htpasswd'|exists
- name: generate the jgroups keystore
shell: >
p=$(< '{{ openshift_metrics_certs_dir }}/hawkular-jgroups-keystore.pwd' )
&&
keytool -genseckey -alias hawkular
-keypass "$p" -storepass "$p" -keyalg Blowfish -keysize 56 -storetype JCEKS
-keystore '{{ openshift_metrics_certs_dir }}/hawkular-jgroups.keystore'
when: >
not '{{ openshift_metrics_certs_dir }}/hawkular-jgroups.keystore'|exists
- name: read files for the hawkular-metrics secret
shell: >
printf '%s: ' '{{ item }}'
&& base64 --wrap 0 '{{ openshift_metrics_certs_dir }}/{{ item }}'
register: hawkular_secrets
with_items:
- ca.crt
- hawkular-metrics.crt
- hawkular-metrics.keystore
- hawkular-metrics-keystore.pwd
- hawkular-metrics.truststore
- hawkular-metrics-truststore.pwd
- hawkular-metrics.pwd
- hawkular-metrics.htpasswd
- hawkular-jgroups.keystore
- hawkular-jgroups-keystore.pwd
- hawkular-cassandra.crt
- hawkular-cassandra.pem
- hawkular-cassandra.keystore
- hawkular-cassandra-keystore.pwd
- hawkular-cassandra.truststore
- hawkular-cassandra-truststore.pwd
changed_when: false
- set_fact:
hawkular_secrets: |
{{ hawkular_secrets.results|map(attribute='stdout')|join('
')|from_yaml }}
- name: generate hawkular-metrics-secrets secret template
template:
src: secret.j2
dest: "{{ mktemp.stdout }}/templates/hawkular_metrics_secrets.yaml"
vars:
name: hawkular-metrics-secrets
labels:
metrics-infra: hawkular-metrics
data:
hawkular-metrics.keystore: >
{{ hawkular_secrets['hawkular-metrics.keystore'] }}
hawkular-metrics.keystore.password: >
{{ hawkular_secrets['hawkular-metrics-keystore.pwd'] }}
hawkular-metrics.truststore: >
{{ hawkular_secrets['hawkular-metrics.truststore'] }}
hawkular-metrics.truststore.password: >
{{ hawkular_secrets['hawkular-metrics-truststore.pwd'] }}
hawkular-metrics.keystore.alias: "{{ 'hawkular-metrics'|b64encode }}"
hawkular-metrics.htpasswd.file: >
{{ hawkular_secrets['hawkular-metrics.htpasswd'] }}
hawkular-metrics.jgroups.keystore: >
{{ hawkular_secrets['hawkular-jgroups.keystore'] }}
hawkular-metrics.jgroups.keystore.password: >
{{ hawkular_secrets['hawkular-jgroups-keystore.pwd'] }}
hawkular-metrics.jgroups.alias: "{{ 'hawkular'|b64encode }}"
when: name not in metrics_secrets.stdout_lines
changed_when: no
- name: generate hawkular-metrics-certificate secret template
template:
src: secret.j2
dest: "{{ mktemp.stdout }}/templates/hawkular_metrics_certificate.yaml"
vars:
name: hawkular-metrics-certificate
labels:
metrics-infra: hawkular-metrics
data:
hawkular-metrics.certificate: >
{{ hawkular_secrets['hawkular-metrics.crt'] }}
hawkular-metrics-ca.certificate: >
{{ hawkular_secrets['ca.crt'] }}
when: name not in metrics_secrets.stdout_lines
changed_when: no
- name: generate hawkular-metrics-account secret template
template:
src: secret.j2
dest: "{{ mktemp.stdout }}/templates/hawkular_metrics_account.yaml"
vars:
name: hawkular-metrics-account
labels:
metrics-infra: hawkular-metrics
data:
hawkular-metrics.username: "{{ 'hawkular'|b64encode }}"
hawkular-metrics.password: >
{{ hawkular_secrets['hawkular-metrics.pwd'] }}
when: name not in metrics_secrets.stdout_lines
changed_when: no
- name: generate cassandra secret template
template:
src: secret.j2
dest: "{{ mktemp.stdout }}/templates/cassandra_secrets.yaml"
vars:
name: hawkular-cassandra-secrets
labels:
metrics-infra: hawkular-cassandra
data:
cassandra.keystore: >
{{ hawkular_secrets['hawkular-cassandra.keystore'] }}
cassandra.keystore.password: >
{{ hawkular_secrets['hawkular-cassandra-keystore.pwd'] }}
cassandra.keystore.alias: "{{ 'hawkular-cassandra'|b64encode }}"
cassandra.truststore: >
{{ hawkular_secrets['hawkular-cassandra.truststore'] }}
cassandra.truststore.password: >
{{ hawkular_secrets['hawkular-cassandra-truststore.pwd'] }}
cassandra.pem: >
{{ hawkular_secrets['hawkular-cassandra.pem'] }}
when: name not in metrics_secrets
changed_when: no
- name: generate cassandra-certificate secret template
template:
src: secret.j2
dest: "{{ mktemp.stdout }}/templates/cassandra_certificate.yaml"
vars:
name: hawkular-cassandra-certificate
labels:
metrics-infra: hawkular-cassandra
data:
cassandra.certificate: >
{{ hawkular_secrets['hawkular-cassandra.crt'] }}
cassandra-ca.certificate: >
{{ hawkular_secrets['hawkular-cassandra.pem'] }}
when: name not in metrics_secrets.stdout_lines
changed_when: no
|