2 min read

Blog Automation Using Terraform and Ansible

How did I automate this site using Terraform, Ansible, and Ghost?
Blog Automation Using Terraform and Ansible

So I guess I should begin with some basics. First, I need a place where I can document my work that goes on here, amongst my other projects. After a short search on awesome-selfhosted I decided upon using Ghost as a blogging platform.

Ghost does a great job documenting the install process on their docs site! I spun up a quick Ubuntu EC2 and tested the process just to ensure it worked without any additional steps- and to my surprise, it did!

Ansible

My goal was to automate as much of the provisioning and configuration as possible, within reason, and not create much overhead or complexities. I quickly created an Ansible playbook to take care of all the steps from Ghost's install guide, excluding the final ```ghost install```. Great, the playbook does all the server setup, but what about the infrastructure?

Terraform

This was the easy part! At its core we're only creating a single EC2 instance, a Route53 record, and then some ancillary items like a DLM job to take a snapshot of our EBS volume every night (more on this later). The only interesting part of the Terraform is how we zip the Ansible directory and upload it to S3, then pull it down in the user_data. Otherwise, this is just your standard fare for creating any type of infrastructure in AWS.

Gotchas

As with any project like this you're going to run into some things you didn't anticipate. For me this was related to the ``` ghost install ``` setup process. For the simplicity of it all, I followed the install instructions, but the cloud engineer in me knows that we should be separating the software, configuration and data store. If this was at my place of employment I would have the mysql data on its own VM, or even better, RDS instance that does routine backups with no guessing. There are many reasons to use RDS, and maybe one day I will- but like I mentioned, for the simplicity of it all I stuck to the install guide. Another thing I would love to do is separate the ghost install onto a different mount, and not the root volume. This is a no brainer, but without dissecting the install, I put it on the root volume, and just take a snapshot everyday. So in the event of a disaster its a pretty pain free to create an AMI from the snapshot and just create a new EC2.

Coming next- plane. How else am I going to keep track of my projects/stories.