Ansible: Deploying Web Applications

Intermediate

356 students completed the lab in ~36m

Total available time: 1h:0m

197 students rated this lab!

This Lab is going to keep building on what was covered in the Lab: Getting Started with Ansible.

In this Lab, you will be deploying a simple Python-based web application. This will be a basic LAMP stack, with the P representing Python.

The goal of this Lab is to introduce you to roles, templates, and handlers. Here is a quick refresher on each of these.

 

Roles

Roles are a way to reuse functionality by putting all of the logic for a particular use case in the same place. As an example, if you have tasks that you might run on all servers regardless of what the server is used for, that logic might be put in a role called common.

And if you have logic to configure a web server, then you may have another role named webserver. And whenever you need to install a new web application, you can include these two roles in your playbook.

 

Templates

Templates at their core are a way to copy files to a remote server. However, the difference between templates and static files is that templates will be processed before they are copied to the remote host. This allows you to include variables, conditionals, loops, etc. Ansible uses Jinja2 as its template engine.

 

Handlers

Handlers are basically tasks that are run when some event happens. As an example, if you change a web server’s configuration file, you will need to restart the web server service. This is an ideal use case for handlers.

 

Before you start

Whitespace

This Lab includes YAML and Python, and both are sensitive to whitespace. This means the potential for running into errors caused by copy and paste is higher. It is something to keep in mind as you proceed.

 

Text editor

Nano will be used for editing any text files. However, if you have your own preference you can use it. If you are new to nano, here is the high level info:

Once in nano, you can close out by pressing CTRL+X.

When closing nano, it will prompt you to save if you have made any changes. To do that press the Y key.

If you chose to save, it will ask you for the filename, if the filename is already set, then you can press the Enter/Return key.

That is how we will save files going forward. CTRL+X to close out of nano, then press Y to save, then press Enter to save to the file name listed.

 

Do you have questions about this Lab? Contact our cloud experts by sending an email to support@cloudacademy.com.

Follow these steps to learn by building helpful cloud resources

Logging in to the Amazon Web Services Console

Your first step to start the Lab experience

Connect to a remote shell using an SSH connection with a User

Connect to a remote shell using an SSH Connection with a User

Creating an Ansible role to install a LAMP stack

In the lab “Getting Started with Ansible” everything was put into one playbook. Which works however it makes it more difficult to reuse logic. So now it’s time to start breaking things out into roles.

Setting default variables and using notifications

Most of the time you’ll know what the initial variables for a role should be, and that’s why you can set the defaults. And notifications help to reduce code.

Deploying a web application

This explains how to deploy a Python based web application. It covers setting up the database, getting the code and configuring the web server.