Skip to content

Commit

Permalink
Initial opensource version
Browse files Browse the repository at this point in the history
  • Loading branch information
hatemosphere committed Oct 16, 2019
0 parents commit 6804a23
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
skip_list:
- '204'
- '303'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.kitchen/
.vagrant/
playbook.retry
4 changes: 4 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include:
- project: "public-group/gitlab-shared-pipelines"
ref: master
file: "/gitlab-ansible-tests.yml"
25 changes: 25 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
driver:
name: vagrant

provisioner:
hosts: test-kitchen
name: ansible_playbook
ansible_connection: ssh
require_chef_for_busser: false
require_ruby_for_busser: false
ansible_version: 2.7.10-1ppa~trusty
ansible_host_key_checking: false
ansible_verbosity: 2
ansible_verbose: true
playbook: tests/playbook.yml

platforms:
- name: debian/stretch64-9.6
driver:
box: debian/stretch64
box_version: 9.6

suites:
- name: default

51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Role Name
=========

VictoriaMetrics

Role Variables
--------------

```
---
victoriametrics_repo_url: "https://github.com/VictoriaMetrics/VictoriaMetrics"
victoriametrics_download_url: "{{ victoriametrics_repo_url }}/releases/download/{{ victoriametrics_version }}/victoria-metrics-{{ victoriametrics_version }}.tar.gz"
victoriametrics_version: "v1.28.0"
victoriametrics_system_user: "victoriametrics"
victoriametrics_system_group: "{{ victoriametrics_system_user }}"
victoriametrics_delete_auth_key: "secret"
victoriametrics_snapshot_auth_key: "secret"
victoriametrics_service_args: ""
```


Example Playbook
----------------

```
- hosts: servers
roles:
- "ansible-victoriametrics-role"
```

Tests
------------
```
# deps
gem install kitchen-ansible --no-document
gem install kitchen-vagrant --no-document
# test
kitchen converge
```

License
-------

BSD

Author Information
------------------

[email protected]
10 changes: 10 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# defaults file for VictoriaMetrics
victoriametrics_repo_url: "https://github.com/VictoriaMetrics/VictoriaMetrics"
victoriametrics_download_url: "{{ victoriametrics_repo_url }}/releases/download/{{ victoriametrics_version }}/victoria-metrics-{{ victoriametrics_version }}.tar.gz"
victoriametrics_version: "v1.13.0"
victoriametrics_system_user: "victoriametrics"
victoriametrics_system_group: "{{ victoriametrics_system_user }}"
victoriametrics_data_dir: "/var/opt/victoria-metrics/"
victoriametrics_service_args: "-storageDataPath {{ victoriametrics_data_dir }}"
victoriametrics_max_open_files: 2097152
8 changes: 8 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# handlers file for VictoriaMetrics
---
- name: Restart VictoriaMetrics service
become: true
systemd:
daemon_reload: true
name: victoriametrics
state: restarted
13 changes: 13 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
galaxy_info:
author: [email protected]
description: Role for VictoriaMetrics
company: Dreamteam
license: BSD
min_ansible_version: 2.4
galaxy_tags: []
platforms:
- name: Debian
versions:
- 9
dependencies: []

10 changes: 10 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: Copy VictoriaMetrics systemd unit file
template:
src: victoriametrics.service.j2
dest: /etc/systemd/system/victoriametrics.service
owner: root
group: root
mode: 0644
notify: Restart VictoriaMetrics service
no_log: True
42 changes: 42 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- name: Create VictoriaMetrics system group
group:
name: "{{ victoriametrics_system_group }}"
state: present
system: true
when: victoriametrics_system_group != "root"

- name: Create VictoriaMetrics system user
user:
name: "{{ victoriametrics_system_user }}"
groups: "{{ victoriametrics_system_group }}"
append: true
shell: /usr/sbin/nologin
system: true
createhome: false
when: victoriametrics_system_user != "root"

- name: Ensure existense of /usr/local/bin
file:
path: /usr/local/bin
state: directory
mode: 0755

- name: Ensure existense of VictoriaMetrics storage directory
file:
path: "{{ victoriametrics_data_dir }}"
state: directory
mode: 0755
owner: "{{ victoriametrics_system_user }}"
group: "{{ victoriametrics_system_group }}"

- name: Download and unarchive VictoriaMetrics release binary
unarchive:
src: "{{ victoriametrics_download_url }}"
dest: /usr/local/bin
mode: 0750
owner: "{{ victoriametrics_system_user }}"
group: "{{ victoriametrics_system_group }}"
remote_src: yes
notify: Restart VictoriaMetrics service
when: not ansible_check_mode
13 changes: 13 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# tasks file for VictoriaMetrics
- import_tasks: preinstall.yml
- import_tasks: install.yml
- import_tasks: configure.yml

- name: Ensure VictoriaMetrics service is enabled on boot
become: true
systemd:
daemon_reload: true
name: victoriametrics
enabled: true
state: started
15 changes: 15 additions & 0 deletions tasks/preinstall.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Assert usage of systemd as an init system
assert:
that: ansible_service_mgr == 'systemd'
msg: "This role only works with systemd"

- name: Get systemd version
command: systemctl --version
changed_when: false
check_mode: false
register: __systemd_version

- name: Set systemd version fact
set_fact:
victoriametrics_systemd_version: "{{ __systemd_version.stdout_lines[0].split(' ')[-1] }}"
31 changes: 31 additions & 0 deletions templates/victoriametrics.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{{ ansible_managed | comment }}

[Unit]
Description=Description=VictoriaMetrics service
After=network.target

[Service]
Type=simple
LimitNOFILE={{ victoriametrics_max_open_files }}
User={{ victoriametrics_system_user }}
Group={{ victoriametrics_system_group }}
ExecStart=/usr/local/bin/victoria-metrics-prod \
{{ victoriametrics_service_args }}

SyslogIdentifier=victoriametrics
Restart=always

PrivateTmp=yes
ProtectHome=yes
NoNewPrivileges=yes

ProtectSystem=full

{% if victoriametrics_systemd_version | int >= 232 %}
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=yes
{% endif %}

[Install]
WantedBy=multi-user.target
5 changes: 5 additions & 0 deletions tests/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: all
become: true
roles:
- "ansible-victoriametrics-role"

0 comments on commit 6804a23

Please sign in to comment.