a few more stylistic changes in the lamp_haproxy module

pull/63/head
Tim Gerla 11 years ago
parent 8bd50b81be
commit 45682a567b
  1. 38
      lamp_haproxy/README.md
  2. 2
      lamp_haproxy/group_vars/all
  3. 3
      lamp_haproxy/group_vars/dbservers
  4. 15
      lamp_haproxy/group_vars/lbservers
  5. 4
      lamp_haproxy/group_vars/webservers
  6. 2
      lamp_haproxy/playbooks/add_webservers.yml
  7. 2
      lamp_haproxy/playbooks/db.yml
  8. 2
      lamp_haproxy/playbooks/haproxy.yml
  9. 5
      lamp_haproxy/playbooks/remove_webservers.yml
  10. 3
      lamp_haproxy/playbooks/rolling_update.yml
  11. 2
      lamp_haproxy/playbooks/web.yml
  12. 2
      lamp_haproxy/roles/common/handlers/main.yml
  13. 6
      lamp_haproxy/roles/common/tasks/main.yml
  14. 3
      lamp_haproxy/roles/db/tasks/main.yml
  15. 4
      lamp_haproxy/roles/haproxy/handlers/main.yml
  16. 2
      lamp_haproxy/roles/haproxy/tasks/main.yml
  17. 36
      lamp_haproxy/roles/haproxy/templates/haproxy.cfg.j2.bck
  18. 2
      lamp_haproxy/roles/web/handlers/main.yml
  19. 2
      lamp_haproxy/roles/web/tasks/add_to_lb.yml
  20. 4
      lamp_haproxy/roles/web/tasks/copy_code.yml
  21. 1
      lamp_haproxy/roles/web/tasks/install_httpd.yml
  22. 4
      lamp_haproxy/roles/web/tasks/remove_from_lb.yml
  23. 39
      lamp_haproxy/roles/web/tasks/utils.yml
  24. 2
      lamp_haproxy/roles/web/templates/index.php.j2

@ -1,12 +1,10 @@
Lamp Stack + load balancer(haproxy) + add/remove nodes from cluster + Serial Rolling update of webserserver
----------------------------------------------------------------------------------------------------------
LAMP Stack + HAProxy: Example Playbooks
-----------------------------------------------------------------------------
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:
###Remove a Node
ansible-playbook -i hosts playbooks/remove_webservers.yml --limit=web2
Removal of a node from the cluster is as simple as executing the following command:
ansible-playbook -i hosts playbooks/remove_webservers.yml --limit=web2
###Add a Node
###Adding a node to the cluster.
Adding a node to the cluster can be done by executing the following command:
ansible-playbook -i hosts playbooks/add_webservers.yml --limit=web2
ansible-playbook -i hosts playbooks/add_webservers.yml --limit=web2
###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.
###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:
ansible-playbook -i hosts playbooks/rolling_update.yml

@ -1,5 +1,5 @@
---
# varialbles here would be applicable to all groups
# Variables here are applicable to all host groups
httpd_port: 80
ntpserver: 192.168.1.2

@ -1,5 +1,6 @@
---
# The variables file used by the playbooks in the dbservers group, these dont have to be imported by vars_files: these are autopopulated.
# The variables file used by the playbooks in the dbservers group.
# These don't have to be explicitly imported by vars_files: they are autopopulated.
mysqlservice: mysqld
mysql_port: 3306

@ -1,18 +1,19 @@
---
# File for the HAproxy configuration
# Variables for the HAproxy configuration
# Supports http and tcp, for ssl smtp etc.. use tcp
# HAProxy supports "http" and "tcp". For SSL, SMTP, etc, use "tcp".
mode: http
# port on which the lb should listen
# Port on which HAProxy should listen
listenport: 8888
# A name for the proxy daemon, this would be the suffix in the logs.
# A name for the proxy daemon, this wil be the suffix in the logs.
daemonname: myapplb
# Balancing Algorithm Avalilable options: roundrobin,source,leastconn,source,uri
# (if persistance is required use source)
# Balancing Algorithm. Available options:
# roundrobin, source, leastconn, source, uri
# (if persistance is required use, "source")
balance: roundrobin
# Which Ethernet interface on which the load balancer should listen
# Ethernet interface on which the load balancer should listen
iface: eth0

@ -1,5 +1,5 @@
---
# File for the web server configuration
# Variables for the web server configuration
# Which Ethernet interface on which the web server should listen
# Ethernet interface on which the web server should listen
iface: eth0

@ -1,5 +1,5 @@
---
# This Playbook adds a webserver into the the web cluster
# This Playbook adds a webserver into the the web cluster
- hosts: webservers
user: root

@ -1,5 +1,5 @@
---
# This playbook deploys mysql and configures database on the db node/nodes
# This playbook deploys MySQL and configures the database on the db node(s)
- hosts: dbservers
user: root

@ -1,5 +1,5 @@
---
#PlayBook for haproxy operations
# Playbook for HAProxy operations
- hosts: lbservers
user: root

@ -1,6 +1,7 @@
---
# This Playbook removes a webserver from the pool serialy.
# This playbook removes a webserver from the pool serially.
# Change the value of serial: to adjust the number of servers
# to be removed at a time.
- hosts: webservers
user: root

@ -1,5 +1,6 @@
---
# 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.
- hosts: webservers
user: root

@ -1,5 +1,5 @@
---
# This Playbook deploys the WebServers with httpd and the code.
# This playbook deploys the webservers with httpd and the code.
- hosts: webservers
user: root

@ -1,5 +1,5 @@
---
# Handler to handle common notifications
# Handlers for common notifications
- name: restart ntp
service: name=ntpd state=restarted

@ -1,5 +1,5 @@
---
# This playbook contains common plays that would be run on all Nodes.
# This playbook contains common plays that will run on all nodes.
- name: Install ntp
yum: name=ntp state=present
@ -18,8 +18,4 @@
get_url: url=http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm dest=/tmp/ force=yes
- name: Install EPEL RPM
# command: rpm -Uvh --force /tmp/epel-release-6-8.noarch.rpm
yum: name=/tmp/epel-release-6-8.noarch.rpm state=installed
- name: Clean up
command: rm -f /tmp/epel-release-6-8.noarch.rpm

@ -1,5 +1,5 @@
---
# This playbook will install mysql and create db user and give permissions.
# This playbook will install MySQL and create db user and give permissions.
- name: Install Mysql package
action: yum pkg=$item state=installed
@ -24,7 +24,6 @@
lineinfile: dest=/etc/sysconfig/iptables state=present regexp="$mysql_port" insertafter="^:OUTPUT " line="-A INPUT -p tcp --dport $mysql_port -j ACCEPT"
notify: restart iptables
- name: Create Application Database
mysql_db: name=$dbname state=present

@ -1,5 +1,5 @@
---
# Handlers for the HAproxy
# Handlers for HAproxy
- name: restart haproxy
service: name=haproxy state=restarted
@ -7,5 +7,3 @@
- name: reload haproxy
service: name=haproxy state=reloaded

@ -1,5 +1,5 @@
---
# This PlayBook Installs the HAProxy and configures it.
# This playbook installs HAProxy and configures it.
- name: Download and install haproxy and socat
yum: name=$item state=installed

@ -1,36 +0,0 @@
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user root
group root
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats level admin
defaults
mode {{ mode }}
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
backend app
{% for host in groups['lbservers'] %}
listen {{ daemonname }} {{ hostvars[host].ansible_eth0.ipv4.address }}:{{ listenport }}
{% endfor %}
balance {{ balance }}

@ -1,5 +1,5 @@
---
# Handler for the webtier
# Handler for the web tier
- name: restart iptables
service: name=iptables state=restarted

@ -1,5 +1,5 @@
---
# This Playbook does utility stuff's like adding a webserver into the pool, etc..
# This Playbook handles the addition of a web server to the pool.
- name: Add server to LB
lineinfile: dest=/etc/haproxy/haproxy.cfg state=present regexp="${ansible_hostname}" line="server ${ansible_hostname} ${hostvars.{$inventory_hostname}.ansible_$iface.ipv4.address}:${httpd_port}"

@ -4,7 +4,5 @@
- name: Copy the code from repository
git: repo=${repository} dest=/var/www/html/
- name: Create's the index.php file
- name: Create the index.php file
template: src=../roles/web/templates/index.php.j2 dest=/var/www/html/index.php

@ -9,7 +9,6 @@
- php-mysql
- libsemanage-python
- libselinux-python
- name: insert iptables rule for httpd
lineinfile: dest=/etc/sysconfig/iptables state=present regexp="$httpd_port" insertafter="^:OUTPUT " line="-A INPUT -p tcp --dport $httpd_port -j ACCEPT"

@ -1,9 +1,9 @@
---
# This Playbook does utility stuff's like adding a webserver into the pool, etc..
# This playbook handles the removal of a webserver from the pool.
- name: Remove the code from server
command: rm -rf /var/www/html/*
- name: Remove server from LB
lineinfile: dest=/etc/haproxy/haproxy.cfg state=absent regexp="${ansible_hostname}"
delegate_to: $item

@ -1,39 +0,0 @@
---
# This Playbook does utility stuff's like adding a webserver into the pool, etc..
- name: Add server to LB
lineinfile: dest=/etc/haproxy/haproxy.cfg state=present regexp="${ansible_hostname}" line="server ${ansible_hostname} ${hostvars.{$inventory_hostname}.ansible_$iface.ipv4.address}:${httpd_port}"
delegate_to: ${lbserver}
register: last_run
tags: add
- name: Reload the haproxy
service: name=haproxy state=reloaded
delegate_to: ${lbserver}
only_if: ${last_run.changed}
tags: add
- name: Remove the code from server
command: rm -rf /var/www/html/*
tags: remove
- name: Remove server from LB
lineinfile: dest=/etc/haproxy/haproxy.cfg state=absent regexp="${ansible_hostname}"
delegate_to: $item
with_items: ${groups.lbservers}}
register: last_run
tags: remove
- name: disable the server in haproxy
shell: echo "disable server myapplb/${ansible_hostname}" | socat stdio /var/lib/haproxy/stats
delegate_to: $item
with_items: ${groups.lbservers}}
tags: remove
- name: Remove the httpd package
yum: name=httpd state=absent
tags: remove

@ -7,7 +7,7 @@
<a href=http://{{ hostvars[inventory_hostname]['ansible_' + iface].ipv4.address }}/index.html>Homepage</a>
</br>
<?php
Print "Hello, World! I am configured in Ansible and i am : ";
Print "Hello, World! I am a web server deployed using Ansible and I am : ";
echo exec('hostname');
Print "</BR>";
?>