Deploy a WordPress Blog in AWS with Ansible (DevOps/Cloud Automation — Part III)

Iyana Garry
3 min readMar 27, 2019

This tutorial will focus on deploying a live site with Ansible. Ansible is another software tool that deploys infrastructure-as-code.

  1. Install the AWS command line interface.

If you’ve been following this tutorial series while using RHEL 7, then you know the drill.

2. Install Ansible.

3. Install Boto.

Boto is a Python interface for AWS. For whatever reason, this needs to be installed in order for Ansible to run your playbook. Otherwise, you will get an error message when executing the playbook.

3. Create an SSH key in AWS.

This will be needed to connect to your EC2 instance directly from your local system.

4. Create an Ansible playbook.

Ansible files are called playbooks.

A major difference between Ansible and other technologies, like Terraform and Chef, is that Ansible will not configure an EC2 instance with the default security group in your AWS account. It needs to be configured with a new security group. So, you have to create one in your playbook.

For the image, I used ami-0dccf86d354af8ce3, which is the image that installs Wordpress on the EC2 instance.

The VPC subnet listed in my playbook, subnet-e8fc2aa4, is my default subnet. You can find your default subnet by running the “aws ec2 describe-subnets” command or going to the VPC dashboard in your AWS account.

The variable for “register” can be anything, as long as it is referenced with “with_items”, which is the last line of code.

Note #1: I see that I accidentally cut off the second-to-last line of code, which says:

wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started

Note #2: You have to use the ‘space’ key instead of the ‘tab’ key to indent. Otherwise, you will get an error message when executing the playbook.

5. Run Ansible.

Run this command to execute your playbook. If you configured your playbook correctly, you won’t see any error messages in red.

In the middle of that glob of green text will be your public IP address. Copy the address and paste it into the URL bar of your browser.

View Part I of this tutorial series on WordPress blog deployment with Terraform.

View Part II of this tutorial series on WordPress blog deployment with Chef.

View Part IV of this tutorial series on WordPress blog deployment with Docker.

--

--