From 66df6c74ecc8c434c54da86be7ae3e9ec2f08035 Mon Sep 17 00:00:00 2001 From: dvirlabs <114520947+dvirlabs@users.noreply.github.com> Date: Thu, 23 Apr 2026 14:06:14 +0300 Subject: [PATCH] fix: Normalize line endings in drift-check content comparison CRITICAL FIX FOR WINDOWS: Problem: Git on Windows uses CRLF, but deployed files use LF. When comparing with slurp (byte-for-byte base64 comparison), CRLF != LF causes false positives. Solution: Decode base64 content and normalize line endings: - Replace CRLF with LF in both Git and server file content - Then compare the normalized content This ensures that line ending differences don't trigger false OUT_OF_SYNC alerts. After deploy, content will match regardless of platform line ending differences. --- ansible/playbooks/drift-check.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ansible/playbooks/drift-check.yml b/ansible/playbooks/drift-check.yml index fdf8de0..aa8d776 100644 --- a/ansible/playbooks/drift-check.yml +++ b/ansible/playbooks/drift-check.yml @@ -14,7 +14,7 @@ drifted_files: [] # ───────────────────────────────────────────────────────────────────────── - # Compare rsyslog.conf content + # Compare rsyslog.conf content (with line ending normalization) # ───────────────────────────────────────────────────────────────────────── - name: Read Git rsyslog.conf slurp: @@ -27,9 +27,23 @@ src: "{{ rsyslog_main_config }}" register: server_main_conf + - name: Normalize line endings and compare rsyslog.conf + set_fact: + # Decode base64, normalize line endings (CRLF -> LF), compare + git_main_content: "{{ (git_main_conf.content | b64decode | replace('\r\n', '\n')) }}" + server_main_content: "{{ (server_main_conf.content | b64decode | replace('\r\n', '\n')) }}" + - name: Check rsyslog.conf content match set_fact: - main_conf_match: "{{ git_main_conf.content == server_main_conf.content }}" + main_conf_match: "{{ git_main_content == server_main_content }}" + + - name: Debug rsyslog.conf comparison + debug: + msg: | + Git rsyslog.conf size: {{ git_main_content | length }} chars + Server rsyslog.conf size: {{ server_main_content | length }} chars + Match: {{ main_conf_match }} + when: not main_conf_match - name: Mark drift if rsyslog.conf differs set_fact: