Learning Experiments
Introduction
Here is a series of progressive experiments to familiarize you with Ansible while constructing your target Rails application infrastructure.
Prerequisites
- An AWS account with necessary permissions.
- Basic familiarity with command-line tools.
- Python and Ansible installed on your local machine.
Experiment 1
Installing PostgreSQL with Ansible
Goal: Learn Ansible basics by writing a playbook to configure an existing server.
- Setup Ansible: Install Ansible on your local machine.
- Ansible Inventory: Create a simple inventory file specifying the public IP address of your EC2 instance.
- Ansible Playbook: Write a basic Ansible playbook to:
- Connect to your EC2 instance.
- Become root (use privilege escalation).
- Install PostgreSQL.
- Start the PostgreSQL service.
- Run the Playbook: Execute the playbook with
ansible-playbook
against an existing EC2 server. Test you can connect to PostgreSQL from your local machine.
Experiment 2
Puma Configuration using Ansible
- Puma Service Setup: Continue playbook additions to:
- Configure a Puma service file (systemd).
- Ensure Puma starts on boot and is accessible within the EC2 instance.
Designing experiments to build prototypes incrementally with Packer, Terraform, and Ansible allows for a structured learning approach. Each step will introduce new concepts and build upon the previous ones, ultimately leading to the provisioning of an EC2 server for a Rails application with Postgres and Puma.
Experiment 3
Ansible for Application Deployment
Goal: Use Ansible to deploy a simple Rails application.
- Develop a Rails App: Create a basic Rails application locally or use an existing one.
- Create a Playbook: Write an Ansible playbook to deploy the Rails application, ensuring Ruby, Rails, and Puma are installed and configured.
- Run the Playbook: Execute the playbook against the server provisioned in Experiment 5.
Experiment 4
Rails Application Setup using Ansible
Goal: Expand the previous experiment to include Postgres and configure Puma as the application server.
Expand Ansible Playbook: Augment your playbook to:
- Install Postgres, configure the database, and ensure Puma is set up as the application server for your Rails app.
- Install Puma and required Rails dependencies.
- Create a dedicated deploy user for your Rails application.
- Clone your Rails app repository onto the server under the Rails user.
- Perform pre-deployment tasks like
bundle install
.
Deploy: Run the updated playbook to deploy the Rails application on your server.
Conclusion
Through these experiments, you’ll progressively build knowledge and skills in using Ansible. Starting with simple tasks and gradually increasing the complexity allows you to understand how these tools can be integrated to automate the deployment and management of a Rails application on AWS EC2 with Postgres as the database and Puma as the application server.