Skip to content

Commit

Permalink
Adds option to disable filebeat modules
Browse files Browse the repository at this point in the history
  • Loading branch information
nkakouros committed Sep 4, 2022
1 parent e1b3613 commit 25a6560
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
57 changes: 57 additions & 0 deletions tasks/flavor-specific/filebeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 25a6560

Please sign in to comment.