I maintain a repo for deployment files of this blog. It already uses Ansible, and Terraform to deploy this instance of Ghost. The only issue is that it uses the unofficial Docker image of Ghost to deploy the instance. I wanted to updated my deployment to use the Ghost recommended infrastructure. This meant, for one, an Ubuntu server with NodeJS 18, and using the Ghost CLI to deploy the actual Ghost instance. I wanted to go one step further and deploy a separate VM for the MySQL database so I can maintain the Ghost instance independently of the database.
Terraform spec updates
The update to the spec file are pretty predictable. I simply added two different servers with lower CPU and RAM configurations. One gigabyte of RAM and one CPU should be enough for most instance of Ghost. Especially with caching implemented.
Referral link
Playbook update
The Ansible playbook contains the bulk of the changes for this update. The first significant change was to remove the Docker dependency and all tasks that used Docker to deploy Ghost. While this method of deployment was working fine, it did take more resources than necessary and is not officially supported by Ghost. I then added the MySQL and NodeJS Ansible roles from Geerlingguy. The MySQL role exposes the variables needed to setup the database for Ghost, and NodeJS role is used to install the Ghost supported version of NodeJS.
The main updates were made in my custom Ghost role tasks. Instead of simply copying the compose file to the server and running the docker-compose command, there is some setup required to run the Ghost CLI. After creating the custom ghost user, I had to create a custom sudoers file to allow the custom ghost user sudo privileges without a password. This, passwordless sudo, functionality is required to complete the ghost installation without human intervention.
After running the Terraform plan, and the playbook, everything should install without human interaction. You can find the full source code in the repo below.
Future changes
I will be updating the repo with a couple of new features soon:
Ability to update installed instance of Ghost
Firewall rules to block public access to the DB server