2.8 KiB
Static Site Host - Ansible playbook
This is an Ansible playbook which allows you to set up a server to serve static sites via Static Web Server. Everything will be ready for your site to be deployed using your CI.
Getting started
Create an file listing the repository host in inventory/hosts
. You shouldn't put every domain that you intend to use as static site in there, only one domain per server.
[static_site_servers]
static.example.org
Create the directory ìnventory/<hostname>/
and then create ìnventory/<hostname>/vars.yml
. In there you will configure your static sites, specifically which user will be created, which domain will be used (can be changed) and the public part of the SSH key your CI will later use. Create them with ssh-keygen
and without a password.
static_sites:
- user: host_1
domain: host_1.example.org
key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMOREPUBLICKEYINFO host_1"
slug: host-1-staging
- user: host_2
domain: host_2.example.org
key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMOREPUBLICKEYINFO host_2"
slug: host-1-prod
You can re-use a user and their key. You can also use different keys per user. Be aware that a shared user or keys will allow any such site to alter all sites that share the user/key.
Now deploy by running
just install-all
In the end you need to setup your CI pipline to deploy to your server. Here is how this would look like for Woodpecker.
---
pipeline:
build:
image: klakegg/hugo:ext
commands:
- hugo
deploy:
image: appleboy/drone-scp
settings:
host:
from_secret: host
username:
from_secret: ssh_user
target:
from_secret: path
source: public/
key:
from_secret: ssh_key
The secrets should be
Key | Example | Description |
---|---|---|
host |
static.example.org |
Hostename of the server where you want to deploy |
ssh_user |
username |
User on the server |
ssh_key |
-----BEGIN OPENSSH PRIVATE KEY----- |
The private SSH key of the user |
path |
/static_sites/USER/public |
Path where to deploy the static files. Deploying means it'll create public in the given path. |