Go to file
Johannes Rothe 39886f45eb
Caddy: enable active health checks for LB
2023-09-17 13:24:27 +02:00
ansible Caddy: enable active health checks for LB 2023-09-17 13:24:27 +02:00
terraform Add possibility to enable or disable public_ip4 2023-09-15 21:58:02 +02:00
.gitignore Add mysql-replication role 2023-09-12 19:15:41 +02:00
LICENSE Add documentation in README 2023-08-17 22:57:12 +02:00
README.md Update README 2023-09-17 13:01:37 +02:00
Vagrantfile Add glusterfs role 2023-09-05 23:23:08 +02:00
playbook.yaml Deploy terraform from ansible 2023-09-14 21:58:41 +02:00

README.md

Hetzner HA WordPress

This repository contains scripts and configuration files to set up a highly available (HA) WordPress instance on Hetzner Cloud infrastructure. The aim of this project is to provide a robust and scalable solution for hosting a WordPress website with high availability.

Table of Contents

Features

  • Automated deployment of cloud infrastructure via terraform
  • Automated provisioning of the servers with ansible
  • A Hetzner TCP Loadbalancer forwards to the loadbalancer server
  • The loadbalancer server terminates TLS, automatically renews the Let's encrypt certificates and loadbalances requests between application servers using Caddy
  • The replication of wordpress files between machines is done with GlusterFS
  • The MySQL database is running on the loadbalancer for now, since this is the only server allowed to fail

Requirements

Before you begin, ensure you have the following:

  • A Hetzner Cloud account and API token
  • A recent installation of ansible
  • Installed the latest version of the ansible community collection ansible-galaxy collection install community.general
  • A recent installation of terraform

Deployment

The whole deployment is done from one ansible playbook. The playbook deploys the cloud infrastructure with terraform and provisions the different servers. In the end the public IPs are removed with terraform.

Change into the ansible folder

cd ansible

Export the hcloud token as environment variable

export HCLOUD_TOKEN="<your-hcloud-token>"

Write the terraform vault password to a file, to not always having to type the password

echo "<ansible-vault-pass>" > vault_pass

Deploy the infrastructure. This can take several minutes on the first run.

ansible-playbook playbook.yaml --vault-password-file vault_pass

To verify that everything is setup you can use the hcloud CLI.

hcloud server list

You should see three running webservers and one loadbalancer.

Testing

To test the provisioning with ansible, vagrant is used. The secrets are stored in an ansible vault. Vagrant expects them in a password file vault_pass in the root of the repo. This file is not included for obvious reasons. Please ask the project maintainer if you need the vault password.

Launch the virtualboxes inside the repository root folder

vagrant up

For subsequent tests of the playbook run

vagrant provision

To connect to a specific machine run

vagrant ssh web1

Future work

  • Use an external secret provider
  • Store the terraform state remotely
  • Monitoring and alerting

License

Hetzner HA WordPress is licensed under the MIT License.