test
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
dvirlabs 2026-04-24 02:14:46 +03:00
parent fa682da7a6
commit eddad9b770
2 changed files with 142 additions and 104 deletions

View File

@ -97,6 +97,7 @@ steps:
GITOPS_STATUS_SERVER_URL: http://gitops-status-server.observability-stack.svc.cluster.local:5000 GITOPS_STATUS_SERVER_URL: http://gitops-status-server.observability-stack.svc.cluster.local:5000
REPO_NAME: rsyslog REPO_NAME: rsyslog
SERVER_NAME: rsyslog-lab SERVER_NAME: rsyslog-lab
MODE: post-deploy
# Optimize Ansible for container environment # Optimize Ansible for container environment
ANSIBLE_HOST_KEY_CHECKING: "False" ANSIBLE_HOST_KEY_CHECKING: "False"
ANSIBLE_FORCE_COLOR: "False" ANSIBLE_FORCE_COLOR: "False"
@ -108,8 +109,8 @@ steps:
# Increase file descriptor limit for Ansible (max safe value) # Increase file descriptor limit for Ansible (max safe value)
ulimit -n 65536 ulimit -n 65536
# Install dependencies: curl for HTTP requests, jq for JSON formatting # Install dependencies: git for detecting deployed files, curl for HTTP requests, jq for JSON formatting
apk add --no-cache curl jq > /dev/null 2>&1 apk add --no-cache git curl jq > /dev/null 2>&1
# Setup SSH key for Ansible # Setup SSH key for Ansible
mkdir -p ~/.ssh mkdir -p ~/.ssh

View File

@ -49,17 +49,64 @@ REPO_NAME="${REPO_NAME:-rsyslog}"
SERVER_NAME="${SERVER_NAME:-rsyslog-lab}" SERVER_NAME="${SERVER_NAME:-rsyslog-lab}"
INVENTORY_FILE="ansible/inventory/hosts.yml" INVENTORY_FILE="ansible/inventory/hosts.yml"
PLAYBOOK="ansible/playbooks/drift-check.yml" PLAYBOOK="ansible/playbooks/drift-check.yml"
MODE="${MODE:-drift-check}" # drift-check or post-deploy
echo "═══════════════════════════════════════════════════════════════════════════════" echo "═══════════════════════════════════════════════════════════════════════════════"
echo " GitOps Status Update" echo " GitOps Status Update"
echo " Repository: $REPO_NAME | Server: $SERVER_NAME" echo " Repository: $REPO_NAME | Server: $SERVER_NAME"
echo " Target: $GITOPS_STATUS_SERVER_URL" echo " Target: $GITOPS_STATUS_SERVER_URL"
echo " Mode: $MODE"
echo "═══════════════════════════════════════════════════════════════════════════════" echo "═══════════════════════════════════════════════════════════════════════════════"
echo "" echo ""
CHANGED_FILES=()
DRIFT_COUNT=0
SYNC_STATUS="SYNCED"
# ───────────────────────────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────────────────────────
# Step 1: Run drift-check playbook # MODE 1: post-deploy - Report what files were deployed from Git
# ───────────────────────────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────────────────────────
if [ "$MODE" = "post-deploy" ]; then
echo "Step 1/4: Analyzing Git changes (what was just deployed)..."
# Check what files changed in the last commit in files/ directory
if command -v git >/dev/null 2>&1 && [ -d .git ]; then
# Get list of changed files in files/ directory from last commit
CHANGED_FILE_PATHS=$(git diff-tree --no-commit-id --name-only -r HEAD -- files/ 2>/dev/null || echo "")
if [ -n "$CHANGED_FILE_PATHS" ]; then
echo " Files changed in last commit:"
while IFS= read -r filepath; do
if [ -n "$filepath" ]; then
# Strip "files/" prefix to get the config file name
filename="${filepath#files/}"
# Skip if it's just "files/" (directory change)
if [ "$filename" != "" ] && [ "$filename" != "files/" ]; then
CHANGED_FILES+=("$filename")
echo " - $filename"
fi
fi
done <<< "$CHANGED_FILE_PATHS"
DRIFT_COUNT=${#CHANGED_FILES[@]}
else
echo " No files changed in files/ directory"
fi
else
echo " Git not available, cannot determine deployed files"
fi
# Always SYNCED after successful deploy
SYNC_STATUS="SYNCED"
echo " ✓ Status: SYNCED - files were deployed successfully"
echo " Total deployed files: $DRIFT_COUNT"
echo ""
# ─────────────────────────────────────────────────────────────────────────────────
# MODE 2: drift-check - Check for manual changes on server (drift detection)
# ─────────────────────────────────────────────────────────────────────────────────
else
echo "Step 1/4: Running drift-check playbook..." echo "Step 1/4: Running drift-check playbook..."
# Capture playbook output to a temp file for parsing # Capture playbook output to a temp file for parsing
@ -98,9 +145,6 @@ echo ""
# ───────────────────────────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────────────────────────
echo "Step 2/4: Analyzing drift detection results..." echo "Step 2/4: Analyzing drift detection results..."
CHANGED_FILES=()
DRIFT_COUNT=0
# Exit code 0 = synced (all tasks succeeded) # Exit code 0 = synced (all tasks succeeded)
# Exit code non-zero = drift detected (fail task was reached) # Exit code non-zero = drift detected (fail task was reached)
if [ "$DRIFT_RC" -eq 0 ]; then if [ "$DRIFT_RC" -eq 0 ]; then
@ -113,7 +157,6 @@ fi
# Extract structured drifted files from playbook output # Extract structured drifted files from playbook output
# The drift-check.yml playbook outputs: DRIFTED_FILES=file1,file2,file3 # The drift-check.yml playbook outputs: DRIFTED_FILES=file1,file2,file3
# With YAML callback, the output format is: msg: DRIFTED_FILES=...
echo " DEBUG: Searching for DRIFTED_FILES in playbook output..." echo " DEBUG: Searching for DRIFTED_FILES in playbook output..."
if grep -q "DRIFTED_FILES=" "$PLAYBOOK_LOG"; then if grep -q "DRIFTED_FILES=" "$PLAYBOOK_LOG"; then
echo " DEBUG: Found DRIFTED_FILES pattern" echo " DEBUG: Found DRIFTED_FILES pattern"
@ -154,13 +197,6 @@ if grep -q "DRIFTED_FILES=" "$PLAYBOOK_LOG"; then
fi fi
else else
echo " DEBUG: DRIFTED_FILES not found in playbook output" echo " DEBUG: DRIFTED_FILES not found in playbook output"
echo " DEBUG: Attempting to parse from changed task output..."
# Fallback: Look for "changed:" indicators in the playbook output
if grep -q "changed: \[" "$PLAYBOOK_LOG"; then
echo " DEBUG: Found changed tasks, but no structured DRIFTED_FILES output"
echo " DEBUG: This might indicate a playbook output format issue"
fi
fi fi
# Additional validation: If OUT_OF_SYNC but no files found, show warning # Additional validation: If OUT_OF_SYNC but no files found, show warning
@ -171,6 +207,7 @@ fi
echo " Total drift count: $DRIFT_COUNT" echo " Total drift count: $DRIFT_COUNT"
echo "" echo ""
fi
# ───────────────────────────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────────────────────────
# Step 3: Build JSON payload # Step 3: Build JSON payload