Skip to content

Commit

Permalink
feat(vector): add vector to some ansible roles
Browse files Browse the repository at this point in the history
Signed-off-by: Devin Buhl <[email protected]>
  • Loading branch information
onedr0p committed Dec 27, 2021
1 parent 3293506 commit beb5f5e
Showing 14 changed files with 182 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ansible/pikvm/inventory/hosts.yml
Original file line number Diff line number Diff line change
@@ -2,5 +2,5 @@
pikvm:
hosts:
pikvm:
ansible_host: 192.168.42.65
ansible_host: 192.168.1.80
ansible_user: root
2 changes: 2 additions & 0 deletions ansible/pikvm/playbooks/pikvm.yml
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
tags: acme
- role: node-exporter.pikvm
tags: node-exporter
- role: vector.pikvm
tags: vector
# TODO: Promtail will not work for journal on arm/arm64
# https://github.com/grafana/loki/issues/1459
# "WARNING!!! Journal target was configured but support for reading the systemd journal is not compiled into this build of promtail!"
1 change: 1 addition & 0 deletions ansible/pikvm/roles/vector.pikvm/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---
7 changes: 7 additions & 0 deletions ansible/pikvm/roles/vector.pikvm/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Restart vector
ansible.builtin.systemd:
name: vector.service
state: restarted
enabled: true
daemon_reload: true
46 changes: 46 additions & 0 deletions ansible/pikvm/roles/vector.pikvm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
- name: Create vector directories
ansible.builtin.file:
path: /etc/vector
state: directory

- name: Check current vector version
ansible.builtin.command: "/usr/local/bin/vector --version"
failed_when: false
changed_when: false
register: vector_version_check

- name: Download and unarchive vector into temporary location
ansible.builtin.unarchive:
src: "{{ vector_download_url }}"
dest: /tmp
remote_src: true
mode: 0755
when: >
vector_version_check.stdout is not defined
or vector_version not in vector_version_check.stdout
register: vector_download_check

- name: Move vector binary into place
ansible.builtin.copy:
src: /tmp/vector-armv7-unknown-linux-gnueabihf/bin/vector
dest: /usr/local/bin/vector
mode: 0755
remote_src: true
when: >
vector_version_check.stdout is not defined
or vector_version not in vector_version_check.stdout
notify: Restart vector

- block:
- name: Copy vector config
ansible.builtin.template:
src: vector.yaml.j2
dest: /etc/vector/vector.yaml
mode: 0755
- name: Create vector systemd file
ansible.builtin.template:
src: vector.service.j2
dest: /etc/systemd/system/vector.service
mode: 0644
notify: Restart vector
12 changes: 12 additions & 0 deletions ansible/pikvm/roles/vector.pikvm/templates/vector.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Vector
After=network-online.target
Wants=network-online.target

[Service]
TimeoutStartSec=0
User=root
ExecStart=/usr/local/bin/vector --config /etc/vector/vector.yaml

[Install]
WantedBy=multi-user.target
19 changes: 19 additions & 0 deletions ansible/pikvm/roles/vector.pikvm/templates/vector.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
data_dir: /tmp
sources:
journal_logs:
type: journald
journal_directory: /run/log/journal
sinks:
loki_journal_sink:
type: loki
inputs:
- journal_logs
endpoint: https://loki.{{ SECRET_PUBLIC_DOMAIN }}
encoding:
codec: json
batch:
max_bytes: 400000
out_of_order_action: rewrite_timestamp
labels:
hostname: "{{ '{{ name }}' }}"
8 changes: 8 additions & 0 deletions ansible/pikvm/roles/vector.pikvm/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
#
# SECRET* vars are encrypted with sops
#

# TODO: Renovate vector version in pikvm ansible
vector_version: 0.18.1
vector_download_url: https://github.com/vectordotdev/vector/releases/download/v{{ vector_version }}/vector-{{ vector_version }}-armv7-unknown-linux-gnueabihf.tar.gz
7 changes: 7 additions & 0 deletions ansible/storage/roles/apps.storage/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -61,3 +61,10 @@
state: restarted
enabled: true
daemon_reload: true

- name: Restart vector
ansible.builtin.systemd:
name: "[email protected]"
state: restarted
enabled: true
daemon_reload: true
16 changes: 10 additions & 6 deletions ansible/storage/roles/apps.storage/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -33,12 +33,12 @@
tags:
- vault

# TODO: Promtail has issues resolving DNS
# https://github.com/grafana/loki/issues/3994
# https://grafana.slack.com/archives/CEPJRLQNL/p1639934111400500
- import_tasks: promtail.yml
tags:
- promtail
# # TODO: Promtail has issues resolving DNS
# # https://github.com/grafana/loki/issues/3994
# # https://grafana.slack.com/archives/CEPJRLQNL/p1639934111400500
# - import_tasks: promtail.yml
# tags:
# - promtail

- import_tasks: traefik.yml
tags:
@@ -56,6 +56,10 @@
tags:
- time-machine

- import_tasks: vector.yml
tags:
- vector

- import_tasks: docker.yml
tags:
- docker
26 changes: 26 additions & 0 deletions ansible/storage/roles/apps.storage/tasks/vector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Create vector directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
loop:
- "{{ containers_base_dir }}/apps/vector"
- "{{ containers_base_dir }}/data/vector"

- block:
- name: Create vector docker compose file
ansible.builtin.template:
src: vector/docker-compose.yml.j2
dest: "{{ containers_base_dir }}/apps/vector/docker-compose.yml"
mode: 0755
- name: Create vector config
ansible.builtin.template:
src: vector/vector.yaml.j2
dest: "{{ containers_base_dir }}/apps/vector/vector.yaml"
mode: 0755
- name: Create vector systemd service file
ansible.builtin.template:
src: "[email protected]"
dest: "/etc/systemd/system/[email protected]"
mode: 0644
notify: Restart vector
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
version: "3.8"

services:
vector:
image: docker.io/timberio/vector:0.18.1-debian
container_name: vector
restart: unless-stopped
network_mode: host
command:
- --config=/etc/vector/vector.yaml
volumes:
- "{{ containers_base_dir }}/apps/vector/vector.yaml:/etc/vector/vector.yaml:ro"
- vector-data:/vector-data-dir
- /var/log:/var/log:ro

volumes:
vector-data:
driver: local
driver_opts:
type: none
o: bind
device: "{{ containers_base_dir }}/data/vector"
19 changes: 19 additions & 0 deletions ansible/storage/roles/apps.storage/templates/vector/vector.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
data_dir: /vector-data-dir
sources:
journal_logs:
type: journald
journal_directory: /var/log/journal
sinks:
loki_journal_sink:
type: loki
inputs:
- journal_logs
endpoint: https://loki.{{ SECRET_PUBLIC_DOMAIN }}
encoding:
codec: json
batch:
max_bytes: 400000
out_of_order_action: rewrite_timestamp
labels:
hostname: "{{ '{{ name }}' }}"
2 changes: 1 addition & 1 deletion hack/valetudo/vector-config.yml
Original file line number Diff line number Diff line change
@@ -29,4 +29,4 @@ sinks:
tls:
verify_certificate: false
labels:
hostname: valetudo
hostname: "{{ name }}"

0 comments on commit beb5f5e

Please sign in to comment.