This commit is contained in:
SebClem 2022-01-15 18:25:03 +01:00
commit 3dcd1b88fc
No known key found for this signature in database
GPG Key ID: 3D8E353F900B1305
10 changed files with 243 additions and 0 deletions

10
README.md Normal file
View File

@ -0,0 +1,10 @@
![publish](https://github.com/dzervas/ansible-vector/workflows/publish/badge.svg)
# Vector ansible role
This is an ansible role to set up [vector](https://vector.dev).
It translates the YAML configuration to TOML, so any configuration is possible.
For available variables check out [defaults](roles/vector/defaults/main.yml)
Currently only amd64, arch64, arch7 through deb and rpm packages are supported

23
defaults/main.yml Normal file
View File

@ -0,0 +1,23 @@
vector_template: vector.toml.j2
vector_config_file: /etc/vector/vector.toml
vector_nightly: no
vector_version: "{{ vector_nightly | ternary('nightly','latest') }}"
add_vector_docker_group: no # Add vector user to "docker" group
add_vector_journal_group: no # Add vector user to "systemd-journal" group
sources:
journald:
type: journald
current_boot_only: true
transforms:
grok:
type: grok_parser
inputs:
- journald
pattern: '(?<capture>\\d+)%{GREEDYDATA}'
sinks:
vector:
type: vector
inputs: ["journald"]
address: "vector.example.com:9000"

5
handlers/main.yml Normal file
View File

@ -0,0 +1,5 @@
- name: restart vector
service:
state: restarted
daemon_reload: yes
name: vector

20
meta/main.yml Normal file
View File

@ -0,0 +1,20 @@
---
galaxy_info:
role_name: vector
namespace: dzervas
author: Dimitris Zervas <dzervas@dzervas.gr>
description: vector.dev ansible role
license: MIT
platforms:
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all
galaxy_tags:
- vector
- logging
- monitoring
min_ansible_version: 2.9

View File

@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include vector"
include_role:
name: "vector"

View File

@ -0,0 +1,61 @@
---
dependency:
name: galaxy
driver:
name: docker
lint: |
set -e
yamllint .
ansible-lint
flake8
platforms:
- name: debian10
image: jrei/systemd-debian:10
privileged: true
command: /lib/systemd/systemd
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: debian9
image: jrei/systemd-debian:9
privileged: true
command: /lib/systemd/systemd
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: ubuntu1804
image: jrei/systemd-ubuntu:18.04
privileged: true
command: /lib/systemd/systemd
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: ubuntu2004
image: jrei/systemd-ubuntu:20.04
privileged: true
command: /lib/systemd/systemd
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- name: centos8
image: jrei/systemd-centos:8
privileged: true
command: /usr/sbin/init
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
provisioner:
name: ansible
verifier:
name: ansible

View File

@ -0,0 +1,20 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Execute vector
command: vector --version
changed_when: false
register: vector_version_rc
- name: Check grok pattern is not mangled
lineinfile:
path: /etc/vector/vector.toml
line: ' pattern = "(?<capture>\\d+)%{GREEDYDATA}"'
diff: true
register: grok_pattern_rc
- name: Assert vector is installed
assert:
that:
- vector_version_rc is success
- grok_pattern_rc is not changed

65
tasks/main.yml Normal file
View File

@ -0,0 +1,65 @@
# Workaround for latest version being named against a version number
- name: Get latest version
uri:
url: https://s3.amazonaws.com/packages.timber.io/?prefix=vector/latest&max-keys=1
return_content: true
register: bucket_content
when: vector_version == "latest"
- name: Set latest version
set_fact:
vector_version: "{{ bucket_content.content | regex_replace('.*\\n.*<Key>[^-]+-(?P<version>[\\d\\.]+)-.*','\\g<version>') }}"
when: vector_version == "latest"
- name: Install Vector (Debian)
apt:
deb: "https://packages.timber.io/vector/{{ version }}/vector-{{ version }}-{{ arch }}.deb"
install_recommends: yes
notify:
- restart vector
vars:
version: "{{ (vector_version == 'nightly')| bool | ternary('nightly/latest', vector_version) }}"
arch: "{{ vector_debian_arch[ansible_machine] }}"
when: ansible_os_family == 'Debian'
- name: Install Vector (RedHat)
yum:
name: "https://packages.timber.io/vector/{{ version }}/vector-{{ package_version }}.{{ arch }}.rpm"
state: present
disable_gpg_check: yes # package is not signed
notify:
- restart vector
vars:
version: "{{ (vector_version == 'nightly')| bool | ternary('nightly/latest', vector_version) }}"
package_version: "{{ vector_version is match('latest') | ternary(vector_version, vector_version ~ '-1') }}"
arch: "{{ vector_redhat_arch[ansible_machine] }}"
when: ansible_os_family == 'RedHat'
- name: Copy config
template:
src: "{{ vector_template }}"
dest: "{{ vector_config_file }}"
mode: 0644
notify: restart vector
- name: Add vector user to docker group
user:
name: vector
groups: docker
append: yes
when: add_vector_docker_group | default(no)
notify: restart vector
- name: Add vector user to systemd-journal group
user:
name: vector
groups: systemd-journal
append: yes
when: add_vector_journal_group | default(no)
notify: restart vector
- name: Start Vector
service:
state: started
enabled: yes
name: vector

24
templates/vector.toml.j2 Normal file
View File

@ -0,0 +1,24 @@
# Set global options
data_dir = "/var/lib/vector"
{% set loop_helper = {
"sources": (sources | default({})),
"transforms": (transforms | default({})),
"sinks": (sinks | default({}))
} %}
{% for name, cat in loop_helper.items() | sort(attribute='0') %}
{% for key, value in cat.items() | sort(attribute='0') %}
[{{ name }}.{{ key }}]
{% if value %}
{%- for skey, svalue in value.items() | sort(attribute='0') %}
{%- if svalue is string %}
{{ skey }} = "{{ svalue }}"
{% else %}
{{ skey }} = {{ svalue | tojson }}
{% endif %}
{% endfor %}
{%- endif %}
{% endfor %}
{% endfor %}

8
vars/main.yml Normal file
View File

@ -0,0 +1,8 @@
vector_debian_arch:
armv7l: armhf
aarch64: arm64
x86_64: amd64
vector_redhat_arch:
armv7l: armv7hl
aarch64: aarch64
x86_64: x86_64