fix: Normalize line endings in drift-check content comparison
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

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.
This commit is contained in:
dvirlabs 2026-04-23 14:06:14 +03:00
parent 96bd931e2f
commit 66df6c74ec

View File

@ -14,7 +14,7 @@
drifted_files: [] drifted_files: []
# ───────────────────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────────────────
# Compare rsyslog.conf content # Compare rsyslog.conf content (with line ending normalization)
# ───────────────────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────────────────
- name: Read Git rsyslog.conf - name: Read Git rsyslog.conf
slurp: slurp:
@ -27,9 +27,23 @@
src: "{{ rsyslog_main_config }}" src: "{{ rsyslog_main_config }}"
register: server_main_conf 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 - name: Check rsyslog.conf content match
set_fact: 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 - name: Mark drift if rsyslog.conf differs
set_fact: set_fact: