From 0055971afd5524f0df00fc8d2203a80f828885f7 Mon Sep 17 00:00:00 2001 From: Colin Wilk Date: Tue, 21 Jul 2026 19:10:19 +0200 Subject: fix: prevent lost YAML targets during parallel writes The YAML strategy performed a separate read-modify-write operation for every managed host. Because these tasks were delegated to the same Prometheus host, parallel Ansible forks could read the same original file before any fork wrote its update. Each fork then generated YAML containing only its own target. Although the copy module atomically replaced the file, it did not make the full read-modify-write sequence atomic. The last fork to write therefore overwrote targets added by earlier forks. Collect exporter updates from all hosts through hostvars, process them in one run_once operation, and write each distinct target file once. This preserves every target without requiring users to set serial. Add parallel coverage for multiple target files and label groups, and reset the fixtures on every convergence so stale files cannot hide the race. --- tasks/main.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tasks/main.yml') diff --git a/tasks/main.yml b/tasks/main.yml index 10f54f7..ecffd79 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,11 +1,16 @@ --- -- name: Process all exporters +- name: Process YAML exporters + ansible.builtin.include_tasks: strategy_yaml.yml + when: prometheus_target_strategy == "yaml" + +- name: Process all lineinfile exporters ansible.builtin.include_tasks: file: process_exporter.yml loop: "{{ prometheus_target_exporter + ([] if prometheus_target_skip_default_exporters else prometheus_target_default_exporters) }}" loop_control: loop_var: item + when: prometheus_target_strategy != "yaml" - name: Run handlers ansible.builtin.include_tasks: -- cgit v1.2.3