Update drift-check to let the pipeline update also what files changed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
dvirlabs 2026-04-22 21:50:39 +03:00
parent 7aeb957eb3
commit f926b7eb0d
2 changed files with 14 additions and 10 deletions

View File

@ -116,7 +116,6 @@
- name: Output structured list of drifted files for GitOps status server
ansible.builtin.debug:
msg: "DRIFTED_FILES={{ drifted_files | join(',') }}"
when: drift_detected
- name: Output sync status marker for parsing
ansible.builtin.debug:

View File

@ -97,29 +97,34 @@ if [ "$DRIFT_RC" -eq 0 ]; then
else
SYNC_STATUS="OUT_OF_SYNC"
echo " ✗ Status: OUT OF SYNC - configuration drift detected"
fi
# Extract structured drifted files from playbook output
# The drift-check.yml playbook outputs: DRIFTED_FILES=file1,file2,file3
# Search for the pattern in the output
if grep -q "DRIFTED_FILES=" "$PLAYBOOK_LOG"; then
DRIFTED_FILES_STR=$(grep "DRIFTED_FILES=" "$PLAYBOOK_LOG" | tail -1)
# Remove ANSI color codes and extract the value
DRIFTED_FILES_STR=$(echo "$DRIFTED_FILES_STR" | sed 's/.*DRIFTED_FILES=//' | sed 's/\x1b\[[0-9;]*m//g' | xargs)
# Extract structured drifted files from playbook output
# The drift-check.yml playbook outputs: DRIFTED_FILES=file1,file2,file3
if grep -q "DRIFTED_FILES=" "$PLAYBOOK_LOG"; then
DRIFTED_FILES_STR=$(grep "DRIFTED_FILES=" "$PLAYBOOK_LOG" | head -1 | sed 's/.*DRIFTED_FILES=//' | sed 's/\x1b\[[0-9;]*m//g')
if [ -n "$DRIFTED_FILES_STR" ]; then
# Parse comma-separated list into array
IFS=',' read -ra CHANGED_FILES <<<"$DRIFTED_FILES_STR"
# Clean up whitespace and convert paths
# Clean up whitespace
for i in "${!CHANGED_FILES[@]}"; do
CHANGED_FILES[$i]=$(echo "${CHANGED_FILES[$i]}" | xargs)
# Convert full paths to relative paths for cleaner output
# /etc/rsyslog.conf -> rsyslog.conf
# /etc/rsyslog.d/30-lab.conf -> rsyslog.d/30-lab.conf
if [[ "${CHANGED_FILES[$i]}" == /etc/rsyslog.conf ]]; then
CHANGED_FILES[$i]="rsyslog.conf"
elif [[ "${CHANGED_FILES[$i]}" == /etc/rsyslog.d/* ]]; then
CHANGED_FILES[$i]=$(echo "${CHANGED_FILES[$i]}" | sed 's|^/etc/||')
fi
echo " - Drift detected in: ${CHANGED_FILES[$i]}"
if [ "$SYNC_STATUS" = "OUT_OF_SYNC" ]; then
echo " - Drift detected in: ${CHANGED_FILES[$i]}"
fi
done
DRIFT_COUNT=${#CHANGED_FILES[@]}