From 782e4429c89c6e91cd9aa7e5ba59517a52200dcd Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Thu, 22 Oct 2026 23:12:08 +0300 Subject: feat: add nginx --- roles/nginx/templates/nginx-validate.j2 | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 roles/nginx/templates/nginx-validate.j2 (limited to 'roles/nginx/templates/nginx-validate.j2') diff --git a/roles/nginx/templates/nginx-validate.j2 b/roles/nginx/templates/nginx-validate.j2 new file mode 100644 index 0000000..81c6fb8 --- /dev/null +++ b/roles/nginx/templates/nginx-validate.j2 @@ -0,0 +1,38 @@ +#!/bin/sh + +# {{ ansible_managed }} +# Atomic Nginx configuration validator wrapper for Ansible + +TEMP_FILE="$1" +DEST_FILE="$2" + +if [ -z "$TEMP_FILE" ] || [ -z "$DEST_FILE" ]; then + echo "Usage: nginx-validate " >&2 + exit 1 +fi + +TIMESTAMP=$(date +%Y%m%d-%H%M%S) +BACKUP_FILE="${DEST_FILE}.${TIMESTAMP}.bak" + +# Back up current destination if it exists +if [ -f "$DEST_FILE" ]; then + cp "$DEST_FILE" "$BACKUP_FILE" +fi + +# Apply the rendered temporary file for testing +cp "$TEMP_FILE" "$DEST_FILE" + +# Test master configuration +if nginx -t; then + rm -f "$BACKUP_FILE" + exit 0 +else + # Restore previous config on failure and clean up + if [ -f "$BACKUP_FILE" ]; then + cp "$BACKUP_FILE" "$DEST_FILE" + rm -f "$BACKUP_FILE" + else + rm -f "$DEST_FILE" + fi + exit 1 +fi -- cgit v1.3.1