Request Metrics Evergreen

Introducing Request Metrics Evergreen

Get fast performance scores with no website changes!

Episode 10: Installing Redis Using An Ansible Galaxy Role

A pre-built playbook from Ansible Galaxy lets us easily install Redis. (Even we don’t re-invent the wheel every time.) The Request Metrics application will use Redis as its main data store. We need to install Redis on our servers to find out if this is a good plan. Ansible provides a repeatable way of doing this configuration work.

Redis setup takes more steps than just apt-get install redis. Because we really don’t want to learn all the necessary steps, we turn to pre-built role written by David Wittman.

Download Redis Roles With Galaxy

Redis roles are shared through Ansible Galaxy. The davidwittman.redis role is downloaded by running Galaxy from the CLI:

> ansible-galaxy install davidwittman.redis

There is one problem with the above command: it downloads the role to a system wide, shared location. Each developer needs to run the above command before running the playbook. We like our repositories to be standalone when possible. A slightly modified command saves the role locally. This lets us commit it to git:

> ansible-galaxy install davidwittman.redis -p ./roles

Install Redis

Now that the role is downloaded, it can be called from our playbook. The include_role module works well because it packages everything up into a single, self contained task:


---
- hosts: redisHosts

  tasks:
    # Install Redis Using davidwittman.redis Role
    - name: Install single node redis # We will want master/slave or clustering in production
      vars:
        redis_version: 5.0.7          # We want new Redis hotness
        redis_port: 6379              # 6379 is the default port, but we like to be explicit
        redis_bind: 127.0.0.1         # Tells Redis to only accept requests from localhost
      include_role: name=davidwittman.redis
redis-playbook.yml

And we’re done! A bunch of time was saved by using an Ansible Galaxy role written by a stranger on the internet. Next, we’ll code up the Request Metrics application to connect to our fresh Redis instance.