From a06dd2ec0bcd98b82dd0e3978ceed0a1bed84ab5 Mon Sep 17 00:00:00 2001 From: Wilfried OLLIVIER Date: Wed, 10 Jul 2019 17:13:09 +0200 Subject: [PATCH] Bootstrap grafana role --- LICENCE | 13 + README.md | 47 ++++ defaults/main.yml | 18 ++ handlers/main.yml | 6 + meta/main.yml | 21 ++ tasks/main.yml | 40 +++ templates/grafana.ini.j2 | 554 +++++++++++++++++++++++++++++++++++++ templates/grafana.ini.orig | 554 +++++++++++++++++++++++++++++++++++++ tests/inventory | 1 + tests/test.yml | 5 + vars/main.yml | 4 + 11 files changed, 1263 insertions(+) create mode 100644 LICENCE create mode 100644 README.md 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/grafana.ini.j2 create mode 100644 templates/grafana.ini.orig create mode 100644 tests/inventory create mode 100644 tests/test.yml create mode 100644 vars/main.yml diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..5568253 --- /dev/null +++ b/LICENCE @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2019 Wilfried OLLIVIER + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6de93ae --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +galaxy-grafana +============== + +Install Grafana on Debian + +Requirements +------------ + +None + +Role Variables +-------------- + +- grafana_name: name of the grafana instance +- grafana_signup: true/false, is signup enabled ? +- grafana_anon_access: true/false, is anon access enabled ? +- grafana_anon_org: if anon access enabled, what org id should be used ? +- grafana_proto: grafana protocol (http/https) +- grafana_domain: domain name of the grafana instance +- grafana_bind_iface: grafana interface bind selection +- grafana_port: grafana port +- grafana_url_port: grafana port (can be changed if a reverse proxy is used) +- grafana_admin_user: grafana admin username +- grafana_admin_pass: grafana admin password + +Dependencies +------------ + +None + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - role: galaxy-grafana + +Run tests +--------- + +Needs galaxy-vagrant to run tests + +Ensure galaxy-vagrant is up + + ansible-playbook -i tests/inventory tests/test.yml diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..c992d6d --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,18 @@ +--- + +# Generic stuff +grafana_name: Metrics +grafana_signup: false +grafana_anon_access: false +grafana_anon_org: 1 + +# Protocol and networking stuff +grafana_proto: http +grafana_domain: galaxy-vagrant.example.com +grafana_bind_iface: eth1 +grafana_port: 3000 +grafana_url_port: 3000 + +# Admmin user stuff +grafana_admin_user: admin +grafana_admin_pass: not24get \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..a137f3c --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,6 @@ +--- + +- name: reload grafana + systemd: + name: grafana-server + state: restarted \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..b56ec97 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,21 @@ +galaxy_info: + author: Wilfried OLLIVIER + description: Galaxy role to install Grafana on Debian + company: none + + license: WTFPL + + min_ansible_version: 2.4 + + platforms: + - name: Debian + versions: + - Stretch + - Buster + + galaxy_tags: + - grafana + - debian + - timeseries + +dependencies: [] \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..801b4f6 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,40 @@ +--- + +# https://grafana.com/docs/installation/debian/ + +- name: Install some required pkg + apt: + name: [ 'software-properties-common', 'apt-transport-https' ] + state: present + update_cache: yes + +- name: Add Grafana apt key + apt_key: + url: https://packages.grafana.com/gpg.key + state: present + +- name: Add Grafana repo to apt + apt_repository: + repo: "{{ grafana.repo }}" + state: present + filename: grafana + +- name: Install grafana + apt: + name: grafana + state: present + update_cache: yes + +- name: Push Grafana config + template: + src: grafana.ini.j2 + dest: /etc/grafana/grafana.ini + notify: reload grafana + register: conf + +- name: Enable and restart Grafana + systemd: + name: grafana-server + state: restarted + enabled: yes + when: conf.changed \ No newline at end of file diff --git a/templates/grafana.ini.j2 b/templates/grafana.ini.j2 new file mode 100644 index 0000000..eb922bd --- /dev/null +++ b/templates/grafana.ini.j2 @@ -0,0 +1,554 @@ +##################### Grafana Configuration Example ##################### +# +# Everything has defaults so you only need to uncomment things you want to +# change + +# possible values : production, development +app_mode = production + +# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty +instance_name = {{ grafana_name }} + +#################################### Paths #################################### +[paths] +# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used) +;data = /var/lib/grafana + +# Temporary files in `data` directory older than given duration will be removed +;temp_data_lifetime = 24h + +# Directory where grafana can store logs +;logs = /var/log/grafana + +# Directory where grafana will automatically scan and look for plugins +;plugins = /var/lib/grafana/plugins + +# folder that contains provisioning config files that grafana will apply on startup and while running. +;provisioning = conf/provisioning + +#################################### Server #################################### +[server] +# Protocol (http, https, socket) +protocol = {{ grafana_proto }} + +# The ip address to bind to, empty will bind to all interfaces +http_addr = {{ hostvars[inventory_hostname]['ansible_' + grafana_bind_iface].ipv4.address }} + +# The http port to use +http_port = {{ grafana_port }} + +# The public facing domain name used to access grafana from a browser +domain = {{ grafana_domain }} + +# Redirect to correct domain if host header does not match domain +# Prevents DNS rebinding attacks +;enforce_domain = false + +# The full public facing url you use in browser, used for redirects and emails +# If you use reverse proxy and sub path specify full url (with sub path) +root_url = {{ grafana_proto }}://{{ grafana_domain }}:{{ grafana_url_port }} + +# Log web requests +;router_logging = false + +# the path relative working path +;static_root_path = public + +# enable gzip +;enable_gzip = false + +# https certs & key file +;cert_file = +;cert_key = + +# Unix socket path +;socket = + +#################################### Database #################################### +[database] +# You can configure the database connection by specifying type, host, name, user and password +# as separate properties or as on string using the url properties. + +# Either "mysql", "postgres" or "sqlite3", it's your choice +;type = sqlite3 +;host = 127.0.0.1:3306 +;name = grafana +;user = root +# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;""" +;password = + +# Use either URL or the previous fields to configure the database +# Example: mysql://user:secret@host:port/database +;url = + +# For "postgres" only, either "disable", "require" or "verify-full" +;ssl_mode = disable + +# For "sqlite3" only, path relative to data_path setting +;path = grafana.db + +# Max idle conn setting default is 2 +;max_idle_conn = 2 + +# Max conn setting default is 0 (mean not set) +;max_open_conn = + +# Connection Max Lifetime default is 14400 (means 14400 seconds or 4 hours) +;conn_max_lifetime = 14400 + +# Set to true to log the sql calls and execution times. +log_queries = + +# For "sqlite3" only. cache mode setting used for connecting to the database. (private, shared) +;cache_mode = private + +#################################### Cache server ############################# +[remote_cache] +# Either "redis", "memcached" or "database" default is "database" +;type = database + +# cache connectionstring options +# database: will use Grafana primary database. +# redis: config like redis server e.g. `addr=127.0.0.1:6379,pool_size=100,db=0`. Only addr is required. +# memcache: 127.0.0.1:11211 +;connstr = + +#################################### Data proxy ########################### +[dataproxy] + +# This enables data proxy logging, default is false +;logging = false + +# How long the data proxy should wait before timing out default is 30 (seconds) +;timeout = 30 + +# If enabled and user is not anonymous, data proxy will add X-Grafana-User header with username into the request, default is false. +;send_user_header = false + +#################################### Analytics #################################### +[analytics] +# Server reporting, sends usage counters to stats.grafana.org every 24 hours. +# No ip addresses are being tracked, only simple counters to track +# running instances, dashboard and error counts. It is very helpful to us. +# Change this option to false to disable reporting. +;reporting_enabled = true + +# Set to false to disable all checks to https://grafana.net +# for new vesions (grafana itself and plugins), check is used +# in some UI views to notify that grafana or plugin update exists +# This option does not cause any auto updates, nor send any information +# only a GET request to http://grafana.com to get latest versions +;check_for_updates = true + +# Google Analytics universal tracking code, only enabled if you specify an id here +;google_analytics_ua_id = + +# Google Tag Manager ID, only enabled if you specify an id here +;google_tag_manager_id = + +#################################### Security #################################### +[security] +# default admin user, created on startup +admin_user = {{ grafana_admin_user }} + +# default admin password, can be changed before first start of grafana, or in profile settings +admin_password = {{ grafana_admin_pass }} + +# used for signing +;secret_key = SW2YcwTIb9zpOOhoPsMm + +# disable gravatar profile images +;disable_gravatar = false + +# data source proxy whitelist (ip_or_domain:port separated by spaces) +;data_source_proxy_whitelist = + +# disable protection against brute force login attempts +;disable_brute_force_login_protection = false + +# set to true if you host Grafana behind HTTPS. default is false. +;cookie_secure = false + +# set cookie SameSite attribute. defaults to `lax`. can be set to "lax", "strict" and "none" +;cookie_samesite = lax + +# set to true if you want to allow browsers to render Grafana in a ,