commit e334925fcae061560f42dd2448a24c0ab7f833bc
parent 4ed7f57ca2f1499b73e19ab02cc4c1c926f9562c
Author: Leah (ctucx) <leah@ctu.cx>
Date: Wed, 3 Feb 2021 17:44:25 +0100
parent 4ed7f57ca2f1499b73e19ab02cc4c1c926f9562c
Author: Leah (ctucx) <leah@ctu.cx>
Date: Wed, 3 Feb 2021 17:44:25 +0100
influxdb: add role
8 files changed, 210 insertions(+), 0 deletions(-)
diff --git a/roles/influxdb/tasks/checks.yml b/roles/influxdb/tasks/checks.yml @@ -0,0 +1,29 @@ +--- + +- fail: msg="Option 'services.influxdb.nginx.domain' has to be set when using nginx!" + when: + - services.influxdb.nginx.enable is defined + - services.influxdb.nginx.enable is true + - services.influxdb.nginx.domain is not defined + +- fail: msg="Option 'services.influxdb.nginx.sslOnly' has to be set when using nginx!" + when: + - services.influxdb.nginx.enable is defined + - services.influxdb.nginx.enable is true + - services.influxdb.nginx.sslOnly is not defined + +- fail: msg="Option 'services.influxdb.nginx.ssl.cert' has to be set when using nginx with ssl!" + when: + - services.influxdb.nginx.enable is defined + - services.influxdb.nginx.enable is true + - services.influxdb.nginx.ssl.enable is defined + - services.influxdb.nginx.ssl.enable is true + - services.influxdb.nginx.ssl.cert is not defined + +- fail: msg="Option 'services.influxdb.nginx.ssl.privkey' has to be set when using nginx with ssl!" + when: + - services.influxdb.nginx.enable is defined + - services.influxdb.nginx.enable is true + - services.influxdb.nginx.ssl.enable is defined + - services.influxdb.nginx.ssl.enable is true + - services.influxdb.nginx.ssl.privkey is not defined
diff --git a/roles/influxdb/tasks/configure.yml b/roles/influxdb/tasks/configure.yml @@ -0,0 +1,9 @@ +--- + +- name: "Create database(s)" + influxdb_database: + hostname: "127.0.0.1" + database_name: "{{ item }}" + with_items: "{{ services.influxdb.databases }}" + when: + - services.influxdb.databases is defined
diff --git a/roles/influxdb/tasks/install.yml b/roles/influxdb/tasks/install.yml @@ -0,0 +1,21 @@ +--- + +- name: "[Alpine] Install package: influxdb" + apk: + name: influxdb + state: present + update_cache: yes + when: + - ansible_distribution == "Alpine" + +- name: "[Archlinux] Install package: influxdb" + pacman: + name: + - influxdb + - python-requests + - python-influxdb + state: present + update_cache: yes + when: + - ansible_distribution == "Archlinux" +
diff --git a/roles/influxdb/tasks/main.yml b/roles/influxdb/tasks/main.yml @@ -0,0 +1,38 @@ +--- + +- include: checks.yml + when: + - services.influxdb.enable is defined + - services.influxdb.enable is true + +- include: install.yml + when: + - services.influxdb.enable is defined + - services.influxdb.enable is true + +- include: start.yml + when: + - services.influxdb.enable is defined + - services.influxdb.enable is true + +- include: configure.yml + when: + - services.influxdb.enable is defined + - services.influxdb.enable is true + +- include: nginx.yml + when: + - services.influxdb.enable is defined + - services.influxdb.enable is true + - services.influxdb.nginx is defined + - services.influxdb.nginx.enable is true + +- include: remove.yml + when: + - services.influxdb.enable is defined + - services.influxdb.enable is false + + + + +
diff --git a/roles/influxdb/tasks/nginx.yml b/roles/influxdb/tasks/nginx.yml @@ -0,0 +1,23 @@ +--- + +- name: "[nginx] Create vhost" + template: + src: nginx-vhost.conf.j2 + dest: /etc/nginx/conf.d/influxdb.conf + mode: 0644 + owner: nginx + group: nginx + +- name: "[OpenRC] Restart service: nginx" + service: + name: nginx + state: restarted + when: + - ansible_service_mgr == "openrc" + +- name: "[systemd] Restart service: nginx" + systemd: + name: nginx + state: restarted + when: + - ansible_service_mgr == "systemd"
diff --git a/roles/influxdb/tasks/remove.yml b/roles/influxdb/tasks/remove.yml @@ -0,0 +1,40 @@ +--- + +- name: "[OpenRC] Disable and stop service: influxdb" + service: + name: influxdb + enabled: no + state: stopped + when: + - ansible_service_mgr == "openrc" + +- name: "[systemd] Disable and stop service: influxdb" + systemd: + name: influxdb + enabled: no + state: stopped + when: + - ansible_service_mgr == "systemd" + +- name: "[Alpine] Remove package: influxdb" + apk: + name: influxdb + state: absent + when: + - ansible_distribution == "Alpine" + +- name: "[Archlinux] Remove package: influxdb" + pacman: + name: influxdb + state: absent + when: + - ansible_distribution == "Archlinux" + +- name: "Delete leftovers" + file: + path: "{{item}}" + state: absent + with_items: + - /etc/nginx/conf.d/influxdb.conf +# - /etc/influxdb.ini +# - /var/lib/influxdb/provisioning
diff --git a/roles/influxdb/tasks/start.yml b/roles/influxdb/tasks/start.yml @@ -0,0 +1,17 @@ +--- + +- name: "[OpenRC] Restart and enable service: influxdb" + service: + name: influxdb + enabled: yes + state: started + when: + - ansible_service_mgr == "openrc" + +- name: "[systemd] Restart and enable service: influxdb" + systemd: + name: influxdb + enabled: yes + state: started + when: + - ansible_service_mgr == "systemd"
diff --git a/roles/influxdb/templates/nginx-vhost.conf.j2 b/roles/influxdb/templates/nginx-vhost.conf.j2 @@ -0,0 +1,33 @@ +# +# !!! This file is managed by Ansible !!! +# + +{% if services.influxdb.nginx.sslOnly is not defined or services.influxdb.nginx.sslOnly is false %} +server { + listen 80 ; + listen [::]:80; + + server_name {{ services.influxdb.nginx.domain }}; + + location / { + proxy_pass http://localhost:8086/; + } +} + +{% endif %} +{% if services.influxdb.nginx.ssl.enable is true %} +server { + listen 443 ssl; + listen [::]:443 ssl; + + ssl_certificate "{{ services.influxdb.nginx.ssl.cert }}"; + ssl_certificate_key "{{ services.influxdb.nginx.ssl.privkey }}"; + include /etc/nginx/ssl.conf; + + server_name {{ services.influxdb.nginx.domain }}; + + location / { + proxy_pass http://localhost:8086/; + } +} +{% endif %}