Today I added a WordPress blog to my site…and it was pretty good.

Today I added a WordPress blog to my site…cool story bro.

I wanted to bolt a blog on to my existing site over running a separate WordPress instance. The reason for this was basically to increase my skills with GCP, ansible, PHP, Python and MySQL.

If all you are after is to get a WordPress site up and running, then its probably much easier to go with the GCP Marketplace WP instance and walk away. I initially tried this and it was almost too easy. You more or less fill out a form and its built for you, and all of the automation behind this is available and unit tested.

That being said my work is not fully absent of a quest for shortcuts. I played with the Google Marketplace instance, a canned WP ansible role, and installing WP manually. At this point I don’t remember what I ended with, but it didn’t matter once I learned how to deploy the existing site repeatably. The key here was two google buckets, one for the WP content files, and another for a restorable database dump.

Here is how this site is built and deployed:

The site is deployed across two Google Cloud instances. The first runs nginx and PHP. It serves a static webpage, as well as the WordPress site. The second is a database instance.

The two instances are fully orchestrated using ansible. When you run the playbook, it builds the two instances, and deploys roles to them.

The playbook pulls the static/wordpress content, along with a database dump from Google Storage buckets.

To facilitate updates and repeatability, a python script is used to keep the buckets updated.

Security??…Gosh I hope so.
Our variables are encrypted using Ansible Vault. Whats cool is under the hood, we use a private-key file to encrypt everything…no passphrase at command line:

Deploying to Google Cloud using Ansible.

Here is the primary playbook:

Here is the directory structure that ansible uses:

This python script is run to keep the content and database updated off platform. You run this after making live changes to maintain repeatability:

Python script …for the boys:   wp_db_gb_sync.py