Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Added support for Beats modules
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Svensson <[email protected]>
  • Loading branch information
stoffus committed Feb 25, 2021
1 parent 9b87312 commit 3ccdb51
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ logging_conf: {"files":{"rotateeverybytes":10485760}}
output_conf: {"elasticsearch":{"hosts":["localhost:9200"]}}
beats_pid_dir: "/var/run"
beats_conf_dir: "/etc/{{beat}}"
beats_modules_dir: "/etc/{{beat}}/modules.d"
12 changes: 12 additions & 0 deletions tasks/beats-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,15 @@
group: root
when: default_ilm_policy is defined
notify: restart the service

- name: Assert modules.path presence
assert:
that:
- beat_conf.filebeat.config.modules.path is defined
fail_msg: 'You need to configure beat_conf.filebeat.config.modules.path for modules to be loaded'
when: beat_modules is defined

- name: Set up and configure modules
include_tasks: beats-modules.yml
with_dict: "{{ beat_modules }}"
when: beat_modules is defined
24 changes: 24 additions & 0 deletions tasks/beats-modules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- name: Disable modules
become: yes
file:
path: "{{ beats_modules_dir }}/{{ item.key }}.yml"
state: absent
when: item.value.enabled is defined and not item.value.enabled
notify: restart the service

- name: Enable modules with default config
become: yes
copy:
remote_src: yes
src: "{{ beats_modules_dir }}/{{ item.key }}.yml.disabled"
dest: "{{ beats_modules_dir }}/{{ item.key }}.yml"
when: (not item.value.enabled is defined or item.value.enabled) and not item.value.config is defined
notify: restart the service

- name: Set up modules with custom config
become: yes
copy:
content: "{{ item.value.config | to_nice_yaml(indent=2) }}"
dest: "{{ beats_modules_dir }}/{{ item.key }}.yml"
when: (not item.value.enabled is defined or item.value.enabled) and item.value.config is defined
notify: restart the service

0 comments on commit 3ccdb51

Please sign in to comment.