This example is an extension of the simple lamp deployment, In this example we deploy a lampstack with a LoadBalancer in front.
This also has the capability to add/remove nodes from the deployment. It also includes examples to do a rolling update of a stack
without affecting the service.
This example is an extension of the simple LAMP deployment. Here we'll deploy a web server with an HAProxy load balancer in front. This set of playbooks also have the capability to dynamically add and remove web server nodes from the deployment. It also includes examples to do a rolling update of a stack without affecting the service.
###Setup Entire Site.
Firstly we setup the entire stack, configure the 'hosts' inventory file to include the names of your hosts on which the stack would be deployed.
First we configure the entire stack by listing our hosts in the 'hosts' inventory file, grouped by their purpose:
[webservers]
web3
@ -16,26 +14,32 @@ Firstly we setup the entire stack, configure the 'hosts' inventory file to inclu
[lbservers]
lbserver
After which we execute the following command to deploy the site.
After which we execute the following command to deploy the site:
ansible-playbook -i hosts site.yml
The deployment can be verified by accessing the webpage." lynx http://<ip-of-lb>:8888. multiple access should land you up in different webservers.
The deployment can be verified by accessing the IP address of your load balnacer host in a web browser: http://<ip-of-lb>:8888. Reloading the page should have you hit different webservers.
###Remove a node from the cluster.
Removal of a node from the cluster would be as simple as executing the following command:
Rolling updates are the preferred way to update the web server software or deployed application, since the load balancer can be dynamically configured to take the hosts to be updated out of the pool. This will keep the service running on other servers so that the users are not interrupted.
In this example the hosts are updated in serial fashion, which means
that only one server will be updated at one time. If you have a lot of web server hosts, this behaviour can be changed by setting the 'serial' keyword in webservers.yml file.
###Rolling update of the entire site or a single hosts
Rolling updates are the preffered way to do an update as this wont affect the end users, In this example the hosts are updated in serial fashion, which means
that only one server would be updated at one time, this behaviour can be changed by setting the 'serial' keyword in webservers.yml file.
Once the code has been updated in the repository which can be defined in the group_vars/all file, execute the following command:
Once the code has been updated in the source repository for your application which can be defined in the group_vars/all file, execute the following command:
# This Playbook does a rolling update of the code for all webservers serially (one at a time). Change the value of serial: to adjust the number of server to be updated.
# This Playbook does a rolling update of the code for all webservers serially (one at a time).
# Change the value of serial: to adjust the number of server to be updated.
Building a simple LAMP stack and deploying Application using Ansible Playbooks.
-------------------------------------------
This playbooks is meant to be a reference and starters guide to building Ansible Playbooks. These playbooks were tested on Centos 6.x so we recommend Centos to test these modules.
These playbooks are meant to be a reference and starter's guide to building Ansible Playbooks. These playbooks were tested on CentOS 6.x so we recommend that you use CentOS or RHEL to test these modules.
### Installing Ansible
Running this playbook requires setting up Ansible first, luckily this is a very simple process on Centos 6.x:
Running this playbook requires setting up Ansible first. Luckily this is a very simple process on CentOS 6.x:
@ -13,16 +13,16 @@ Running this playbook requires setting up Ansible first, luckily this is a very
cd ansible
source hacking/env-setup
Generate/Synchronize your ssh keys(Optional you can pass -k parameter to prompt for password)
Generate/synchronize your SSH keys (optional you can pass -k parameter to prompt for password)
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
Create a sample inventory file (File containing the hostnames)
Create a sample inventory file. The inventory file contains a grouped list of hostnames that are managed by Ansible. The command below will just add "localhost" to the host list.
echo "localhost" > ansible_hosts
Test if we are setup properly
Test if we are setup properly:
ansible -i ansible_hosts localhost -m ping
localhost | success >> {
@ -31,8 +31,7 @@ Test if we are setup properly
}
Now we setup our Lamp Stack, The stack can be on a single node or multiple nodes. The inventory file 'hosts' defines the nodes in which the stacks should be configured.
Now we set up our LAMP stack. The stack can be on a single node or multiple nodes. The inventory file 'hosts' defines the nodes in which the stacks should be configured.
[webservers]
localhost
@ -40,8 +39,8 @@ Now we setup our Lamp Stack, The stack can be on a single node or multiple nodes
[dbservers]
bensible
Here the webserver would be configured on the localhost and the dbserver on bensible. The stack can be deployed using the following command.
Here the webserver would be configured on the localhost and the dbserver on a server called "bensible". The stack can be deployed using the following command:
ansible-playbook -i hosts site.yml
Once Done, you can check by browsing to http://<ipofhost>/index.php
Once done, you can check the results by browsing to http://localhost/index.php. You should see a simple test page and a list of databases retrieved from the database server.