From 785cae7ccf8c69366438a446ff121ecbb7ad5465 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 8 Dec 2020 20:06:25 +0100 Subject: add grahpite web and grafana roles --- roles/monitoring/graphite/web/defaults/main.yml | 5 +++ roles/monitoring/graphite/web/handlers/main.yml | 1 + roles/monitoring/graphite/web/tasks/main.yml | 50 ++++++++++++++++++++++ .../graphite/web/templates/nginx-vhost.conf.j2 | 20 +++++++++ .../graphite/web/templates/uwsgi-app.ini.j2 | 8 ++++ 5 files changed, 84 insertions(+) create mode 100644 roles/monitoring/graphite/web/defaults/main.yml create mode 100644 roles/monitoring/graphite/web/handlers/main.yml create mode 100644 roles/monitoring/graphite/web/tasks/main.yml create mode 100644 roles/monitoring/graphite/web/templates/nginx-vhost.conf.j2 create mode 100644 roles/monitoring/graphite/web/templates/uwsgi-app.ini.j2 (limited to 'roles/monitoring/graphite/web') diff --git a/roles/monitoring/graphite/web/defaults/main.yml b/roles/monitoring/graphite/web/defaults/main.yml new file mode 100644 index 00000000..167c39a1 --- /dev/null +++ b/roles/monitoring/graphite/web/defaults/main.yml @@ -0,0 +1,5 @@ +--- +# graphite_web_secret_key: <--- pwgen -s 64 -1 + +graphite_web_nginx_listen: 127.0.0.1:81 default_server +graphite_web_uwsgi_port: 3031 diff --git a/roles/monitoring/graphite/web/handlers/main.yml b/roles/monitoring/graphite/web/handlers/main.yml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/roles/monitoring/graphite/web/handlers/main.yml @@ -0,0 +1 @@ +--- diff --git a/roles/monitoring/graphite/web/tasks/main.yml b/roles/monitoring/graphite/web/tasks/main.yml new file mode 100644 index 00000000..7c796722 --- /dev/null +++ b/roles/monitoring/graphite/web/tasks/main.yml @@ -0,0 +1,50 @@ +--- +- name: instsall apt packages + apt: + name: graphite-web + state: present + +- name: configure secret key + lineinfile: + path: /etc/graphite/local_settings.py + regexp: '#?SECRET_KEY\s*=' + line: "SECRET_KEY = '{{ graphite_web_secret_key }}'" + +- name: initialize database + become: yes + become_method: su + become_user: "_graphite" + become_flags: "-s /bin/bash" + command: graphite-manage migrate --run-syncdb + args: + creates: /var/lib/graphite/graphite.db + +- name: fix sqlite database permissions + file: + path: /var/lib/graphite/graphite.db + owner: "_graphite" + group: "_graphite" + mode: "0600" + +- name: check if uwsgi plugin python3 is installed + assert: + msg: "This role needs uwsgi with python3 plugin installed" + that: + - uwsgi_plugins is defined + - "'python3' in uwsgi_plugins" + +- name: install uwsgi app + vars: + uwsgi_app: + name: graphite + content: "{{ lookup('template', 'uwsgi-app.ini.j2') }}" + include_role: + name: uwsgi/app + +- name: install nginx vhost + vars: + nginx_vhost: + name: graphite + content: "{{ lookup('template', 'nginx-vhost.conf.j2') }}" + include_role: + name: nginx/vhost diff --git a/roles/monitoring/graphite/web/templates/nginx-vhost.conf.j2 b/roles/monitoring/graphite/web/templates/nginx-vhost.conf.j2 new file mode 100644 index 00000000..48b6ef73 --- /dev/null +++ b/roles/monitoring/graphite/web/templates/nginx-vhost.conf.j2 @@ -0,0 +1,20 @@ +server { + listen {{ graphite_web_nginx_listen }}; + + server_name _; + + location / { + include uwsgi_params; + uwsgi_pass 127.0.0.1:{{ graphite_web_uwsgi_port }}; + } + rewrite ^/admin(.*)admin/([^/]+)/([^/]+)$ /media/$2/$3 redirect; + location /media { + alias /usr/share/python-django-common/django/contrib/admin/static/admin/; + } + location /static/ { + alias /usr/share/graphite-web/static/; + } + + access_log /var/log/nginx/access-graphite.log; + error_log /var/log/nginx/error-graphite.log; +} diff --git a/roles/monitoring/graphite/web/templates/uwsgi-app.ini.j2 b/roles/monitoring/graphite/web/templates/uwsgi-app.ini.j2 new file mode 100644 index 00000000..e5b01a04 --- /dev/null +++ b/roles/monitoring/graphite/web/templates/uwsgi-app.ini.j2 @@ -0,0 +1,8 @@ +[uwsgi] +plugin = python3 +processes = 2 +socket = 127.0.0.1:{{ graphite_web_uwsgi_port }} +gid = _graphite +uid = _graphite +chdir = /usr/share/graphite-web +wsgi-file = /usr/share/graphite-web/graphite.wsgi -- cgit v1.2.3