ansible-role-apache/lamp_haproxy/README.md

67 lines
2.2 KiB
Markdown
Raw Normal View History

LAMP Stack + HAProxy: Example Playbooks
-----------------------------------------------------------------------------
2013-03-12 08:35:13 +01:00
(This example requires Ansible 1.2)
2013-03-12 08:35:13 +01:00
This example is an extension of the simple LAMP deployment. Here we'll install
and configure a web server with an HAProxy load balancer in front, and deploy
an application to the web servers. 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.
You can also optionally configure a Nagios monitoring node.
### Initial Site Setup
First we configure the entire stack by listing our hosts in the 'hosts'
inventory file, grouped by their purpose:
2013-03-12 17:38:26 +01:00
2013-03-12 08:35:13 +01:00
[webservers]
web3
web2
[dbservers]
web3
[lbservers]
2013-03-12 17:15:36 +01:00
lbserver
2013-03-12 17:38:26 +01:00
2013-04-16 01:36:17 +02:00
# an optional nagios node
[monitoring]
nagiosserver
After which we execute the following command to deploy the site:
2013-03-12 17:38:26 +01:00
2013-04-16 01:36:17 +02:00
ansible-playbook -i hosts site.yml
2013-03-12 08:35:13 +01:00
The deployment can be verified by accessing the IP address of your load
balancer host in a web browser: http://<ip-of-lb>:8888. Reloading the page
should have you hit different webservers.
2013-03-12 08:35:13 +01:00
### Removing and Adding a Node
2013-03-12 17:38:26 +01:00
Removal and addition of nodes to the cluster is as simple as editing the
hosts inventory and re-running:
2013-04-08 14:37:55 +02:00
ansible-playbook -i hosts site.yml
### Rolling Update
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.
2013-03-12 08:35:13 +01:00
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:
2013-03-12 17:38:26 +01:00
ansible-playbook -i hosts rolling_update.yml
2013-03-12 08:35:13 +01:00
You can optionally pass: -e webapp_version=xxx to the rolling_update
playbook to specify a specific version of the example webapp to deploy.