From ccdf6fab93ac1d348a9e34deea381b47692d2228 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sun, 1 Dec 2019 20:40:40 -0600 Subject: [PATCH] Add InfluxDB role --- roles/influxdb/defaults/main.yaml | 20 +++++++++++ roles/influxdb/handlers/main.yaml | 14 ++++++++ roles/influxdb/tasks/Debian.yaml | 12 +++++++ roles/influxdb/tasks/main.yaml | 44 +++++++++++++++++++++++ roles/influxdb/templates/influxdb.conf.j2 | 38 ++++++++++++++++++++ roles/influxdb/vars/default.yaml | 1 + 6 files changed, 129 insertions(+) create mode 100644 roles/influxdb/defaults/main.yaml create mode 100644 roles/influxdb/handlers/main.yaml create mode 100644 roles/influxdb/tasks/Debian.yaml create mode 100644 roles/influxdb/tasks/main.yaml create mode 100644 roles/influxdb/templates/influxdb.conf.j2 create mode 100644 roles/influxdb/vars/default.yaml diff --git a/roles/influxdb/defaults/main.yaml b/roles/influxdb/defaults/main.yaml new file mode 100644 index 0000000..022f257 --- /dev/null +++ b/roles/influxdb/defaults/main.yaml @@ -0,0 +1,20 @@ +--- +influxdb_package_name: influxdb +influxdb_package_state: present + +influxdb_service_name: influxdb.service +influxdb_service_state: started +influxdb_service_enabled: yes + +influxdb_config: + reporting-disabled: yes + meta: + dir: /var/lib/influxdb/meta + data: + dir: /var/lib/influxdb/data + wal-dir: /var/lib/influxdb/wal + series-id-set-cache-size: 100 + index-version: tsi1 + query-log-enabled: no + http: + log-enabled: no diff --git a/roles/influxdb/handlers/main.yaml b/roles/influxdb/handlers/main.yaml new file mode 100644 index 0000000..624c994 --- /dev/null +++ b/roles/influxdb/handlers/main.yaml @@ -0,0 +1,14 @@ +--- +- name: reload influxdb + service: + name: "{{ influxdb_service_name }}" + state: restarted + when: influxdb_service_enabled + +- name: influxdb daemon-reload + systemd: + name: "{{ influxdb_service_name }}" + daemon_reload: yes + state: restarted + +# vim:ft=yaml.ansible: diff --git a/roles/influxdb/tasks/Debian.yaml b/roles/influxdb/tasks/Debian.yaml new file mode 100644 index 0000000..33f574f --- /dev/null +++ b/roles/influxdb/tasks/Debian.yaml @@ -0,0 +1,12 @@ +--- +- name: add influx apt key + apt_key: + url: https://repos.influxdata.com/influxdb.key + state: present + +- name: configure apt repository + apt_repository: + repo: "deb https://repos.influxdata.com/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} stable" + filename: influxdb + update_cache: yes + state: present diff --git a/roles/influxdb/tasks/main.yaml b/roles/influxdb/tasks/main.yaml new file mode 100644 index 0000000..128a689 --- /dev/null +++ b/roles/influxdb/tasks/main.yaml @@ -0,0 +1,44 @@ +--- +- name: gather os specific variables + include_vars: "{{ lookup('first_found', possible_files) }}" + vars: + possible_files: + files: + - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml" + - "{{ ansible_distribution }}.yaml" + - "{{ ansible_os_family }}.yaml" + - "default.yaml" + paths: + - vars + +- name: include os specific tasks + include_tasks: "{{ lookup('first_found', possible_files) }}" + vars: + possible_files: + files: + - "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml" + - "{{ ansible_distribution }}.yaml" + - "{{ ansible_os_family }}.yaml" + - "default.yaml" + paths: + - tasks + +- name: install package + package: + name: "{{ influxdb_package_name }}" + state: "{{ influxdb_package_state }}" + +- name: configure + template: + src: influxdb.conf.j2 + dest: /etc/influxdb/influxdb.conf + owner: root + group: root + mode: 0644 + notify: reload influxdb + +- name: manage service + service: + name: "{{ influxdb_service_name }}" + state: "{{ influxdb_service_state }}" + enabled: "{{ influxdb_service_enabled }}" diff --git a/roles/influxdb/templates/influxdb.conf.j2 b/roles/influxdb/templates/influxdb.conf.j2 new file mode 100644 index 0000000..19ed9c7 --- /dev/null +++ b/roles/influxdb/templates/influxdb.conf.j2 @@ -0,0 +1,38 @@ +{%- macro toml_scalar(v, seq=False) -%} +{% if v is string %} + "{{ v | quote }}"{% if seq %},{% endif %} +{% elif v is sameas True or v is sameas False %} + {{ v | bool | lower }}{% if seq %},{% endif %} +{% elif v is sameas None %} + ""{% if seq %},{% endif %} +{% elif v is number %} + {{ v }}{% if seq %},{% endif %} +{% endif %} +{%- endmacro -%} + +{%- macro render_section(config = {}) -%} +{% for k, v in config.items() | default({}) %} +{% if v is mapping %} +[{{ k }}] +{{ render_section(v) }} +{% elif v is string %} +{{ k }} = "{{ v | quote }}" +{% elif v is sameas True or v is sameas False %} +{{ k }} = {{ v | bool | lower }} +{% elif v is sameas None %} +{{ k }} = "" +{% elif v is number %} +{{ k }} = {{ v }} +{% elif v is sequence %} +{{ k }} = [ +{% for i in v | default([]) %} + {{ toml_scalar(i, seq=True) }} +{% endfor %} +] +{% endif %} +{% endfor %} +{%- endmacro -%} + +# {{ ansible_managed }} + +{{ render_section(influxdb_config) }} diff --git a/roles/influxdb/vars/default.yaml b/roles/influxdb/vars/default.yaml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/influxdb/vars/default.yaml @@ -0,0 +1 @@ +---