ansible-playbook-static-sit.../README.md

65 lines
2.6 KiB
Markdown

# Static Site Host - Ansible playbook
This is an [Ansible](https://www.ansible.com/) playbook which allows you to set up a server to serve static sites via [Static Web Server](https://github.com/static-web-server/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.
```yaml
static_sites:
- user: host_1
domain: host_1.example.org
key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMOREPUBLICKEYINFO host_1"
- user: host_2
domain: host_2.example.org
key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMOREPUBLICKEYINFO host_2"
```
Now deploy by running
```zsh
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](https://woodpecker-ci.org/).
```yaml
---
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. |