How to deploy multinode WordPress on DreamCompute using Ansible

Why Ansible?

Ansible is a configuration management tool that has OpenStack integration built in. This means you can use ansible not only to configure your servers, but when running them on OpenStack, ansible can create and destroy servers for you. Deploying a multinode WordPress site is tedious and long as you can see in the manual tutorial . You can automate all those steps easily with Ansible following the instructions below.

Installing Ansible

In order to install Ansible, you need a few dependencies first, python2, python-virtualenv, and python-pip. In order to install those, run the following.

[user@localhost] sudo apt-get install -y python2 python-virtualenv \
    python-pip

Type in your password for sudo (If you have one). It then will download some packages and install them. Next we need to install Shade and Ansible in a virtual environment, Shade is a library that Ansible uses to talk to OpenStack. In order to do that, run the following.

[user@localhost] virtualenv -p /usr/bin/python2 venv && source \
    venv/bin/activate && pip install ansible && pip install shade

Now you have Shade installed and are ready to start writing Ansible playbooks.

Whenever you want to use Ansible or Shade, you will have to activate the virtual environment that they are in as they are not installed system wide. The way you do that is by running:

[user@localhost] source venv/bin/activate
(venv)[user@localhost]

In order to deactivate the virtual environment, run the following:

(venv)[user@localhost] deactivate
[user@localhost]

Downloading the playbook

Download the Ansible playbook by cloning the OpenStack Ops (osops) repository:

[user@localhost] git clone https://github.com/squidboylan/osops-tools-contrib.git

Configuring the playbook

Navigate to the Ansible playbook by running:

[user@localhost] cd osops-tools-contrib/ansible/lampstack

Edit the vars/dreamhost.yml file and make the following changes:

  • Set the username variable

    username: "DreamCompute username goes here",
    
  • Set the project_name variable

    project_name: "DreamCompute project name goes here",
    

    Note

    Your project name can be found in your OpenRC file

  • Set the public_key_file variable

    public_key_file: "/home/username/.ssh/id_rsa.pub",
    

    Change the path to the path of your public key

Running the playbook

In order to run the playbook, run the following command:

(venv)[user@localhost] ansible-playbook -e \
    "env=dreamhost action=apply password=yourpassword" site.yml

This will create your WordPress site, after it runs, visit the IP address of your balancer, and if everything worked you should see a WordPress site. The full run of the playbook may take 8 - 12 minutes.

In order to delete the site, run the following:

(venv)[user@localhost] ansible-playbook -e \
    "env=dreamhost action=destroy password=yourpassword" site.yml

Extra configuration

There are several configuration changes that can be made to the playbook to modify the WordPress site it creates. Take a look at the “vars/dreamhost.yml” file:

  • stack_size is the variable that defines how many servers to use for your site. The number of webservers you have is stack_size-2.
  • flavor_name is the flavor of server to use for the servers, change this to whatever server flavor you want.
  • volume_size is the size of the volume to put your MySQL database on. A bigger site with more data will need a bigger volume.
  • wp_theme is the WordPress theme to use with the site.
  • wp_title is the title of the WordPress site

The “group_vars/all.yml” file also has some configuration:

  • db_user is the database user that wordpress will use
  • db_pass is the password for the database user that wordpress will use, it also gets used as the admin password for the website. The default setting will generate a random password using ascii characters that is 8 letters long and store it in /tmp/sqlpassword

Did this article answer your questions?

Article last updated .