pull/63/head
bennojoy 11 years ago
parent 61186b3e04
commit c7dca761e6
  1. 10
      lamp_haproxy/roles/add_webservers.yml
  2. 11
      lamp_haproxy/roles/db.yml
  3. 6
      lamp_haproxy/roles/dbtier/handlers/main.yml
  4. 32
      lamp_haproxy/roles/dbtier/tasks/install_mysql.yml
  5. 11
      lamp_haproxy/roles/dbtier/templates/my.cnf.j2
  6. 10
      lamp_haproxy/roles/haproxy.yml
  7. 19
      lamp_haproxy/roles/haproxy/tasks/install_haproxy.yml
  8. 9
      lamp_haproxy/roles/remove_webservers.yml
  9. 8
      lamp_haproxy/roles/rolling_update.yml
  10. 11
      lamp_haproxy/roles/web.yml
  11. 5
      lamp_haproxy/roles/webtier/handlers/main.yml
  12. 15
      lamp_haproxy/roles/webtier/tasks/add_to_lb.yml
  13. 10
      lamp_haproxy/roles/webtier/tasks/copy_code.yml
  14. 26
      lamp_haproxy/roles/webtier/tasks/install_httpd.yml
  15. 23
      lamp_haproxy/roles/webtier/tasks/remove_from_lb.yml
  16. 22
      lamp_haproxy/roles/webtier/tasks/rolling_update.yml
  17. 39
      lamp_haproxy/roles/webtier/tasks/utils.yml
  18. 16
      lamp_haproxy/roles/webtier/templates/index.php.j2
  19. 13
      lamp_simple/README.md
  20. 6
      lamp_simple/hosts
  21. 2
      lamp_simple/roles/common/tasks/main.yml
  22. 11
      lamp_simple/roles/db.yml
  23. 6
      lamp_simple/roles/dbtier/handlers/main.yml
  24. 32
      lamp_simple/roles/dbtier/tasks/install_mysql.yml
  25. 11
      lamp_simple/roles/dbtier/templates/my.cnf.j2
  26. 11
      lamp_simple/roles/web.yml
  27. 5
      lamp_simple/roles/webtier/handlers/main.yml
  28. 10
      lamp_simple/roles/webtier/tasks/copy_code.yml
  29. 26
      lamp_simple/roles/webtier/tasks/install_httpd.yml
  30. 24
      lamp_simple/roles/webtier/templates/index.php.j2
  31. 4
      lamp_simple/site.yml

@ -1,10 +0,0 @@
---
# This Playbook adds a webserver into the the web cluster
- hosts: webservers
user: root
serial: 1
tasks:
- include: ../roles/webtier/tasks/install_httpd.yml
- include: ../roles/webtier/tasks/copy_code.yml
- include: ../roles/webtier/tasks/add_to_lb.yml

@ -1,11 +0,0 @@
---
# This playbook deploys mysql and configures database on the db node/nodes
- hosts: dbservers
user: root
tasks:
- include: common/tasks/main.yml
- include: dbtier/tasks/install_mysql.yml
handlers:
- include: dbtier/handlers/main.yml
- include: common/handlers/main.yml

@ -1,6 +0,0 @@
---
# Handler to handle DB tier notifications
- name: restart mysql
service: name=mysqld state=restarted

@ -1,32 +0,0 @@
---
# This playbook will install mysql and create db user and give permissions.
- name: Install Mysql package
action: yum pkg=$item state=installed
with_items:
- mysql-server
- MySQL-python
- libselinux-python
- libsemanage-python
- name: Configure SELinux to start mysql on any port
seboolean: name=mysql_connect_any state=true persistent=yes
- name: Create Mysql configuration file
action: template src=dbtier/templates/my.cnf.j2 dest=/etc/my.cnf
notify:
- restart mysql
- name: Start Mysql Service
service: name=mysqld state=started enabled=true
- name: insert iptables rule
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
- name: Create Application DB User
mysql_user: name=$dbuser password=$upassword priv=*.*:ALL host='%' state=present

@ -1,11 +0,0 @@
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
port={{ mysql_port }}
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

@ -1,10 +0,0 @@
---
#PlayBook for haproxy operations
- hosts: lbservers
user: root
tasks:
- include: haproxy/tasks/install_haproxy.yml
handlers:
- include: haproxy/handlers/main.yml
- include: common/handlers/main.yml

@ -1,19 +0,0 @@
---
# 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: 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"
notify: restart iptables
- name: Configure the haproxy cnf file with hosts
template: src=haproxy/templates/haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg
notify: restart haproxy

@ -1,9 +0,0 @@
---
# This Playbook removes a webserver from the pool serialy.
- hosts: webservers
user: root
serial: 1
tasks:
- include: ../roles/webtier/tasks/remove_from_lb.yml

@ -1,8 +0,0 @@
---
# 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
serial: 1
tasks:
- include: ../roles/webtier/tasks/rolling_update.yml

@ -1,11 +0,0 @@
---
# This Playbook deploys the WebServers with httpd and the code.
- hosts: webservers
user: root
tasks:
- include: common/tasks/main.yml
- include: webtier/tasks/install_httpd.yml
- include: webtier/tasks/copy_code.yml
handlers:
- include: webtier/handlers/main.yml

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

@ -1,15 +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} ${ansible_eth0.ipv4.address}:${httpd_port}"
delegate_to: $item
with_items: ${groups.lbservers}
register: last_run
- name: Reload the haproxy
service: name=haproxy state=reloaded
delegate_to: $item
with_items: ${groups.lbservers}
only_if: ${last_run.changed}

@ -1,10 +0,0 @@
---
# This Playbook is responsible for copying the latest dev/production code from the version control system.
- name: Copy the code from repository
git: repo=${repository} dest=/var/www/html/
- name: Create's the index.php file
template: src=webtier/templates/index.php.j2 dest=/var/www/html/index.php

@ -1,26 +0,0 @@
---
# This playbook installs http and the php modules.
- name: Install http and php etc
action: yum name=$item state=installed
with_items:
- httpd
- php
- 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"
register: last_run
- name: Apply iptable rule
service: name=iptables state=restarted
only_if: ${last_run.changed}
- name: http service state
service: name=httpd state=started enabled=yes
- name: Configure SELinux to allow httpd to connect to remote database
seboolean: name=httpd_can_network_connect_db state=true persistent=yes

@ -1,23 +0,0 @@
---
# This Playbook does utility stuff's like adding a webserver into the pool, etc..
- 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
with_items: ${groups.lbservers}
register: last_run
- 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}
- name: Remove the httpd package
yum: name=httpd state=absent

@ -1,22 +0,0 @@
---
# This Playbook implements a rolling update on the infrastructure, change the value of the serial keyword to specify the number of servers the update should happen.
- name: Remove the code from server
command: rm -rf /var/www/html/*
- 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}
- name: Copy the code from repository
git: repo=${repository} dest=/var/www/html/
- name: Create's the index.php file
template: src=webtier/templates/index.php.j2 dest=/var/www/html/index.php
- name: Enable the server in haproxy
shell: echo "enable server myapplb/${ansible_hostname}" | socat stdio /var/lib/haproxy/stats
delegate_to: $item
with_items: ${groups.lbservers}

@ -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} ${ansible_eth0.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

@ -1,16 +0,0 @@
<html>
<head>
<title>Ansible Application</title>
</head>
<body>
</br>
<a href=http://{{ ansible_eth0.ipv4.address }}/index.html>Homepage</a>
</br>
<?php
Print "Hello, World! I am configured in Ansible and i am : ";
echo exec('hostname');
Print "</BR>";
?>
</body>
</html>

@ -42,17 +42,6 @@ Now we setup our Lamp Stack, The stack can be on a single node or multiple nodes
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 bensible. The stack can be deployed using the following command.
ansible-playbook -i hosts site.yml ansible-playbook -i hosts site.yml
Once Done, you can check by browsing to http://<ipofhost>/index.php Once Done, you can check by browsing to http://<ipofhost>/index.php
If you want to add a new webserver to the stack it would be as simple as changing the hosts file to add the new webserver name and rerun the above command.
[webservers]
localhost
webserver1
[dbservers]
bensible
ansible-playbook -i hosts site.yml

@ -1,5 +1,7 @@
[webservers] [webservers]
web2 web3
[dbservers] [dbservers]
web3 web2

@ -6,7 +6,7 @@
tags: ntp tags: ntp
- name: Configure ntp file - name: Configure ntp file
template: src=common/templates/ntp.conf.j2 dest=/etc/ntp.conf template: src=../roles/common/templates/ntp.conf.j2 dest=/etc/ntp.conf
tags: ntp tags: ntp
notify: restart ntp notify: restart ntp

@ -1,11 +0,0 @@
---
# This playbook deploys mysql and configures database on the db node/nodes
- hosts: dbservers
user: root
tasks:
- include: common/tasks/main.yml
- include: dbtier/tasks/install_mysql.yml
handlers:
- include: dbtier/handlers/main.yml
- include: common/handlers/main.yml

@ -1,6 +0,0 @@
---
# Handler to handle DB tier notifications
- name: restart mysql
service: name=mysqld state=restarted

@ -1,32 +0,0 @@
---
# This playbook will install mysql and create db user and give permissions.
- name: Install Mysql package
action: yum pkg=$item state=installed
with_items:
- mysql-server
- MySQL-python
- libselinux-python
- libsemanage-python
- name: Configure SELinux to start mysql on any port
seboolean: name=mysql_connect_any state=true persistent=yes
- name: Create Mysql configuration file
action: template src=dbtier/templates/my.cnf.j2 dest=/etc/my.cnf
notify:
- restart mysql
- name: Start Mysql Service
service: name=mysqld state=started enabled=true
- name: insert iptables rule
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
- name: Create Application DB User
mysql_user: name=$dbuser password=$upassword priv=*.*:ALL host='%' state=present

@ -1,11 +0,0 @@
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
port={{ mysql_port }}
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

@ -1,11 +0,0 @@
---
# This Playbook deploys the WebServers with httpd and the code.
- hosts: webservers
user: root
tasks:
- include: common/tasks/main.yml
- include: webtier/tasks/install_httpd.yml
- include: webtier/tasks/copy_code.yml
handlers:
- include: webtier/handlers/main.yml

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

@ -1,10 +0,0 @@
---
# This Playbook is responsible for copying the latest dev/production code from the version control system.
- name: Copy the code from repository
git: repo=${repository} dest=/var/www/html/
- name: Create's the index.php file
template: src=webtier/templates/index.php.j2 dest=/var/www/html/index.php

@ -1,26 +0,0 @@
---
# This playbook installs http and the php modules.
- name: Install http and php etc
action: yum name=$item state=installed
with_items:
- httpd
- php
- 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"
register: last_run
- name: Apply iptable rule
service: name=iptables state=restarted
only_if: ${last_run.changed}
- name: http service state
service: name=httpd state=started enabled=yes
- name: Configure SELinux to allow httpd to connect to remote database
seboolean: name=httpd_can_network_connect_db state=true persistent=yes

@ -1,24 +0,0 @@
<html>
<head>
<title>Ansible Application</title>
</head>
<body>
</br>
<a href=http://{{ ansible_eth0.ipv4.address }}/index.html>Homepage</a>
</br>
<?php
Print "Hello, World! I am configured in Ansible and i am : ";
echo exec('hostname');
Print "</BR>";
echo "List of Databases: </BR>";
{% for host in groups['dbservers'] %}
$link = mysql_connect('{{ hostvars[host].ansible_eth0.ipv4.address }}', '{{ hostvars[host].dbuser }}', '{{ hostvars[host].upassword }}') or die(mysql_error());
{% endfor %}
$res = mysql_query("SHOW DATABASES");
while ($row = mysql_fetch_assoc($res)) {
echo $row['Database'] . "\n";
}
?>
</body>
</html>

@ -1,5 +1,5 @@
--- ---
#This Playbook deploys the whole application stack in this site. #This Playbook deploys the whole application stack in this site.
- include: roles/db.yml - include: playbooks/db.yml
- include: roles/web.yml - include: playbooks/web.yml