blob: 8e0b5c943458cec390ca6eda7c8a6092bc10d7ec (
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
|
---
################################################################################
################################################################################
- name: Lineinfile bootstrap and subsequent hosts
hosts: application
pre_tasks:
- 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
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
- path: /opt/yaml_parallel_second.yml
host: "{{ inventory_hostname }}:9200"
labels:
job: node
- path: /opt/yaml_parallel.yml
host: "{{ inventory_hostname }}:9300"
labels:
job: alternate
################################################################################
################################################################################
- 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 }}"
################################################################################
################################################################################
- name: Lineinfile exporter resolution matrix
hosts: application
pre_tasks:
- name: Create lineinfile resolution target files
ansible.builtin.copy:
dest: "{{ item }}"
content: ""
mode: "0644"
force: false
become: true
delegate_to: "{{ prometheus_target_host }}"
loop:
- /opt/lineinfile_defaults.yml
- /opt/lineinfile_no_id.yml
- /opt/lineinfile_override.yml
- /opt/lineinfile_skipped.yml
- name: Create lineinfile default prefix directory
ansible.builtin.file:
path: /opt/lineinfile-prefix
state: directory
mode: "0755"
become: true
delegate_to: "{{ prometheus_target_host }}"
- name: Create lineinfile prefixed target
ansible.builtin.copy:
dest: /opt/lineinfile-prefix/default-prefix.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:
inherited:
path: lineinfile_defaults.yml
host: inherited-default
default_only:
path: lineinfile_defaults.yml
host: appended-default
overridden:
path: unused.yml
host: unused-host
prefixed:
path: default-prefix.yml
host: prefixed-default
path_prefix: /opt/lineinfile-prefix/
prometheus_target_default_exporters:
- id: default_only
roles:
- role: kliwniloc.prometheus_target
prometheus_target_strategy_lineinfile_prefix: "- "
prometheus_target_exporter:
- id: inherited
- id: inherited
- path: lineinfile_no_id.yml
host: no-id
- id: overridden
path: /opt/lineinfile_override.yml
path_prefix: ""
host: item-override
- id: prefixed
################################################################################
################################################################################
- name: Lineinfile skips default exporters
hosts: application
vars:
prometheus_target_host: prometheus
prometheus_target_skip_default_exporters: true
prometheus_target_exporter_defaults:
skipped:
path: /opt/lineinfile_skipped.yml
host: must-not-appear
prometheus_target_default_exporters:
- id: skipped
roles:
- role: kliwniloc.prometheus_target
################################################################################
################################################################################
- name: YAML exporter resolution matrix
hosts: application
pre_tasks:
- name: Create YAML resolution target files
ansible.builtin.copy:
dest: "{{ item.path }}"
content: "{{ item.content }}"
mode: "0644"
force: false
become: true
delegate_to: "{{ prometheus_target_host }}"
loop:
- path: /opt/yaml_defaults.yml
content: ""
- path: /opt/yaml_no_id.yml
content: ""
- path: /opt/yaml_override.yml
content: ""
- path: /opt/yaml_null.yml
content: "~\n"
- path: /opt/yaml_skipped.yml
content: ""
- name: Create YAML default prefix directory
ansible.builtin.file:
path: /opt/yaml-prefix
state: directory
mode: "0755"
become: true
delegate_to: "{{ prometheus_target_host }}"
- name: Create YAML prefixed target
ansible.builtin.copy:
dest: /opt/yaml-prefix/default-prefix.yml
content: ""
mode: "0644"
force: false
become: true
delegate_to: "{{ prometheus_target_host }}"
vars:
prometheus_target_host: prometheus
prometheus_target_strategy: yaml
prometheus_target_exporter_target_prefix: /opt/
prometheus_target_exporter_defaults:
inherited:
path: yaml_defaults.yml
host: inherited-default:9700
labels:
job: inherited
environment: production
default_only:
path: yaml_defaults.yml
host: appended-default:9701
labels:
job: default
overridden:
path: unused.yml
host: unused-host
labels:
job: unused
prefixed:
path: default-prefix.yml
host: prefixed-default:9702
path_prefix: /opt/yaml-prefix/
labels:
job: prefixed
prometheus_target_default_exporters:
- id: default_only
roles:
- role: kliwniloc.prometheus_target
prometheus_target_exporter:
- id: inherited
host: application:9700
labels:
environment: staging
- id: inherited
host: application:9700
labels:
environment: staging
- path: yaml_no_id.yml
host: no-id:9700
labels:
job: no-id
- id: overridden
path: /opt/yaml_override.yml
path_prefix: ""
host: item-override:9700
labels:
job: override
- id: prefixed
- path: yaml_null.yml
host: from-null:9700
################################################################################
################################################################################
- name: YAML skips default exporters
hosts: application
vars:
prometheus_target_host: prometheus
prometheus_target_strategy: yaml
prometheus_target_skip_default_exporters: true
prometheus_target_exporter_defaults:
skipped:
path: /opt/yaml_skipped.yml
host: must-not-appear:9700
labels:
job: skipped
prometheus_target_default_exporters:
- id: skipped
roles:
- role: kliwniloc.prometheus_target
################################################################################
################################################################################
- name: Handler execution matrix
hosts: application_group
pre_tasks:
- name: Create handler matrix target
ansible.builtin.copy:
dest: /opt/handler_matrix.yml
content: ""
mode: "0644"
force: false
become: true
delegate_to: "{{ prometheus_target_host }}"
run_once: true
vars:
prometheus_target_host: prometheus
prometheus_target_handler_command_enabled: true
prometheus_target_handler_command_become: false
prometheus_target_handler_command_run_once: false
prometheus_target_handler_command:
cmd: "touch /tmp/command-handler-{{ inventory_hostname }}"
creates: "/tmp/command-handler-{{ inventory_hostname }}"
prometheus_target_handler_shell_enabled: true
prometheus_target_handler_shell_become: false
prometheus_target_handler_shell_run_once: true
prometheus_target_handler_shell:
cmd: touch /tmp/shell-handler-run-once
creates: /tmp/shell-handler-run-once
roles:
- role: kliwniloc.prometheus_target
prometheus_target_strategy_lineinfile_prefix: "- "
prometheus_target_exporter:
- path: /opt/handler_matrix.yml
host: "{{ inventory_hostname }}"
################################################################################
################################################################################
- name: Disabled handlers do not execute
hosts: application
pre_tasks:
- name: Create disabled handler target
ansible.builtin.copy:
dest: /opt/handler_disabled.yml
content: ""
mode: "0644"
force: false
become: true
delegate_to: "{{ prometheus_target_host }}"
vars:
prometheus_target_host: prometheus
prometheus_target_handler_command_enabled: false
prometheus_target_handler_command:
cmd: touch /tmp/disabled-command-handler
prometheus_target_handler_shell_enabled: false
prometheus_target_handler_shell:
cmd: touch /tmp/disabled-shell-handler
roles:
- role: kliwniloc.prometheus_target
prometheus_target_strategy_lineinfile_prefix: "- "
prometheus_target_exporter:
- path: /opt/handler_disabled.yml
host: application
################################################################################
################################################################################
- name: Remove lineinfile exporters
hosts: application_remove
vars:
prometheus_target_host: prometheus
prometheus_target_strategy_lineinfile_prefix: " - "
prometheus_target_exporter_defaults:
remove_shared:
path: /opt/lineinfile_state_removal.yml
host: remove:9100
state: absent
roles:
- role: kliwniloc.prometheus_target
prometheus_target_exporter:
- id: remove_shared
- path: /opt/lineinfile_state_removal.yml
host: remove:9200
state: absent
- path: /opt/lineinfile_state_missing.yml
host: missing:9100
state: absent
################################################################################
################################################################################
- name: Remove YAML exporters
hosts: application_remove
vars:
prometheus_target_host: prometheus
prometheus_target_strategy: yaml
prometheus_target_exporter_defaults:
remove_shared:
path: /opt/yaml_state_removal.yml
host: remove:9100
state: absent
roles:
- role: kliwniloc.prometheus_target
prometheus_target_exporter:
- id: remove_shared
- path: /opt/yaml_state_removal.yml
host: remove:9200
state: absent
- path: /opt/yaml_state_missing.yml
host: missing:9100
state: absent
|