From 25a65609410a57eb3b2bbf4df95d14d359343374 Mon Sep 17 00:00:00 2001 From: Nikolaos Kakouros Date: Sun, 4 Sep 2022 21:12:32 +0000 Subject: [PATCH] Adds option to disable filebeat modules --- defaults/main.yml | 5 ++- tasks/flavor-specific/filebeat.yml | 57 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 4b30273..1f094ec 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -309,7 +309,10 @@ beats_filebeat_module_files: [] # for consistency). beats_filebeat_modules: [] -# The list of filebeat modules to enable. +# List of filebeat modules to enable. + +beats_filebeat_modules_disable: [] +# List of filebeat modules to disable. # }}} # Heartbeat specifics {{{ beats_heartbeat_monitors_path: /etc/heartbeat/monitors.d/ diff --git a/tasks/flavor-specific/filebeat.yml b/tasks/flavor-specific/filebeat.yml index a7affe9..3ac997e 100644 --- a/tasks/flavor-specific/filebeat.yml +++ b/tasks/flavor-specific/filebeat.yml @@ -145,3 +145,60 @@ | default('', true) }} when: ansible_os_family == 'Windows' + +- name: "{{ beats_flavor }}: Disable filebeat modules on Linux" + block: + - name: "{{ beats_flavor }}: Check if filebeat modules are disabled on Linux" + stat: + path: "{{ beats_filebeat_modules_dir }}/{{ _beats__module }}.yml" + register: _beats_filebeat_disabled_modules + loop: "{{ beats_filebeat_modules }}" + loop_control: + loop_var: _beats__module + + - name: "{{ beats_flavor }}: Disable filebeat modules on Linux" + command: "{{ beats_linux_exec }} modules disable {{ modules_to_disable }}" + when: modules_to_disable | length > 0 + vars: + modules_to_disable: >- + {{ + beats_filebeat_modules_disable + | reject('in', _beats_filebeat_disabled_modules.results + | selectattr('stat.exists') + | map(attribute='stat.path') + | map('basename') + | map('replace', '.yml', '') + ) + | join(' ') + | default('', true) + }} + when: ansible_os_family != 'Windows' + +- name: "{{ beats_flavor }}: Disable filebeat modules on Windows" + block: + - name: "{{ beats_flavor }}: Check if filebeat modules are disabled on Windows" + win_stat: + path: "{{ beats_filebeat_modules_dir }}/{{ _beats__module }}.yml" + register: _beats_filebeat_disabled_modules + loop: "{{ beats_filebeat_modules }}" + loop_control: + loop_var: _beats__module + + - name: "{{ beats_flavor }}: Disable filebeat modules on Windows" + win_command: "{{ beats_win_exec }} modules disable {{ modules_to_disable }}" + when: modules_to_disable | length > 0 + vars: + modules_to_disable: >- + {{ + beats_filebeat_modules_disable + | reject('in', _beats_filebeat_disabled_modules.results + | selectattr('stat.exists') + | map(attribute='stat.path') + | map('basename') + | map('replace', '.yml', '') + ) + | join(' ') + | default('', true) + }} + + when: ansible_os_family == 'Windows'