From 5a7c9c40c9364ccd875191f56cd7299116913f08 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Mon, 28 Apr 2014 12:20:21 +0200 Subject: [PATCH] Initial code for the role --- README.md | 8 ++++++-- defaults/main.yml | 13 ++++++++++++ handlers/main.yml | 5 +++++ meta/main.yml | 15 ++++++++++++++ tasks/main.yml | 48 ++++++++++++++++++++++++++++++++++++++++++++ templates/config.cfg | 33 ++++++++++++++++++++++++++++++ 6 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/config.cfg diff --git a/README.md b/README.md index 41fd0be..6aad712 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ -ansible-role-serverdensity -========================== +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. diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..0a6123f --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,13 @@ +--- +# 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_groups: + apache: 'all' + mysql: 'all' + proxy: 'all' diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..33555a2 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,5 @@ +--- +# file: roles/serverdensity/handlers/main.yml + +- name: 'ServerDensity | Restart Agent' + service: name=sd-agent state=restarted diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..748101e --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,15 @@ +--- +galaxy_info: + author: "jurgenhaas" + company: "PARAGON Executive Services GmbH" + min_ansible_version: 1.5 + platforms: + - name: Ubuntu + versions: + - precise + - quantal + - raring + - saucy + - trusty + categories: + - monitoring diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..62c3e85 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,48 @@ +--- +# 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 | Install Public Repo Key' + apt_key: + url='https://www.serverdensity.com/downloads/boxedice-public.key' + state=present + +- 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: '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' diff --git a/templates/config.cfg b/templates/config.cfg new file mode 100644 index 0000000..d74dac7 --- /dev/null +++ b/templates/config.cfg @@ -0,0 +1,33 @@ +# Server Density Agent Config +# Docs: https://support.serverdensity.com/hc/en-us/articles/201003178-Agent-config-variables +# Plugins: http://plugins.serverdensity.com/ + +[Main] +sd_url: {{sd_url}} +agent_key: {{sd_agent_key}} + +plugin_directory: /usr/bin/sd-agent/plugins +logging_level: {{sd_logging_level}} + +{% 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 + +apache_status_url: http://{{inventory_hostname}}/server-status/?auto +apache_status_user: +apache_status_pass: +{% endif %} + +{% 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 + +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 %} -- GitLab