From 3c6da980c2ad3a34dfa516226bdf90d48c26a65e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexander=20K=C3=A4b?= <alexander.kaeb@h-da.de>
Date: Mon, 19 Aug 2024 16:01:50 +0200
Subject: [PATCH] feat: provide way to add tags to sidecar.yml and implement
 workaround symlink

---
 README.md                |  8 +++++++-
 tasks/sidecar.yml        | 23 +++++++++++++++++++++++
 templates/sidecar.yml.j2 |  7 +++++++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index ab0e778..9484e0a 100644
--- a/README.md
+++ b/README.md
@@ -24,6 +24,12 @@ graylog_sidecar_server_url:
 graylog_sidecar_server_api_token:
 ```
 
+## Auto fetch configs
+
+You can specify a list of tags that will be used to auto fetch configs from the graylog
+server. To do so add the `config_tags` variable and provide a list of tags for which the
+configs should be pulled by the sidecar.
+
 ## Node Certificates
 
 For node certificates to be generated you will need to create an additional host group
@@ -38,7 +44,7 @@ via a host group called `graylog-nodes`.
 You may also use a completely separate host to store the CA files for Graylog and the
 Sidecar service. If this is the case, you need to set the `use_central_ca_host` variable
 to `true` and provide a host group called `ca-store`. The other groups mentioned earlier
-may be omitted.
+**need to be omitted**.
 
 The log node CA file must be available at: `/etc/graylog/graylog-ca.pem`
 The sidecar CA file must be available at: `/etc/graylog/sidecar/sidecar-ca.pem`
diff --git a/tasks/sidecar.yml b/tasks/sidecar.yml
index a5be537..14d5c46 100644
--- a/tasks/sidecar.yml
+++ b/tasks/sidecar.yml
@@ -79,6 +79,29 @@
   changed_when: false
   become: true
 
+- name: Create Workaround Symlink for filebeat when version >= '1.5.0'
+  when: sidecar_version is version('1.5.0', 'ge')
+  become: true
+  block:
+    - name: Create Workaround Symlink | Ensure directories exist
+      ansible.builtin.file:
+        path: '/usr/share/filebeat/bin/'
+        state: directory
+        mode: '0755'
+
+    - name: Create Workaround Symlink | Check if old filebeat version exists
+      ansible.builtin.stat:
+        path: '/usr/share/filebeat/bin/filebeat'
+      register: filebeat_bin
+
+    - name: Create Workaround Symlink | Create Symlink if required
+      when: not filebeat_bin.stat.exists
+      ansible.builtin.file:
+        src: '/usr/lib/graylog-sidecar/filebeat'
+        dest: '/usr/share/filebeat/bin/filebeat'
+        state: link
+      
+
 - name: Enable / start sidecar service
   ansible.builtin.service:
     name: graylog-sidecar
diff --git a/templates/sidecar.yml.j2 b/templates/sidecar.yml.j2
index f55db49..dd5db8a 100644
--- a/templates/sidecar.yml.j2
+++ b/templates/sidecar.yml.j2
@@ -3,3 +3,10 @@
 server_url: {{ graylog_sidecar_server_url }}
 server_api_token: {{ graylog_sidecar_server_api_token }}
 node_id: {{ graylog_sidecar_node_id }}
+
+{% if config_tags is not none and config_tags | length > 0 %}
+tags:
+{% for tag in config_tags %}
+  - {{ tag }}
+{% endfor %}
+{% endif %}
\ No newline at end of file
-- 
GitLab