From 3ccdb51c22f72de4612d5514d9e20fda3d529de5 Mon Sep 17 00:00:00 2001 From: Christopher Svensson Date: Thu, 25 Feb 2021 13:37:13 +0100 Subject: [PATCH] Added support for Beats modules Signed-off-by: Christopher Svensson --- defaults/main.yml | 1 + tasks/beats-config.yml | 12 ++++++++++++ tasks/beats-modules.yml | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 tasks/beats-modules.yml diff --git a/defaults/main.yml b/defaults/main.yml index 3ff9346..78364d9 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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" diff --git a/tasks/beats-config.yml b/tasks/beats-config.yml index a2ce7ba..46def47 100644 --- a/tasks/beats-config.yml +++ b/tasks/beats-config.yml @@ -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 diff --git a/tasks/beats-modules.yml b/tasks/beats-modules.yml new file mode 100644 index 0000000..bb4427d --- /dev/null +++ b/tasks/beats-modules.yml @@ -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