Some various fixups and interface name handling.

- Add 'iface' group variable to specify the network interface on which the
  systems should listen.
- Add a couple of missing playbook inclusions
- Set up EPEL on all hosts for socat and haproxy
pull/63/head
Tim Gerla 11 years ago
parent 07387a29fd
commit af427cad37
  1. 12
      lamp_haproxy/group_vars/lbservers
  2. 5
      lamp_haproxy/group_vars/webservers
  3. 1
      lamp_haproxy/playbooks/haproxy.yml
  4. 1
      lamp_haproxy/playbooks/web.yml
  5. 9
      lamp_haproxy/roles/common/tasks/main.yml
  6. 13
      lamp_haproxy/roles/haproxy/tasks/main.yml
  7. 4
      lamp_haproxy/roles/haproxy/templates/haproxy.cfg.j2
  8. 2
      lamp_haproxy/roles/web/tasks/add_to_lb.yml
  9. 2
      lamp_haproxy/roles/web/tasks/utils.yml
  10. 2
      lamp_haproxy/roles/web/templates/index.php.j2

@ -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

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

@ -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

@ -9,3 +9,4 @@
- include: ../roles/web/tasks/copy_code.yml
handlers:
- include: ../roles/web/handlers/main.yml
- include: ../roles/common/handlers/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

@ -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"

@ -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 %}

@ -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

@ -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

@ -4,7 +4,7 @@
</head>
<body>
</br>
<a href=http://{{ ansible_eth0.ipv4.address }}/index.html>Homepage</a>
<a href=http://{{ hostvars[ansible_hostname]['ansible_' + iface].ipv4.address }}/index.html>Homepage</a>
</br>
<?php
Print "Hello, World! I am configured in Ansible and i am : ";