DEV Community

Ismail Bouaziz
Ismail Bouaziz

Posted on

I Tested an AI That Deploys and Verifies Nginx on Real VMs

Infrastructure automation is a core part of the DevOps role. However, most AI-based tools still stop at one stage: code generation. Execution, monitoring, and validation are often left to the engineer.

I tested an AI-driven DevOps solution that takes a different approach: it generates a script, executes it on a real virtual machine, and automatically verifies the result.

This article shares a hands-on experience based on a concrete and realistic scenario.

The scenario I tested

The test focuses on a common system administration and DevOps task:

Setting up Nginx with Basic Authentication on Ubuntu using a Bash script.
The scenario includes:

  • Installing Nginx
  • Creating users with htpasswd
  • Protecting a specific path with basic authentication
  • Testing access with and without credentials
  • Verifying that unauthorized requests return HTTP 401

Even though this setup looks simple, it involves multiple layers: system configuration, security, services, and validation.

Execution triggered by a prompt

The entire workflow is launched using a single natural language prompt.

Once the prompt is submitted, the tool:

  • automatically starts a real Ubuntu VM
  • generates a Bash script tailored to the scenario
  • executes the script on the VM
  • provides a Grafana link to visualize the execution in real time

This link gives access to a detailed dashboard showing each phase: VM startup, script generation, execution, and final validation.

Execution monitoring dashboard

Execution visibility and metrics

The Grafana dashboard provides clear visibility into how the scenario runs.

It allows you to track:

  • VM startup time
  • AI generation time
  • Script execution duration
  • Status of each step

In this test:

  • the VM started in less than a second
  • the full execution completed in about 23 seconds
  • the scenario succeeded on the first iteration

Automatic result verification

The tool doesn’t stop at script execution.

It actively verifies that:

  • Nginx is installed and running
  • the protected directory exists
  • authentication is properly enforced
  • unauthenticated requests return 401 Unauthorized
  • authenticated requests can access the protected content

Execution output and validation summary

Generated Bash script

#!/bin/bash
set -e

# Suppress interactive prompts
export NEEDRESTART_MODE=a
export NEEDRESTART_SUSPEND=1
export DEBIAN_FRONTEND=noninteractive

echo "=========================================="
echo "Nginx Basic Authentication Setup"
echo "=========================================="

# Wait for any existing apt locks
echo "Waiting for apt lock to be released..."
while sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; do
  sleep 2
done

# 1. Update package cache
echo ""
echo "Step 1: Updating package cache..."
sudo apt-get update
echo "✓ Package cache updated"

# 2. Install nginx package
echo ""
echo "Step 2: Installing Nginx..."
sudo apt-get install -y nginx
echo "✓ Nginx installed"

# 3. Install apache2-utils package
echo ""
echo "Step 3: Installing apache2-utils..."
sudo apt-get install -y apache2-utils
echo "✓ apache2-utils installed"

# 4. Start nginx service
echo ""
echo "Step 4: Starting Nginx service..."
sudo systemctl start nginx
sudo systemctl enable nginx
echo "✓ Nginx service started and enabled"

# 5. Create protected directory
echo ""
echo "Step 5: Creating protected directory..."
sudo mkdir -p /var/www/html/protected
echo "✓ Protected directory created"

# 6. Create index.html file in protected directory
echo ""
echo "Step 6: Creating index.html in protected directory..."
sudo tee /var/www/html/protected/index.html > /dev/null <<'EOF'
<!DOCTYPE html>
<html>
<head>
    <title>Protected Content</title>
</head>
<body>
    <h1>Welcome to Protected Area</h1>
    <p>This content is protected by basic authentication.</p>
    <p>If you can see this, you have successfully authenticated.</p>
</body>
</html>
EOF
echo "✓ index.html created"

# 7. Create htpasswd file with test user
echo ""
echo "Step 7: Creating htpasswd file..."
sudo htpasswd -bc /etc/nginx/.htpasswd testuser testpass123
echo "✓ htpasswd file created with testuser:testpass123"

# 8. Configure nginx with basic authentication
echo ""
echo "Step 8: Configuring Nginx with basic authentication..."
sudo tee /etc/nginx/sites-available/default > /dev/null <<'EOF'
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name _;

    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
        try_files "color:#9CDCFE">$uri "color:#9CDCFE">$uri/ =404;
    }

    location /protected {
        auth_basic "Restricted Area";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }
}
EOF
echo "✓ Nginx configuration updated"

# 9. Test nginx configuration syntax
echo ""
echo "Step 9: Testing Nginx configuration syntax..."
sudo nginx -t
echo "✓ Nginx configuration is valid"

# Restart nginx service
echo ""
echo "Step 10: Restarting Nginx service..."
sudo systemctl restart nginx
echo "✓ Nginx service restarted"

# Verification
echo ""
echo "=========================================="
echo "Verification Tests"
echo "=========================================="

# Wait for nginx to be ready
sleep 2

# Test 1: Access without credentials (should return 401)
echo ""
echo "Test 1: Accessing /protected without credentials..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost/protected/)
if [ "">$HTTP_CODE" = "401" ]; then
    echo "✓ Got HTTP 401 (Unauthorized) - correct behavior"
else
    echo "✗ Expected HTTP 401, got HTTP ">$HTTP_CODE"
    exit 1
fi

# Test 2: Access with valid credentials (should return 200)
echo ""
echo "Test 2: Accessing /protected with valid credentials..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -u testuser:testpass123 http://localhost/protected/)
if [ "">$HTTP_CODE" = "200" ]; then
    echo "✓ Got HTTP 200 (OK) - authentication successful"
else
    echo "✗ Expected HTTP 200, got HTTP ">$HTTP_CODE"
    exit 1
fi

# Test 3: Display content with valid credentials
echo ""
echo "Test 3: Retrieving protected content with valid credentials..."
echo "Content retrieved:"
echo "---"
curl -s -u testuser:testpass123 http://localhost/protected/index.html
echo ""
echo "---"

echo ""
echo "=========================================="
echo "✓ All tests passed!"
echo "=========================================="
echo ""
echo "Summary:"
echo "- Nginx installed and running"
echo "- Basic authentication configured"
echo "- Protected directory: /var/www/html/protected"
echo "- Credentials: testuser / testpass123"
echo "- Test with: curl -u testuser:testpass123 http://localhost/protected/"
Enter fullscreen mode Exit fullscreen mode

What this changes for DevOps work

This approach reshapes how automation tasks are handled.

Instead of spending time writing scripts, fixing errors, rerunning commands, and manually testing each step, DevOps engineers can focus directly on the final outcome. The real behavior of the infrastructure becomes the central concern: does the service work as expected, is security correctly applied, and does the result match the requirements?

This workflow is especially effective for use cases such as proofs of concept, test environments, technical demonstrations, and learning scenarios. In these contexts, the time savings are tangible, and the value lies in validation rather than script authoring.

Final thoughts

This test shows that AI can now go beyond simple script generation and deliver functional, observable, and verified infrastructure.

For DevOps teams, this opens the door to a new way of working, where the focus shifts from automation mechanics to rapid validation of real infrastructure outcomes.

Check it out at antrieb.sh.
Join the community: Discord

Top comments (0)