Script icon
If icon
Commands icon
AnsibleCLI icon
SlackIncomingWebhook icon
Log icon
Schedule icon

Automated TLS Certificate Renewal and Ansible Fleet Rollout Gate

Autonomous TLS certificate renewal gate. Probes expiry, issues fresh certificates, rolls out to server fleets via Ansible, and verifies live endpoints.

Categories
CloudInfrastructure

In enterprise infrastructure environments, web servers and reverse proxies (Nginx, HAProxy, Apache) across multi-node server fleets host TLS certificates that require periodic renewal. While tools like Certbot or internal PKIs issue renewed certificates, the operational rollout (distributing keypairs across servers, verifying web server configuration syntax, performing zero-downtime daemon reloads, and confirming that external clients actually receive the updated certificate) is frequently executed manually via ad-hoc SSH loops or unmonitored scripts. When manual steps are missed or daemon reloads fail, expired certificates cause widespread browser security warnings and broken API integrations.

This blueprint implements a closed-loop reliability gate for TLS certificate lifecycle management. It probes live endpoints over port 443 to extract certificate expiration dates, triggers automated renewal when remaining validity drops below configurable thresholds, executes rolling fleet deployments via Ansible (io.kestra.plugin.ansible.cli.AnsibleCLI), validates web server syntax before graceful daemon reload, and runs post-deployment TLS verification handshakes to confirm that the new certificate is actively served.

How it works

  1. probe_tls_certificate (io.kestra.plugin.scripts.python.Script) establishes an SSL socket connection to the target domain on port 443, extracts notAfter expiration timestamps, and calculates remaining validity days.
  2. evaluate_renewal_threshold (io.kestra.plugin.core.flow.If) evaluates whether remaining days breach expiry_threshold_days.
  3. stage_certificate_bundle (io.kestra.plugin.scripts.shell.Commands) verifies cryptographic keypair formatting and intermediate CA chains.
  4. ansible_fleet_rollout (io.kestra.plugin.ansible.cli.AnsibleCLI) executes an Ansible playbook across target inventory hosts to deploy the certificate bundle, test web server configuration syntax (nginx -t), and execute graceful daemon reloads.
  5. verify_post_deployment_tls (io.kestra.plugin.scripts.python.Script) performs a live post-rollout handshake to verify that clients are actively served the renewed certificate with extended validity.
  6. notify_rollout_slack (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) dispatches an itemized deployment scorecard to Slack.

What you get

  • Closed-loop automation bridging certificate expiration detection, fleet deployment, and live verification.
  • Safe-by-default execution with dry-run protection (--check mode) to validate playbooks before active host mutation.
  • Automated configuration syntax testing before service reload to prevent broken web server restarts.
  • Real-time Slack notifications summarizing deployment changes and certificate validity extensions.

Who it's for

  • Platform Engineers and System Administrators maintaining bare-metal or VM web server fleets.
  • Site Reliability Engineers eliminating manual certificate renewal checklists and expired cert outages.
  • DevSecOps teams establishing automated, verifiable TLS compliance governance.

Why orchestrate this with Kestra

Coordinating TLS certificate lifecycle management requires uniting network socket probing, declarative flow branching, configuration management tooling (Ansible), and chatops alerting into an auditable workflow. Kestra provides scheduled triggers, containerized task runners, and unified execution lineage out of the box.

Pitfalls

  • Configuration syntax errors: A flawed web server configuration can crash during reload; the flow executes syntax validation (nginx -t or haproxy -c) before triggering daemon reloads.
  • Intermediate CA bundle truncation: Client browsers reject certificates if intermediate trust chains are omitted; ensure fullchain bundles (cert + intermediate) are staged.
  • Split-horizon DNS: Ensure internal worker probes target the same public VIP or SNI host headers that external clients connect to.
  • Private key permissions: Ensure private keys deployed by Ansible are restricted to 0600 root permissions on target servers.

Prerequisites

  • Reachable target web server fleet accessible via Ansible SSH credentials.
  • Ansible inventory and SSH private key configured in Kestra secrets.
  • Slack incoming webhook endpoint for operational notifications.

Secrets

  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for dispatching fleet deployment cards.
  • ANSIBLE_SSH_KEY: SSH private key for connecting to fleet inventory hosts.

Quick start

  1. Execute the flow with dry_run: true to observe live certificate expiration probing and Ansible --check syntax validation.
  2. Point domain_name and inventory_content at your real server fleet and set dry_run: false for active certificate rollout.
  3. Enable the weekly schedule trigger for continuous automated Monday morning certificate audits.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.