Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ansible/roles/serverdensity
  • shrikeh/serverdensity
2 results
Show changes
Commits on Source (61)
......@@ -52,3 +52,5 @@ coverage.xml
# Sphinx documentation
docs/_build/
# SVN
.svn
The MIT License (MIT)
Copyright (c) 2014 Jürgen Haas
Copyright (c) 2015, 2016 Jürgen Haas, PARAGON Executive Services GmbH
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
SOFTWARE.
Ansible role to install and configure Server Density Agent
==========================================================
This is currently developed and tested for Ubuntu only but should easily be extended to other Nix's later on.
See defaults/main.yml for variables that you should re-define in your own inventory.
---
# file: roles/serverdensity/defaults/main.yml
sd_url: false
sd_api_token: ''
sd_api_cache_file: '/tmp/sd_cache'
sd_agent_key: ''
sd_logging_level: 'info'
sd_plugins: []
sd_update_remote: yes
sd_account:
sd_url:
sd_api_token:
sd_api_cache_file: no
sd_agent_key:
sd_logging_level: info
sd_alert_cleanup: no
sd_force_update: yes
sd_groups:
apache: 'all'
mysql: 'all'
proxy: 'all'
apache: none
mysql: none
proxy: none
sd_repo_public_key_uri: 'https://archive.serverdensity.com/sd-packaging-public.key'
sd_agent_plugins_dir: /usr/share/python/sd-agent/checks.d/plugins
sd_plugins_files_dir: "{{ playbook_dir }}/files/sd-plugins"
sd_uninstallv1: no
mysql_root_password: root
---
# file: roles/serverdensity/handlers/main.yml
- name: 'ServerDensity | Restart Agent'
service: name=sd-agent state=restarted
- name: Restart Agent
service:
name: sd-agent
state: restarted
- name: Restart Apache
service:
name: apache2
state: restarted
---
galaxy_info:
author: "jurgenhaas"
description: "Server Density client install role and inventory synchronisation tool"
company: "PARAGON Executive Services GmbH"
min_ansible_version: 1.5
platforms:
- name: Ubuntu
versions:
- precise
- quantal
- raring
- saucy
- trusty
- name: Ubuntu
versions:
- precise
- quantal
- raring
- saucy
- trusty
categories:
- monitoring
- monitoring
dependencies: []
---
# file: roles/serverdensity/tasks/apache.yml
- name: Install The Agent
apt:
pkg: sd-agent-apache
state: present
notify:
- Restart Agent
- name: Configure The Agent
template:
src: apache.yaml
dest: /etc/sd-agent/conf.d/apache.yaml
owner: root
group: root
mode: 0644
notify:
- Restart Agent
- name: Enable some required modules
apache2_module:
name: '{{ item }}'
state: present
with_items:
- status
notify:
- Restart Apache
- name: Configuration file for ServerDensity
template:
src: etc-apache2-sites-available-sd-agent
dest: /etc/apache2/sites-available/sd-agent{{ apache_conf_ext|default('.conf') }}
owner: root
group: root
mode: 0644
notify:
- Restart Apache
- name: Enable the sd-agent site
command: a2ensite sd-agent
args:
creates: /etc/apache2/sites-enabled/sd-agent{{ apache_conf_ext|default('.conf') }}
notify:
- Restart Apache
---
# file: roles/serverdensity/tasks/main.yml
- name: 'ServerDensity | Init SD plugin'
local_action:
serverdensity
api_token={{sd_api_token}}
cleanup=true
cache='{{sd_api_cache_file}}'
- name: ServerDensity Role
set_fact:
role_serverdensity_started: yes
tags:
- always
- name: 'ServerDensity | Install Public Repo Key'
apt_key:
url='https://www.serverdensity.com/downloads/boxedice-public.key'
state=present
- block:
- name: 'ServerDensity | Add ServerDensity Repository To Apt'
copy:
content='deb http://www.serverdensity.com/downloads/linux/deb all main'
dest='/etc/apt/sources.list.d/sd-agent.list'
- name: Import serverdensity
import_tasks: serverdensity.yml
when: sd_api_token != ''
- name: 'ServerDensity | Install The Agent'
apt:
pkg=sd-agent
state=installed
update_cache=yes
notify: 'ServerDensity | Restart Agent'
- name: 'ServerDensity | Create Plugins Directory'
file:
dest='/usr/bin/sd-agent/plugins'
state=directory
mode=755
- name: 'ServerDensity | Copy Plugins'
copy:
src={{inventory_dir}}/files/sd-plugins/{{item.1}}
dest=/usr/bin/sd-agent/plugins/{{item.1}}
with_items: sd_plugins|dictsort
notify: 'ServerDensity | Restart Agent'
- name: 'ServerDensity | Configure The Agent'
template: src=config.cfg
dest=/etc/sd-agent/config.cfg
owner=root
group=root
mode=0644
when: sd_agent_key != ''
notify: 'ServerDensity | Restart Agent'
when: not excluded_roles or "serverdensity" not in excluded_roles
---
# file: roles/serverdensity/tasks/mysql.yml
- name: Install The Agent
apt:
pkg: sd-agent-mysql
state: present
notify:
- Restart Agent
- name: Configure The Agent
template:
src: mysql.yaml
dest: /etc/sd-agent/conf.d/mysql.yaml
owner: root
group: root
mode: 0644
notify:
- Restart Agent
---
# file: roles/serverdensity/tasks/serverdensity.yml
- name: Import uninstallv1
import_tasks: uninstallv1.yml
when: sd_uninstallv1
- name: Init SD plugin
serverdensity:
api_token: '{{ sd_api_token }}'
cleanup: '{{ sd_alert_cleanup }}'
force: '{{ sd_force_update }}'
cache: '{{ sd_api_cache_file }}'
delegate_to: localhost
when: sd_update_remote
- name: Install Public Repo Key
apt_key:
keyring: /etc/apt/trusted.gpg.d/serverdensity.gpg
url: '{{ sd_repo_public_key_uri }}'
state: present
- name: Add ServerDensity Repository To Apt
copy:
content: 'deb http://archive.serverdensity.com/ubuntu/ all main'
dest: /etc/apt/sources.list.d/sd-agent.list
mode: 0644
- name: Install The Agent
apt:
pkg: sd-agent
state: present
update_cache: yes
notify:
- Restart Agent
- name: Create Plugins Directory
file:
dest: '{{ sd_agent_plugins_dir }}'
state: directory
mode: 0755
- name: Copy Plugins
copy:
src: '{{ sd_plugins_files_dir }}/{{ item }}'
dest: '{{ sd_agent_plugins_dir }}/{{ item }}'
with_items: '{{ sd_plugins|default([]) }}'
notify:
- Restart Agent
- name: Configure The Agent
template:
src: '{{ item }}'
dest: '/etc/sd-agent/{{ item }}'
owner: root
group: root
mode: 0644
with_items:
- config.cfg
- plugins.cfg
# - supervisor.conf
when: sd_agent_key != ''
notify:
- Restart Agent
- name: Import apache
import_tasks: apache.yml
when: sd_groups.apache != 'none' and inventory_hostname in groups[sd_groups.apache]
- name: Import mysql
import_tasks: mysql.yml
when: sd_groups.mysql != 'none' and inventory_hostname in groups[sd_groups.mysql]
---
# file: roles/serverdensity/tasks/uninstallv1.yml
# Stop agent
- name: Stop v1 Agent
service:
name: sd-agent
state: stopped
# Uninstall agent
- name: Uninstall v1 Agent
apt:
pkg: sd-agent
state: absent
# Remove /usr/bin/sd-agent
- name: Remove Plugins Directory
file:
dest: /usr/bin/sd-agent
state: absent
init_config:
instances:
- apache_status_url: http://{{ inventory_hostname }}/server-status?auto
# Server Density Agent Config
# Docs: https://support.serverdensity.com/hc/en-us/articles/201003178-Agent-config-variables
# Plugins: http://plugins.serverdensity.com/
# Version 2
[Main]
sd_url: {{sd_url}}
agent_key: {{sd_agent_key}}
sd_account: {{ sd_account }}
agent_key: {{ sd_agent_key }}
plugin_directory: /usr/bin/sd-agent/plugins
logging_level: {{sd_logging_level}}
plugin_directory: {{ sd_agent_plugins_dir }}
{% if inventory_hostname in groups[sd_groups.apache] %}
# Apache
# See https://support.serverdensity.com/hc/en-us/articles/201253343-Apache-monitoring-Linux-Mac-and-FreeBSD
# ========================================================================== #
# Logging
# See https://support.serverdensity.com/hc/en-us/articles/213093038-Log-levels-agent-debug-mode
# ========================================================================== #
apache_status_url: http://{{inventory_hostname}}/server-status/?auto
apache_status_user:
apache_status_pass:
{% endif %}
log_level: {{ sd_logging_level }}
{% if inventory_hostname in groups[sd_groups.mysql] %}
# MySQL
# See https://support.serverdensity.com/hc/en-us/articles/201013827-MySQL-monitoring-Linux-Mac-and-FreeBSD
# collector_log_file: /var/log/sd-agent/collector.log
# forwarder_log_file: /var/log/sd-agent/forwarder.log
mysql_server: 127.0.0.1
mysql_user: root
mysql_pass: root
{% endif %}
{% if inventory_hostname in groups[sd_groups.proxy] %}
haproxy_svname: {{inventory_hostname}}
haproxy_url: http://127.0.0.1:7000/haproxy_stats
{% endif %}
# if syslog is enabled but a host and port are not set, a local domain socket
# connection will be attempted
#
# log_to_syslog: yes
# syslog_host:
# syslog_port:
<VirtualHost *:80>
Include /etc/apache2/{{ apache_conf_dir|default('conf-available') }}/global-redirect.conf
ServerName {{ inventory_hostname }}
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 127.0.0.1{% for address in ansible_all_ipv4_addresses %} {{ address }}{% endfor %}
</Location>
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
LogLevel warn
{% if apache_version|default('2.4') == '2.4' %}
ErrorLogFormat "[%{u}t] [%l] [pid %P] [client\ %{X-Forwarded-For}i] %M% ,\ referer:\ %{Referer}i"
{% endif %}
LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined env=!forwarded
CustomLog ${APACHE_LOG_DIR}/access.log proxy env=forwarded
</VirtualHost>
init_config:
instances:
- server: 127.0.0.1
user: root
pass: {{ mysql_root_password }}
# PLugins config
{% if sd_groups.proxy != 'none' and inventory_hostname in groups[sd_groups.proxy] %}
[haproxy]
haproxy_svname: {{ inventory_hostname }}
haproxy_url: http://127.0.0.1:7000/haproxy_stats
{% endif %}
[supervisorctl]
serverurl = unix:///var/tmp/sd-supervisor.sock
[unix_http_server]
file=/var/tmp/sd-supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisord]
http_port = /var/tmp/sd-supervisor.sock
minfds = 1024
minprocs = 200
loglevel = info
logfile = /var/log/sd-agent/supervisord.log
logfile_maxbytes = 50MB
nodaemon = false
pidfile = /var/run/sd-supervisord.pid
logfile_backups = 10
environment=PYTHONPATH=/usr/share/python/sd-agent,LANG=POSIX
[program:collector]
command=/usr/share/python/sd-agent/bin/python /usr/share/python/sd-agent/agent.py foreground --use-local-forwarder
stdout_logfile=NONE
stderr_logfile=NONE
priority=999
startsecs=5
startretries=3
user=sd-agent
environment=PYTHONPATH='/usr/share/python/sd-agent:$PYTHONPATH'
[program:forwarder]
command=/usr/share/python/sd-agent/bin/python /usr/share/python/sd-agent/sdagent.py
stdout_logfile=NONE
stderr_logfile=NONE
startsecs=5
startretries=3
priority=998
user=sd-agent
[group:sd-agent]
programs=forwarder,collector