From 6ad76e4b330e2ee14ce515a880580bc66398b993 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Wed, 3 Dec 2025 22:01:58 -0600 Subject: [PATCH] r/fluent-bit: Support drop-in configuration files Fluent Bit supports including configuration fragments from other files using its `includes` option. Adding a glob pattern to the default configuration will allow other roles to supply additional configuration by creating files in the `/etc/fluent-bit/include` directory. This makes composition of configuration significantly easier. Unfortunately, `fluent-bit` has a quirk in that there must exist at least one file matching the glob pattern, or it will fail to start. To work around this, we must supply an empty fragment. --- roles/fluent-bit/defaults/main.yml | 2 ++ roles/fluent-bit/tasks/main.yml | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/roles/fluent-bit/defaults/main.yml b/roles/fluent-bit/defaults/main.yml index b50d6f4..93ef4d7 100644 --- a/roles/fluent-bit/defaults/main.yml +++ b/roles/fluent-bit/defaults/main.yml @@ -1,4 +1,6 @@ fluent_bit_config: + includes: + - /etc/fluent-bit/include/*.yml service: '{{ fluent_bit_config_service }}' parsers: '{{ fluent_bit_parsers }}' multiline_parsers: '{{ fluent_bit_multiline_parsers }}' diff --git a/roles/fluent-bit/tasks/main.yml b/roles/fluent-bit/tasks/main.yml index 55c25ee..39005de 100644 --- a/roles/fluent-bit/tasks/main.yml +++ b/roles/fluent-bit/tasks/main.yml @@ -5,6 +5,29 @@ tags: - install +- name: ensure fluent-bit config include directory exists + file: + path: /etc/fluent-bit/include + owner: root + group: root + mode: u=rwx,go= + state: directory + tags: + - config +# fluent-bit will fail to start if a glob pattern listed in `includes` does not +# match any files. To allow roles to drop additiona configuration files in the +# include directory without modifying the main configuration file, we need to +# have an empty file in the include directory all the time. +- name: ensure fluent-bit empty include file exists + copy: + dest: /etc/fluent-bit/include/_.yml + content: '' + owner: root + group: root + mode: u=rwx,go= + tags: + - config + - name: ensure fluent-bit is configured copy: dest: /etc/fluent-bit/fluent-bit.yml