aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/molecule/default/converge.yml
blob: 4e379dafd623e086be33e3e151883bee56a268da (plain) (blame)
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
---
################################################################################
################################################################################
- name: Lineinfile bootstrap and subsequent hosts
  hosts: application
  pre_tasks:
    - name: Create test user
      ansible.builtin.user:
        name: prometheus
      become: true
      delegate_to: "{{ prometheus_target_host }}"

    - name: Create lineinfile bootstrap target
      ansible.builtin.copy:
        dest: /opt/lineinfile_bootstrap.yml
        owner: prometheus
        group: prometheus
        mode: "0600"
        content: |
          - labels:
              my: label
            targets:
            - existing:9100
        force: false
      become: true
      delegate_to: "{{ prometheus_target_host }}"

  vars:
    prometheus_target_host: prometheus
    prometheus_target_strategy_lineinfile_prefix: "  - "
    prometheus_target_strategy_lineinfile_suffix: :9100

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - path: /opt/lineinfile_bootstrap.yml
          host: "{{ inventory_hostname }}"

################################################################################
################################################################################
- name: Lineinfile first host on empty file
  hosts: application
  pre_tasks:
    - name: Create empty lineinfile target
      ansible.builtin.copy:
        dest: /opt/lineinfile_first_host.yml
        owner: prometheus
        group: prometheus
        mode: "0600"
        content: ""
        force: false
      become: true
      delegate_to: "{{ prometheus_target_host }}"

  vars:
    prometheus_target_host: prometheus
    prometheus_target_strategy_lineinfile_prefix: "- "
    prometheus_target_strategy_lineinfile_suffix: :9100

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - path: /opt/lineinfile_first_host.yml
          host: "{{ inventory_hostname }}"

################################################################################
################################################################################
- name: Lineinfile subsequent hosts and parallel writes
  hosts: application_group
  pre_tasks:
    - name: Create lineinfile parallel target
      ansible.builtin.copy:
        dest: /opt/lineinfile_parallel.yml
        owner: prometheus
        group: prometheus
        mode: "0600"
        content: ""
        force: false
      become: true
      delegate_to: "{{ prometheus_target_host }}"
      run_once: true

  vars:
    prometheus_target_host: prometheus
    prometheus_target_strategy_lineinfile_prefix: "- "
    prometheus_target_strategy_lineinfile_suffix: :9100

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - path: /opt/lineinfile_parallel.yml
          host: "{{ inventory_hostname }}"

################################################################################
################################################################################
- name: Lineinfile user edited file
  hosts: application2
  pre_tasks:
    - name: Create user edited lineinfile target
      ansible.builtin.copy:
        dest: /opt/lineinfile_user_edited.yml
        owner: prometheus
        group: prometheus
        mode: "0600"
        content: |
          # user comment
          - labels:
              env: prod
            targets:
            - existing:9100
        force: false
      delegate_to: "{{ prometheus_target_host }}"

  vars:
    prometheus_target_host: prometheus
    prometheus_target_strategy_lineinfile_prefix: "  - "
    prometheus_target_strategy_lineinfile_suffix: :9100

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - path: /opt/lineinfile_user_edited.yml
          host: "{{ inventory_hostname }}"

################################################################################
################################################################################
- name: Lineinfile remove last host scenario
  hosts: localhost
  connection: local
  gather_facts: false
  tasks:
    - name: Create single host lineinfile target
      ansible.builtin.copy:
        dest: /opt/lineinfile_remove_last.yml
        owner: prometheus
        group: prometheus
        mode: "0600"
        content: |
          - labels:
              env: stage
            targets:
              - application:9100
        force: false
      become: true
      delegate_to: prometheus

    - name: Remove last host line externally
      ansible.builtin.lineinfile:
        path: /opt/lineinfile_remove_last.yml
        line: "    - application:9100"
        state: absent
      become: true
      delegate_to: prometheus

################################################################################
################################################################################
- name: YAML bootstrap and first host
  hosts: application
  pre_tasks:
    - name: Create empty yaml bootstrap target
      ansible.builtin.copy:
        dest: /opt/yaml_bootstrap.yml
        mode: "0644"
        content: ""
        force: false
      become: true
      delegate_to: "{{ prometheus_target_host }}"

  vars:
    prometheus_target_host: prometheus
    prometheus_target_strategy: yaml

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - path: /opt/yaml_bootstrap.yml
          host: "{{ inventory_hostname }}:9100"
          labels:
            job: node

################################################################################
################################################################################
- name: YAML subsequent hosts and parallel writes
  hosts: application_group
  pre_tasks:
    - name: Create yaml parallel target
      ansible.builtin.copy:
        dest: /opt/yaml_parallel.yml
        mode: "0644"
        content: |
          - labels:
              job: node
            targets:
              - existing:9100
        force: false
      delegate_to: "{{ prometheus_target_host }}"
      run_once: true

  vars:
    prometheus_target_host: prometheus
    prometheus_target_strategy: yaml

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - path: /opt/yaml_parallel.yml
          host: "{{ inventory_hostname }}:9100"
          labels:
            job: node

################################################################################
################################################################################
- name: YAML user edited file exact label matching
  hosts: application2
  pre_tasks:
    - name: Create user edited yaml target
      ansible.builtin.copy:
        dest: /opt/yaml_user_edited.yml
        mode: "0644"
        content: |
          # user comment that will be lost after parse/write
          - labels:
              severity: warning
              job: external
            targets:
              - existing_host1:9100
          - labels:
              severity: critical
            targets:
              - application2:9200
          - targets:
              - unlabeled:9100
        force: false
      delegate_to: "{{ prometheus_target_host }}"

  vars:
    prometheus_target_host: prometheus
    prometheus_target_strategy: yaml
    prometheus_target_exporter_defaults:
      exact_match:
        path: /opt/yaml_user_edited.yml
        host: "{{ inventory_hostname }}:9100"
        labels:
          severity: warning
          job: external
      move_target:
        path: /opt/yaml_user_edited.yml
        host: "{{ inventory_hostname }}:9200"
        labels:
          severity: critical
          team: blue
      no_labels:
        path: /opt/yaml_user_edited.yml
        host: standalone:9300

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - id: exact_match
        - id: move_target
        - id: no_labels

################################################################################
################################################################################
- name: YAML remove last host by moving target
  hosts: application
  pre_tasks:
    - name: Create yaml remove last host target
      ansible.builtin.copy:
        dest: /opt/yaml_move_remove_last.yml
        mode: "0644"
        content: |
          - labels:
              job: old
            targets:
              - application:9400
        force: false
      become: true
      delegate_to: "{{ prometheus_target_host }}"

  vars:
    prometheus_target_host: prometheus
    prometheus_target_strategy: yaml

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - path: /opt/yaml_move_remove_last.yml
          host: "{{ inventory_hostname }}:9400"
          labels:
            job: new

################################################################################
################################################################################
- name: YAML branch coverage matrix
  hosts: application3
  pre_tasks:
    - name: Create yaml branch coverage target
      ansible.builtin.copy:
        dest: /opt/yaml_branch_matrix.yml
        mode: "0644"
        content: |
          - labels:
              job: append
              env: prod
            targets:
              - existing_append:9500
          - labels:
              job: wrong
              env: prod
            targets:
              - keep_same_length:9500
          - labels:
              job: short
            targets:
              - keep_length_mismatch:9500
          - labels:
              job: present
              env: prod
            targets:
              - application3:9501
          - labels:
              job: move_source
            targets:
              - application3:9502
          - targets:
              - orphan_unlabeled:9503
          - targets:
              - shared_unlabeled:9504
          - labels:
              job: foreign
            targets:
              - foreign:9505
        force: false
      delegate_to: "{{ prometheus_target_host }}"

  vars:
    prometheus_target_host: prometheus
    prometheus_target_strategy: yaml

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - path: /opt/yaml_branch_matrix.yml
          host: application3:9506
          labels:
            job: append
            env: prod
        - path: /opt/yaml_branch_matrix.yml
          host: application3:9501
          labels:
            job: present
            env: prod
        - path: /opt/yaml_branch_matrix.yml
          host: application3:9502
          labels:
            job: move_target
        - path: /opt/yaml_branch_matrix.yml
          host: orphan_unlabeled:9503
          labels:
            job: promoted
        - path: /opt/yaml_branch_matrix.yml
          host: standalone_branch:9504
        - path: /opt/yaml_branch_matrix.yml
          host: shared_unlabeled:9504

################################################################################
################################################################################
- name: YAML missing file creation branches
  hosts: application4
  vars:
    prometheus_target_host: prometheus
    prometheus_target_strategy: yaml

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - path: /opt/yaml_missing_labeled.yml
          host: "{{ inventory_hostname }}:9600"
          labels:
            team: infra
        - path: /opt/yaml_missing_unlabeled.yml
          host: "{{ inventory_hostname }}:9601"

################################################################################
################################################################################
- name: Simple compatibility checks
  hosts: application
  pre_tasks:
    - name: Create compatibility target files
      ansible.builtin.copy:
        dest: "{{ item }}"
        content: ""
        mode: "0644"
        force: false
      become: true
      delegate_to: "{{ prometheus_target_host }}"
      loop:
        - /opt/simple_target1.yml
        - /opt/simple_target2.yml
        - /opt/simple_target3.yml
        - /opt/simple_target4.yml
        - /opt/prefix_target1.yml
        - /opt/prefix_target2.yml

    - name: Create prefix directory
      ansible.builtin.file:
        path: /opt/prefix
        state: directory
        mode: "0644"
      become: true
      delegate_to: "{{ prometheus_target_host }}"

    - name: Create prefix target
      ansible.builtin.copy:
        dest: /opt/prefix/prefix_target3.yml
        content: ""
        mode: "0644"
        force: false
      become: true
      delegate_to: "{{ prometheus_target_host }}"

  vars:
    prometheus_target_host: prometheus
    prometheus_target_exporter_target_prefix: /opt/
    prometheus_target_exporter_defaults:
      node_exporter:
        path: simple_target1.yml
        host: "{{ inventory_hostname }}"
      blackbox_exporter:
        path: simple_target2.yml
        host: "{{ inventory_hostname }}_AA"
      prefixed_exporter:
        path: prefix_target1.yml
        host: "{{ inventory_hostname }}"
      prefixed_other:
        path: prefix_target_not_exist.yml
        host: "{{ inventory_hostname }}"
        path_prefix: /opt/prefix/

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - id: node_exporter
        - { id: blackbox_exporter, host: test1 }
        - { id: blackbox_exporter, host: test2 }
        - { host: exporter_without_id, path: simple_target4.yml }
        - { id: blackbox_exporter, path: simple_target3.yml }
        - { id: prefixed_exporter }
        - {
            id: prefixed_exporter,
            path: /opt/prefix_target2.yml,
            path_prefix: "",
          }
        - { id: prefixed_other, path: prefix_target3.yml }

################################################################################
################################################################################
- name: Hook compatibility checks
  hosts: application_group
  pre_tasks:
    - name: Create hook target
      ansible.builtin.copy:
        dest: /opt/hook_target.yml
        content: ""
        mode: "0644"
        force: false
      become: true
      delegate_to: "{{ prometheus_target_host }}"

  vars:
    prometheus_target_host: prometheus
    prometheus_target_handler_command_enabled: true
    prometheus_target_handler_command:
      cmd: mkdir -p /opt/hook1
      creates: /opt/hook1
    prometheus_target_handler_command_run_once: true
    prometheus_target_handler_shell_enabled: true
    prometheus_target_handler_shell:
      cmd: echo hello >> /opt/hook2

  roles:
    - role: kliwniloc.prometheus_target
      prometheus_target_exporter:
        - path: /opt/hook_target.yml
          host: "{{ inventory_hostname }}"