|
17 | 17 | # Deploy MinIO |
18 | 18 | # |
19 | 19 | # Deploys MinIO as an S3-compatible storage backend. |
20 | | -# Creates namespace, PVC, Deployment, Service, Routes, bucket, |
21 | | -# and optionally a service account. |
| 20 | +# Creates namespace, PVC, Deployment, Service, Routes. |
| 21 | +# Bucket is created via mkdir in the container command. |
22 | 22 | # |
23 | 23 | # Output facts: |
24 | | -# cifmw_deploy_minio_access_key: Service account access key (if created) |
25 | | -# cifmw_deploy_minio_secret_key: Service account secret key (if created) |
| 24 | +# cifmw_deploy_minio_access_key: Root user (for OADP credentials) |
| 25 | +# cifmw_deploy_minio_secret_key: Root password (for OADP credentials) |
26 | 26 |
|
27 | | -- name: Print setup header |
28 | | - ansible.builtin.debug: |
29 | | - msg: |
30 | | - - "========================================" |
31 | | - - "MinIO Setup" |
32 | | - - "========================================" |
33 | | - - "Namespace: {{ cifmw_deploy_minio_namespace }}" |
34 | | - - "Storage Size: {{ cifmw_deploy_minio_storage_size }}" |
35 | | - - "Storage Class: {{ cifmw_deploy_minio_storage_class if cifmw_deploy_minio_storage_class else 'default' }}" |
36 | | - - "Bucket Name: {{ cifmw_deploy_minio_bucket_name }}" |
37 | | - |
38 | | -- name: Create MinIO namespace |
39 | | - ansible.builtin.shell: | |
40 | | - oc create namespace {{ cifmw_deploy_minio_namespace }} --dry-run=client -o yaml | oc apply -f - |
41 | | - changed_when: true |
42 | | - |
43 | | -- name: Create MinIO PVC (with storage class) |
44 | | - ansible.builtin.shell: | |
45 | | - cat <<EOF | oc apply -f - |
46 | | - apiVersion: v1 |
47 | | - kind: PersistentVolumeClaim |
48 | | - metadata: |
49 | | - name: minio-pvc |
50 | | - namespace: {{ cifmw_deploy_minio_namespace }} |
51 | | - spec: |
52 | | - accessModes: |
53 | | - - ReadWriteOnce |
54 | | - storageClassName: {{ cifmw_deploy_minio_storage_class }} |
55 | | - resources: |
56 | | - requests: |
57 | | - storage: {{ cifmw_deploy_minio_storage_size }} |
58 | | - EOF |
59 | | - changed_when: true |
60 | | - when: cifmw_deploy_minio_storage_class != "" |
61 | | - |
62 | | -- name: Create MinIO PVC (default storage class) |
63 | | - ansible.builtin.shell: | |
64 | | - cat <<EOF | oc apply -f - |
65 | | - apiVersion: v1 |
66 | | - kind: PersistentVolumeClaim |
67 | | - metadata: |
68 | | - name: minio-pvc |
69 | | - namespace: {{ cifmw_deploy_minio_namespace }} |
70 | | - spec: |
71 | | - accessModes: |
72 | | - - ReadWriteOnce |
73 | | - resources: |
74 | | - requests: |
75 | | - storage: {{ cifmw_deploy_minio_storage_size }} |
76 | | - EOF |
77 | | - changed_when: true |
78 | | - when: cifmw_deploy_minio_storage_class == "" |
79 | | - |
80 | | -- name: Create MinIO credentials secret |
81 | | - ansible.builtin.shell: | |
82 | | - cat <<EOF | oc apply -f - |
83 | | - apiVersion: v1 |
84 | | - kind: Secret |
85 | | - metadata: |
86 | | - name: minio-credentials |
87 | | - namespace: {{ cifmw_deploy_minio_namespace }} |
88 | | - type: Opaque |
89 | | - stringData: |
90 | | - MINIO_ROOT_USER: {{ cifmw_deploy_minio_root_user }} |
91 | | - MINIO_ROOT_PASSWORD: {{ cifmw_deploy_minio_root_password }} |
92 | | - EOF |
93 | | - changed_when: true |
94 | | - |
95 | | -- name: Create MinIO deployment |
96 | | - ansible.builtin.shell: | |
97 | | - cat <<EOF | oc apply -f - |
98 | | - apiVersion: apps/v1 |
99 | | - kind: Deployment |
100 | | - metadata: |
101 | | - name: minio |
102 | | - namespace: {{ cifmw_deploy_minio_namespace }} |
103 | | - spec: |
104 | | - selector: |
105 | | - matchLabels: |
106 | | - app: minio |
107 | | - strategy: |
108 | | - type: Recreate |
109 | | - template: |
110 | | - metadata: |
111 | | - labels: |
112 | | - app: minio |
113 | | - spec: |
114 | | - containers: |
115 | | - - name: minio |
116 | | - image: {{ cifmw_deploy_minio_image }} |
117 | | - args: |
118 | | - - server |
119 | | - - /data |
120 | | - - --console-address |
121 | | - - :9001 |
122 | | - env: |
123 | | - - name: MINIO_ROOT_USER |
124 | | - valueFrom: |
125 | | - secretKeyRef: |
126 | | - name: minio-credentials |
127 | | - key: MINIO_ROOT_USER |
128 | | - - name: MINIO_ROOT_PASSWORD |
129 | | - valueFrom: |
130 | | - secretKeyRef: |
131 | | - name: minio-credentials |
132 | | - key: MINIO_ROOT_PASSWORD |
133 | | - ports: |
134 | | - - containerPort: 9000 |
135 | | - name: api |
136 | | - - containerPort: 9001 |
137 | | - name: console |
138 | | - volumeMounts: |
139 | | - - name: data |
140 | | - mountPath: /data |
141 | | - livenessProbe: |
142 | | - httpGet: |
143 | | - path: /minio/health/live |
144 | | - port: 9000 |
145 | | - initialDelaySeconds: 30 |
146 | | - periodSeconds: 20 |
147 | | - readinessProbe: |
148 | | - httpGet: |
149 | | - path: /minio/health/ready |
150 | | - port: 9000 |
151 | | - initialDelaySeconds: 30 |
152 | | - periodSeconds: 20 |
153 | | - volumes: |
154 | | - - name: data |
155 | | - persistentVolumeClaim: |
156 | | - claimName: minio-pvc |
157 | | - EOF |
158 | | - changed_when: true |
159 | | - |
160 | | -- name: Create MinIO service |
161 | | - ansible.builtin.shell: | |
162 | | - cat <<EOF | oc apply -f - |
163 | | - apiVersion: v1 |
164 | | - kind: Service |
165 | | - metadata: |
166 | | - name: minio |
167 | | - namespace: {{ cifmw_deploy_minio_namespace }} |
168 | | - spec: |
169 | | - type: ClusterIP |
170 | | - ports: |
171 | | - - port: 9000 |
172 | | - targetPort: 9000 |
173 | | - name: api |
174 | | - - port: 9001 |
175 | | - targetPort: 9001 |
176 | | - name: console |
177 | | - selector: |
178 | | - app: minio |
179 | | - EOF |
180 | | - changed_when: true |
| 27 | +- name: Create temp directory for rendered templates |
| 28 | + ansible.builtin.tempfile: |
| 29 | + state: directory |
| 30 | + prefix: deploy-minio- |
| 31 | + register: _deploy_minio_rendered_dir |
181 | 32 |
|
182 | | -- name: Create MinIO console route |
183 | | - ansible.builtin.shell: | |
184 | | - cat <<EOF | oc apply -f - |
185 | | - apiVersion: route.openshift.io/v1 |
186 | | - kind: Route |
187 | | - metadata: |
188 | | - name: minio-console |
189 | | - namespace: {{ cifmw_deploy_minio_namespace }} |
190 | | - spec: |
191 | | - to: |
192 | | - kind: Service |
193 | | - name: minio |
194 | | - port: |
195 | | - targetPort: console |
196 | | - tls: |
197 | | - termination: edge |
198 | | - insecureEdgeTerminationPolicy: Redirect |
199 | | - EOF |
200 | | - changed_when: true |
| 33 | +- name: Render MinIO manifests |
| 34 | + ansible.builtin.template: |
| 35 | + src: minio.yaml.j2 |
| 36 | + dest: "{{ _deploy_minio_rendered_dir.path }}/minio.yaml" |
201 | 37 |
|
202 | | -- name: Create MinIO API route |
| 38 | +- name: Apply MinIO manifests |
203 | 39 | ansible.builtin.shell: | |
204 | | - cat <<EOF | oc apply -f - |
205 | | - apiVersion: route.openshift.io/v1 |
206 | | - kind: Route |
207 | | - metadata: |
208 | | - name: minio-api |
209 | | - namespace: {{ cifmw_deploy_minio_namespace }} |
210 | | - spec: |
211 | | - to: |
212 | | - kind: Service |
213 | | - name: minio |
214 | | - port: |
215 | | - targetPort: api |
216 | | - tls: |
217 | | - termination: edge |
218 | | - insecureEdgeTerminationPolicy: Redirect |
219 | | - EOF |
| 40 | + oc apply -f {{ _deploy_minio_rendered_dir.path }}/minio.yaml |
220 | 41 | changed_when: true |
221 | 42 |
|
222 | 43 | - name: Wait for MinIO deployment to be ready |
223 | 44 | ansible.builtin.shell: | |
224 | 45 | oc wait --for=condition=available --timeout=300s deployment/minio -n {{ cifmw_deploy_minio_namespace }} |
225 | 46 | changed_when: false |
226 | 47 |
|
| 48 | +- name: Export credentials for downstream roles |
| 49 | + ansible.builtin.set_fact: |
| 50 | + cifmw_deploy_minio_access_key: "{{ cifmw_deploy_minio_root_user }}" |
| 51 | + cifmw_deploy_minio_secret_key: "{{ cifmw_deploy_minio_root_password }}" |
| 52 | + |
227 | 53 | - name: Get MinIO routes |
228 | 54 | ansible.builtin.shell: | |
229 | | - echo "Console URL: https://$(oc get route minio-console -n {{ cifmw_deploy_minio_namespace }} -o jsonpath='{.spec.host}')" |
230 | | - echo "API URL: https://$(oc get route minio-api -n {{ cifmw_deploy_minio_namespace }} -o jsonpath='{.spec.host}')" |
| 55 | + echo "Console: https://$(oc get route minio-console -n {{ cifmw_deploy_minio_namespace }} -o jsonpath='{.spec.host}')" |
| 56 | + echo "API: https://$(oc get route minio-api -n {{ cifmw_deploy_minio_namespace }} -o jsonpath='{.spec.host}')" |
231 | 57 | register: _minio_routes |
232 | 58 | changed_when: false |
233 | 59 |
|
234 | | -- name: Display MinIO routes |
235 | | - ansible.builtin.debug: |
236 | | - msg: "{{ _minio_routes.stdout_lines }}" |
237 | | - |
238 | | -- name: Install MinIO client (mc) |
239 | | - ansible.builtin.shell: | |
240 | | - if ! command -v mc &> /dev/null; then |
241 | | - curl -o /tmp/mc https://dl.min.io/client/mc/release/linux-amd64/mc |
242 | | - chmod +x /tmp/mc |
243 | | - echo "/tmp/mc" |
244 | | - else |
245 | | - echo "mc" |
246 | | - fi |
247 | | - register: _mc_path |
248 | | - changed_when: false |
249 | | - |
250 | | -- name: Configure MinIO client |
251 | | - ansible.builtin.shell: | |
252 | | - MINIO_API_URL=$(oc get route minio-api -n {{ cifmw_deploy_minio_namespace }} -o jsonpath='{.spec.host}') |
253 | | - {{ _mc_path.stdout }} alias set minio https://${MINIO_API_URL} {{ cifmw_deploy_minio_root_user }} {{ cifmw_deploy_minio_root_password }} --insecure |
254 | | - changed_when: true |
255 | | - |
256 | | -- name: Create bucket |
257 | | - ansible.builtin.shell: | |
258 | | - {{ _mc_path.stdout }} mb minio/{{ cifmw_deploy_minio_bucket_name }} --insecure || true |
259 | | - changed_when: true |
260 | | - |
261 | | -- name: Verify bucket was created |
262 | | - ansible.builtin.shell: | |
263 | | - {{ _mc_path.stdout }} ls minio --insecure | grep {{ cifmw_deploy_minio_bucket_name }} |
264 | | - register: _bucket_check |
265 | | - changed_when: false |
266 | | - |
267 | | -- name: Create MinIO service account |
268 | | - ansible.builtin.shell: | |
269 | | - {{ _mc_path.stdout }} admin user svcacct add minio {{ cifmw_deploy_minio_root_user }} --insecure |
270 | | - register: _service_account |
271 | | - changed_when: true |
272 | | - failed_when: false |
273 | | - when: cifmw_deploy_minio_create_service_account | bool |
274 | | - |
275 | | -- name: Parse service account credentials |
276 | | - ansible.builtin.set_fact: |
277 | | - cifmw_deploy_minio_access_key: "{{ _service_account.stdout | regex_search('Access Key: (.+)', '\\1') | first }}" |
278 | | - cifmw_deploy_minio_secret_key: "{{ _service_account.stdout | regex_search('Secret Key: (.+)', '\\1') | first }}" |
279 | | - when: |
280 | | - - cifmw_deploy_minio_create_service_account | bool |
281 | | - - _service_account.rc == 0 |
282 | | - - _service_account.stdout != "" |
283 | | - |
284 | | -- name: Save service account credentials |
285 | | - ansible.builtin.copy: |
286 | | - content: | |
287 | | - MinIO Service Account Credentials |
288 | | - ================================== |
289 | | -
|
290 | | - Access Key: {{ cifmw_deploy_minio_access_key }} |
291 | | - Secret Key: {{ cifmw_deploy_minio_secret_key }} |
292 | | - dest: "/tmp/minio-service-account-{{ cifmw_deploy_minio_namespace }}.txt" |
293 | | - mode: "0600" |
294 | | - when: |
295 | | - - cifmw_deploy_minio_create_service_account | bool |
296 | | - - cifmw_deploy_minio_access_key is defined |
297 | | - |
298 | 60 | - name: Print setup complete |
299 | 61 | ansible.builtin.debug: |
300 | 62 | msg: |
301 | 63 | - "========================================" |
302 | 64 | - "MinIO Setup Complete" |
303 | 65 | - "========================================" |
304 | | - - "" |
305 | 66 | - "{{ _minio_routes.stdout_lines[0] }}" |
306 | 67 | - "{{ _minio_routes.stdout_lines[1] }}" |
307 | | - - "" |
308 | | - - "Bucket: {{ cifmw_deploy_minio_bucket_name }}" |
309 | | - - "{{ 'Service Account Access Key: ' + cifmw_deploy_minio_access_key if cifmw_deploy_minio_access_key is defined else 'Service account not created' }}" |
| 68 | + - "Buckets: {{ cifmw_deploy_minio_buckets | join(', ') }}" |
| 69 | + |
| 70 | +- name: Cleanup rendered templates |
| 71 | + ansible.builtin.file: |
| 72 | + path: "{{ _deploy_minio_rendered_dir.path }}" |
| 73 | + state: absent |
0 commit comments