parent
cd3b1e30ca
commit
3ff2020d2c
@ -1,10 +0,0 @@ |
|||||||
--- |
|
||||||
# This Playbook adds a webserver into the the web cluster |
|
||||||
|
|
||||||
- hosts: webservers |
|
||||||
user: root |
|
||||||
serial: 1 |
|
||||||
tasks: |
|
||||||
- include: roles/web/tasks/install_httpd.yml |
|
||||||
- include: roles/web/tasks/copy_code.yml |
|
||||||
- include: roles/web/tasks/add_to_lb.yml |
|
@ -1,10 +0,0 @@ |
|||||||
--- |
|
||||||
# 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 |
|
||||||
serial: 1 |
|
||||||
tasks: |
|
||||||
- include: ../roles/web/tasks/remove_from_lb.yml |
|
@ -0,0 +1,39 @@ |
|||||||
|
# {{ ansible_managed }} |
||||||
|
|
||||||
|
# service checks to be applied to all hosts |
||||||
|
|
||||||
|
define service { |
||||||
|
use local-service |
||||||
|
host_name localhost |
||||||
|
service_description Root Partition |
||||||
|
check_command check_local_disk!20%!10%!/ |
||||||
|
} |
||||||
|
|
||||||
|
define service { |
||||||
|
use local-service |
||||||
|
host_name * |
||||||
|
service_description Current Users |
||||||
|
check_command check_local_users!20!50 |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
define service { |
||||||
|
use local-service |
||||||
|
host_name * |
||||||
|
service_description Total Processes |
||||||
|
check_command check_local_procs!250!400!RSZDT |
||||||
|
} |
||||||
|
|
||||||
|
define service { |
||||||
|
use local-service |
||||||
|
host_name * |
||||||
|
service_description Current Load |
||||||
|
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0 |
||||||
|
} |
||||||
|
|
||||||
|
define service { |
||||||
|
use local-service |
||||||
|
host_name * |
||||||
|
service_description Swap Usage |
||||||
|
check_command check_local_swap!20!10 |
||||||
|
} |
@ -0,0 +1,25 @@ |
|||||||
|
# {{ ansible_managed }} |
||||||
|
|
||||||
|
define hostgroup { |
||||||
|
hostgroup_name dbservers |
||||||
|
alias Database Servers |
||||||
|
} |
||||||
|
|
||||||
|
{% for host in groups['dbservers'] %} |
||||||
|
define host { |
||||||
|
use linux-server |
||||||
|
host_name {{ host }} |
||||||
|
alias {{ host }} |
||||||
|
address {{ hostvars[host].ansible_default_ipv4.address }} |
||||||
|
hostgroups dbservers |
||||||
|
} |
||||||
|
{% endfor %} |
||||||
|
|
||||||
|
#define service { |
||||||
|
# use local-service |
||||||
|
# hostgroup_name dbservers |
||||||
|
# service_description MySQL Database Server |
||||||
|
# check_command check_mysql |
||||||
|
# notifications_enabled 0 |
||||||
|
#} |
||||||
|
|
@ -0,0 +1,22 @@ |
|||||||
|
# {{ ansible_managed }} |
||||||
|
|
||||||
|
define hostgroup { |
||||||
|
hostgroup_name loadbalancers |
||||||
|
alias Load Balancers |
||||||
|
} |
||||||
|
|
||||||
|
{% for host in groups['lbservers'] %} |
||||||
|
define host { |
||||||
|
use linux-server |
||||||
|
host_name {{ host }} |
||||||
|
alias {{ host }} |
||||||
|
address {{ hostvars[host].ansible_default_ipv4.address }} |
||||||
|
hostgroups loadbalancers |
||||||
|
} |
||||||
|
define service { |
||||||
|
use local-service |
||||||
|
host_name {{ host }} |
||||||
|
service_description HAProxy Load Balancer |
||||||
|
check_command check_http!-p{{ hostvars[host].listenport }} |
||||||
|
} |
||||||
|
{% endfor %} |
@ -1,112 +0,0 @@ |
|||||||
# {{ ansible_managed }} |
|
||||||
|
|
||||||
define hostgroup { |
|
||||||
hostgroup_name webservers |
|
||||||
alias Web Servers |
|
||||||
} |
|
||||||
|
|
||||||
define hostgroup { |
|
||||||
hostgroup_name loadbalancers |
|
||||||
alias Load Balancers |
|
||||||
} |
|
||||||
|
|
||||||
define hostgroup { |
|
||||||
hostgroup_name dbservers |
|
||||||
alias Database Servers |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
{% for host in groups['webservers'] %} |
|
||||||
define host { |
|
||||||
use linux-server |
|
||||||
host_name {{ host }} |
|
||||||
alias {{ host }} |
|
||||||
address {{ hostvars[host].ansible_default_ipv4.address }} |
|
||||||
hostgroups webservers |
|
||||||
} |
|
||||||
{% endfor %} |
|
||||||
|
|
||||||
{% for host in groups['lbservers'] %} |
|
||||||
define host { |
|
||||||
use linux-server |
|
||||||
host_name {{ host }} |
|
||||||
alias {{ host }} |
|
||||||
address {{ hostvars[host].ansible_default_ipv4.address }} |
|
||||||
hostgroups loadbalancers |
|
||||||
} |
|
||||||
define service { |
|
||||||
use local-service |
|
||||||
host_name {{ host }} |
|
||||||
service_description HAProxy Load Balancer |
|
||||||
check_command check_http!-p{{ hostvars[host].listenport }} |
|
||||||
} |
|
||||||
{% endfor %} |
|
||||||
|
|
||||||
{% for host in groups['dbservers'] %} |
|
||||||
define host { |
|
||||||
use linux-server |
|
||||||
host_name {{ host }} |
|
||||||
alias {{ host }} |
|
||||||
address {{ hostvars[host].ansible_default_ipv4.address }} |
|
||||||
hostgroups dbservers |
|
||||||
} |
|
||||||
{% endfor %} |
|
||||||
|
|
||||||
# service checks to be applied to all hosts |
|
||||||
|
|
||||||
define service { |
|
||||||
use local-service |
|
||||||
host_name localhost |
|
||||||
service_description Root Partition |
|
||||||
check_command check_local_disk!20%!10%!/ |
|
||||||
} |
|
||||||
|
|
||||||
define service { |
|
||||||
use local-service |
|
||||||
host_name * |
|
||||||
service_description Current Users |
|
||||||
check_command check_local_users!20!50 |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
define service { |
|
||||||
use local-service |
|
||||||
host_name * |
|
||||||
service_description Total Processes |
|
||||||
check_command check_local_procs!250!400!RSZDT |
|
||||||
} |
|
||||||
|
|
||||||
define service { |
|
||||||
use local-service |
|
||||||
host_name * |
|
||||||
service_description Current Load |
|
||||||
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0 |
|
||||||
} |
|
||||||
|
|
||||||
define service { |
|
||||||
use local-service |
|
||||||
host_name * |
|
||||||
service_description Swap Usage |
|
||||||
check_command check_local_swap!20!10 |
|
||||||
} |
|
||||||
|
|
||||||
# service checks to be applied to the web server |
|
||||||
|
|
||||||
define service { |
|
||||||
use local-service |
|
||||||
hostgroup_name webservers |
|
||||||
service_description webserver |
|
||||||
check_command check_http |
|
||||||
notifications_enabled 0 |
|
||||||
} |
|
||||||
|
|
||||||
# service checks to be applied to the database server |
|
||||||
|
|
||||||
#define service { |
|
||||||
# use local-service |
|
||||||
# hostgroup_name dbservers |
|
||||||
# service_description MySQL Database Server |
|
||||||
# check_command check_mysql |
|
||||||
# notifications_enabled 0 |
|
||||||
#} |
|
||||||
|
|
@ -0,0 +1,25 @@ |
|||||||
|
# {{ ansible_managed }} |
||||||
|
|
||||||
|
define hostgroup { |
||||||
|
hostgroup_name webservers |
||||||
|
alias Web Servers |
||||||
|
} |
||||||
|
|
||||||
|
{% for host in groups['webservers'] %} |
||||||
|
define host { |
||||||
|
use linux-server |
||||||
|
host_name {{ host }} |
||||||
|
alias {{ host }} |
||||||
|
address {{ hostvars[host].ansible_default_ipv4.address }} |
||||||
|
hostgroups webservers |
||||||
|
} |
||||||
|
{% endfor %} |
||||||
|
|
||||||
|
# service checks to be applied to the web server |
||||||
|
define service { |
||||||
|
use local-service |
||||||
|
hostgroup_name webservers |
||||||
|
service_description webserver |
||||||
|
check_command check_http |
||||||
|
notifications_enabled 0 |
||||||
|
} |
@ -1,5 +0,0 @@ |
|||||||
--- |
|
||||||
# Handler for the web tier |
|
||||||
|
|
||||||
- name: restart iptables |
|
||||||
service: name=iptables state=restarted |
|
@ -1,15 +0,0 @@ |
|||||||
--- |
|
||||||
# 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}" |
|
||||||
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,8 +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 the index.php file |
|
||||||
template: src=index.php.j2 dest=/var/www/html/index.php |
|
@ -1,11 +0,0 @@ |
|||||||
--- |
|
||||||
# This playbook installs the php modules. |
|
||||||
|
|
||||||
- name: Install http and php etc |
|
||||||
action: yum name=$item state=installed |
|
||||||
with_items: |
|
||||||
- php |
|
||||||
- php-mysql |
|
||||||
|
|
||||||
- name: Configure SELinux to allow httpd to connect to remote database |
|
||||||
seboolean: name=httpd_can_network_connect_db state=true persistent=yes |
|
@ -0,0 +1,17 @@ |
|||||||
|
--- |
||||||
|
|
||||||
|
# httpd is handled by the base-apache role upstream |
||||||
|
- name: Install php |
||||||
|
action: yum name=$item state=installed |
||||||
|
with_items: |
||||||
|
- php |
||||||
|
- php-mysql |
||||||
|
|
||||||
|
- name: Configure SELinux to allow httpd to connect to remote database |
||||||
|
seboolean: name=httpd_can_network_connect_db state=true persistent=yes |
||||||
|
|
||||||
|
- name: Copy the code from repository |
||||||
|
git: repo=${repository} dest=/var/www/html/ |
||||||
|
|
||||||
|
- name: Create the index.php file |
||||||
|
template: src=index.php.j2 dest=/var/www/html/index.php |
@ -1,23 +0,0 @@ |
|||||||
--- |
|
||||||
# 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 |
|
||||||
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 |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in new issue