remove some redundancy, split up nagios config files

pull/63/head
Tim Gerla 11 years ago
parent cd3b1e30ca
commit 3ff2020d2c
  1. 10
      lamp_haproxy/add_webservers.yml
  2. 1
      lamp_haproxy/nagios.yml
  3. 10
      lamp_haproxy/remove_webservers.yml
  4. 39
      lamp_haproxy/roles/nagios/files/ansible-managed-services.cfg
  5. 1
      lamp_haproxy/roles/nagios/files/nagios.cfg
  6. 19
      lamp_haproxy/roles/nagios/tasks/main.yml
  7. 25
      lamp_haproxy/roles/nagios/templates/dbservers.cfg.j2
  8. 22
      lamp_haproxy/roles/nagios/templates/lbservers.cfg.j2
  9. 112
      lamp_haproxy/roles/nagios/templates/servers.cfg.j2
  10. 25
      lamp_haproxy/roles/nagios/templates/webservers.cfg.j2
  11. 5
      lamp_haproxy/roles/web/handlers/main.yml
  12. 15
      lamp_haproxy/roles/web/tasks/add_to_lb.yml
  13. 8
      lamp_haproxy/roles/web/tasks/copy_code.yml
  14. 11
      lamp_haproxy/roles/web/tasks/install_httpd.yml
  15. 17
      lamp_haproxy/roles/web/tasks/main.yml
  16. 23
      lamp_haproxy/roles/web/tasks/remove_from_lb.yml

@ -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,6 +1,7 @@
---
# This playbook configures the monitoring node
# trigger fact-gathering for all hosts
- hosts: all
tasks:

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

@ -35,6 +35,7 @@ cfg_file=/etc/nagios/objects/templates.cfg
# Definitions for monitoring the local (Linux) host
cfg_file=/etc/nagios/objects/localhost.cfg
cfg_file=/etc/nagios/ansible-managed-services.cfg
cfg_dir=/etc/nagios/ansible-managed

@ -16,26 +16,25 @@
- name: create nagios config dir
file: path=/etc/nagios/ansible-managed state=directory
tags:
- nagios-setup
- name: configure nagios
copy: src=nagios.cfg dest=/etc/nagios/nagios.cfg
tags:
- nagios-setup
notify: restart nagios
- name: configure localhost monitoring
copy: src=localhost.cfg dest=/etc/nagios/objects/localhost.cfg
tags:
- nagios-setup
notify: restart nagios
- name: configure nagios services
copy: src=ansible-managed-services.cfg dest=/etc/nagios/
- name: create the nagios object files
template: src=servers.cfg.j2
dest=/etc/nagios/ansible-managed/servers.cfg
tags:
- nagios-setup
template: src={{ item + ".j2" }}
dest=/etc/nagios/ansible-managed/{{ item }}
with_items:
- webservers.cfg
- dbservers.cfg
- lbservers.cfg
notify: restart nagios
- name: start nagios

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