diff --git a/lamp_haproxy/group_vars/lbservers b/lamp_haproxy/group_vars/lbservers index ddcda55..042cc35 100644 --- a/lamp_haproxy/group_vars/lbservers +++ b/lamp_haproxy/group_vars/lbservers @@ -1,16 +1,18 @@ --- # File for the HAproxy configuration -#Supports http and tcp, for ssl smtp etc.. use tcp +# Supports http and tcp, for ssl smtp etc.. use tcp mode: http -#port on which the lb should listen +# port on which the lb 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 would 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 Avalilable options: roundrobin,source,leastconn,source,uri +# (if persistance is required use source) balance: roundrobin +# Which Ethernet interface on which the load balancer should listen +iface: eth0 diff --git a/lamp_haproxy/group_vars/webservers b/lamp_haproxy/group_vars/webservers new file mode 100644 index 0000000..fb06515 --- /dev/null +++ b/lamp_haproxy/group_vars/webservers @@ -0,0 +1,5 @@ +--- +# File for the web server configuration + +# Which Ethernet interface on which the web server should listen +iface: eth0 diff --git a/lamp_haproxy/playbooks/haproxy.yml b/lamp_haproxy/playbooks/haproxy.yml index 66c4a1d..76d9edb 100644 --- a/lamp_haproxy/playbooks/haproxy.yml +++ b/lamp_haproxy/playbooks/haproxy.yml @@ -4,6 +4,7 @@ - hosts: lbservers user: root tasks: + - include: ../roles/common/tasks/main.yml - include: ../roles/haproxy/tasks/main.yml handlers: - include: ../roles/haproxy/handlers/main.yml diff --git a/lamp_haproxy/playbooks/web.yml b/lamp_haproxy/playbooks/web.yml index 073dfb6..3c6e9d0 100644 --- a/lamp_haproxy/playbooks/web.yml +++ b/lamp_haproxy/playbooks/web.yml @@ -9,3 +9,4 @@ - include: ../roles/web/tasks/copy_code.yml handlers: - include: ../roles/web/handlers/main.yml + - include: ../roles/common/handlers/main.yml diff --git a/lamp_haproxy/roles/common/tasks/main.yml b/lamp_haproxy/roles/common/tasks/main.yml index 3e1cfec..10fcf6c 100644 --- a/lamp_haproxy/roles/common/tasks/main.yml +++ b/lamp_haproxy/roles/common/tasks/main.yml @@ -14,5 +14,12 @@ service: name=ntpd state=started enabled=true tags: ntp +- name: Download the EPEL repository RPM + 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 diff --git a/lamp_haproxy/roles/haproxy/tasks/main.yml b/lamp_haproxy/roles/haproxy/tasks/main.yml index 8e9a2f6..d5daaa9 100644 --- a/lamp_haproxy/roles/haproxy/tasks/main.yml +++ b/lamp_haproxy/roles/haproxy/tasks/main.yml @@ -1,14 +1,11 @@ --- # This PlayBook Installs the HAProxy and configures it. -- name: Download and install haproxy - command: creates=/opt/haproxy.rpm curl -o /opt/haproxy.rpm ftp://ftp.univie.ac.at/systems/linux/fedora/epel/6/i386/haproxy-1.4.18-1.el6.i686.rpm - -- name: Install the haproxy rpm. - command: creates=/etc/haproxy/haproxy.cfg yum -y localinstall /opt/haproxy.rpm - -- name: Install the socat package for dynamic addition/removal of hosts - yum: name=socat state=installed +- name: Download and install haproxy and socat + yum: name=$item state=installed + with_items: + - haproxy + - socat - name: Open firewall port for haproxy. lineinfile: dest=/etc/sysconfig/iptables state=present regexp="$listenport" insertafter="^:OUTPUT " line="-A INPUT -p tcp --dport $listenport -j ACCEPT" diff --git a/lamp_haproxy/roles/haproxy/templates/haproxy.cfg.j2 b/lamp_haproxy/roles/haproxy/templates/haproxy.cfg.j2 index e39ae5f..b284ce0 100644 --- a/lamp_haproxy/roles/haproxy/templates/haproxy.cfg.j2 +++ b/lamp_haproxy/roles/haproxy/templates/haproxy.cfg.j2 @@ -31,9 +31,9 @@ defaults backend app {% for host in groups['lbservers'] %} - listen {{ daemonname }} {{ hostvars[host].ansible_eth0.ipv4.address }}:{{ listenport }} + listen {{ daemonname }} {{ hostvars[host]['ansible_' + iface].ipv4.address }}:{{ listenport }} {% endfor %} balance {{ balance }} {% for host in groups['webservers'] %} - server {{ hostvars[host].ansible_hostname }} {{ hostvars[host].ansible_eth0.ipv4.address }}:{{ httpd_port }} + server {{ hostvars[host].ansible_hostname }} {{ hostvars[host]['ansible_' + iface].ipv4.address }}:{{ httpd_port }} {% endfor %} diff --git a/lamp_haproxy/roles/web/tasks/add_to_lb.yml b/lamp_haproxy/roles/web/tasks/add_to_lb.yml index a3b7e3d..8d22efb 100644 --- a/lamp_haproxy/roles/web/tasks/add_to_lb.yml +++ b/lamp_haproxy/roles/web/tasks/add_to_lb.yml @@ -2,7 +2,7 @@ # 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} ${ansible_eth0.ipv4.address}:${httpd_port}" + 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: $item with_items: ${groups.lbservers} register: last_run diff --git a/lamp_haproxy/roles/web/tasks/utils.yml b/lamp_haproxy/roles/web/tasks/utils.yml index 5ba4e7a..ac3786f 100644 --- a/lamp_haproxy/roles/web/tasks/utils.yml +++ b/lamp_haproxy/roles/web/tasks/utils.yml @@ -2,7 +2,7 @@ # 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} ${ansible_eth0.ipv4.address}:${httpd_port}" + 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 diff --git a/lamp_haproxy/roles/web/templates/index.php.j2 b/lamp_haproxy/roles/web/templates/index.php.j2 index a8c4dca..5b2183e 100644 --- a/lamp_haproxy/roles/web/templates/index.php.j2 +++ b/lamp_haproxy/roles/web/templates/index.php.j2 @@ -4,7 +4,7 @@
- Homepage + Homepage