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

Commit 3ccdb51

Browse files
committed
Added support for Beats modules
Signed-off-by: Christopher Svensson <stoffus@stoffus.com>
1 parent 9b87312 commit 3ccdb51

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ logging_conf: {"files":{"rotateeverybytes":10485760}}
1212
output_conf: {"elasticsearch":{"hosts":["localhost:9200"]}}
1313
beats_pid_dir: "/var/run"
1414
beats_conf_dir: "/etc/{{beat}}"
15+
beats_modules_dir: "/etc/{{beat}}/modules.d"

tasks/beats-config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,15 @@
8585
group: root
8686
when: default_ilm_policy is defined
8787
notify: restart the service
88+
89+
- name: Assert modules.path presence
90+
assert:
91+
that:
92+
- beat_conf.filebeat.config.modules.path is defined
93+
fail_msg: 'You need to configure beat_conf.filebeat.config.modules.path for modules to be loaded'
94+
when: beat_modules is defined
95+
96+
- name: Set up and configure modules
97+
include_tasks: beats-modules.yml
98+
with_dict: "{{ beat_modules }}"
99+
when: beat_modules is defined

tasks/beats-modules.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- name: Disable modules
2+
become: yes
3+
file:
4+
path: "{{ beats_modules_dir }}/{{ item.key }}.yml"
5+
state: absent
6+
when: item.value.enabled is defined and not item.value.enabled
7+
notify: restart the service
8+
9+
- name: Enable modules with default config
10+
become: yes
11+
copy:
12+
remote_src: yes
13+
src: "{{ beats_modules_dir }}/{{ item.key }}.yml.disabled"
14+
dest: "{{ beats_modules_dir }}/{{ item.key }}.yml"
15+
when: (not item.value.enabled is defined or item.value.enabled) and not item.value.config is defined
16+
notify: restart the service
17+
18+
- name: Set up modules with custom config
19+
become: yes
20+
copy:
21+
content: "{{ item.value.config | to_nice_yaml(indent=2) }}"
22+
dest: "{{ beats_modules_dir }}/{{ item.key }}.yml"
23+
when: (not item.value.enabled is defined or item.value.enabled) and item.value.config is defined
24+
notify: restart the service

0 commit comments

Comments
 (0)