commit e6ce2b5c97fec6e4a24b7c26434aa13a52610dcd Author: Wilfried OLLIVIER Date: Wed Jul 10 17:11:05 2019 +0200 Bootstrap influx.create.db role 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..d384716 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +galaxy-influx.create.db +======================= + +Galaxy role to create InfluxDB database and user + +Requirements +------------ + +InfluxDB service up and running + +Role Variables +-------------- + +- db_name: name of the db to create +- user_name: name of the user to create +- user_pass: user password + +- admin_user: name of admin user +- admin_pass: password of admin user + +- is_admin: true/false, to enable admin mode or not + +- priv: READ/WRITE/ALL, to setup database priv of user_name on db_name + +- policy_name: name of the retention policy to apply +- policy_duration: duration of the retention policy to apply +- policy_replication: policy replication + +Dependencies +------------ + +- galaxy-influx + +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-influx.create.db + +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..6046cbf --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,23 @@ +--- + +# Database name +db_name: telegraf + +# User and password +user_name: telegraf +user_pass: not24get + +# Admin auth +admin_user: admin +admin_pass: not24get + +# Is Admin (true/false) +is_admin: no + +# priviledges +priv: ALL + +# retention policy +policy_name: monthly +policy_duration: 100d +policy_replication: 1 \ No newline at end of file diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..f9d4720 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,21 @@ +galaxy_info: + author: Wilfried OLLIVIER + description: Galaxy role to create InfluxDB database and user + company: none + + license: WTFPL + + min_ansible_version: 2.4 + + platforms: + - name: Debian + versions: + - Stretch + - Buster + + galaxy_tags: + - influxdb + - 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..1d1d11a --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,37 @@ +--- + +- name: Ensure dependencies + apt: + name: [ 'python-requests', 'python-pip' ] + state: present + +- name: Ensure python-influxdb + pip: + name: influxdb + state: present + +- name: Ensure database + influxdb_database: + login_username: "{{ admin_user }}" + login_password: "{{ admin_pass }}" + database_name: "{{ db_name }}" + +- name: Set retention policy + influxdb_retention_policy: + login_username: "{{ admin_user }}" + login_password: "{{ admin_pass }}" + database_name: "{{ db_name }}" + policy_name: "{{ policy_name }}" + duration: "{{ policy_duration }}" + replication: "{{ policy_replication }}" + +- name: Ensure user and grant access to DB + influxdb_user: + user_name: "{{ user_name }}" + user_password: "{{ user_pass }}" + login_username: "{{ admin_user }}" + login_password: "{{ admin_pass }}" + admin: "{{ is_admin }}" + grants: + - database: "{{ db_name }}" + privilege: "{{ priv }}" diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..38d0757 --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +galaxy-vagrant.example.com diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..bc05788 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: galaxy-vagrant.example.com + remote_user: root + roles: + - role: ../galaxy-influx.create.db \ No newline at end of file