Bootstrap influx.create.db role

This commit is contained in:
Wilfried OLLIVIER 2019-07-10 17:11:05 +02:00
commit e6ce2b5c97
7 changed files with 150 additions and 0 deletions

13
LICENCE Normal file
View File

@ -0,0 +1,13 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2019 Wilfried OLLIVIER <wollivier@fdn.fr>
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.

50
README.md Normal file
View File

@ -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

23
defaults/main.yml Normal file
View File

@ -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

21
meta/main.yml Normal file
View File

@ -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: []

37
tasks/main.yml Normal file
View File

@ -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 }}"

1
tests/inventory Normal file
View File

@ -0,0 +1 @@
galaxy-vagrant.example.com

5
tests/test.yml Normal file
View File

@ -0,0 +1,5 @@
---
- hosts: galaxy-vagrant.example.com
remote_user: root
roles:
- role: ../galaxy-influx.create.db