Let's Encrypt SSL Setup

Automatically configures SSL certificates using Let's Encrypt and Certbot

Script Author

Rowan de Haas's avatar
Rowan de Haas
Script Author

Script Details

Created 7 months ago
Size 1 KB

Tags

Script Content

Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#cloud-config
package_update: true
package_upgrade: true

packages:
  - certbot
  - python3-certbot-nginx
  - python3-certbot-apache

write_files:
  - path: /etc/letsencrypt/renewal-hooks/deploy/reload-services.sh
    content: |
      #!/bin/bash
      systemctl reload nginx 2>/dev/null || true
      systemctl reload apache2 2>/dev/null || true
    permissions: '0755'

runcmd:
  # Create SSL certificate (replace example.com with your domain)
  - certbot --nginx --non-interactive --agree-tos --email admin@example.com -d example.com
  # Setup automatic renewal
  - systemctl enable certbot.timer
  - systemctl start certbot.timer
  # Test renewal
  - certbot renew --dry-run

How to Use This Script

Cloud Provider Examples

Amazon EC2

aws ec2 run-instances
  --image-id ami-12345678
  --instance-type t3.micro
  --user-data file://script.yaml

DigitalOcean

doctl compute droplet create
  --image ubuntu-22-04-x64
  --size s-1vcpu-1gb
  --user-data-file script.yaml
  my-droplet

Google Cloud

gcloud compute instances create
  my-instance
  --metadata-from-file
  user-data=script.yaml