Skip to content
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ filebeat_apt_repo: "{{ filebeat_version|version_compare('5', '<')|ternary(filebe
filebeat_repo_url_v1: https://packages.elastic.co/beats/yum/el/$basearch
filebeat_repo_url_v5: https://artifacts.elastic.co/packages/5.x/yum
filebeat_repo_url: "{{ filebeat_version|version_compare('5', '<')|ternary(filebeat_repo_url_v1, filebeat_repo_url_v5) }}"

# Set to false for AMI building with packer
start_services: true
1 change: 1 addition & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
service:
name: filebeat
state: restarted
when: start_services
18 changes: 16 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,22 @@
- name: flush handlers to prevent start then restart
meta: flush_handlers

- name: start and enable filebeat
- name: check if systemd present
stat:
path: /bin/systemctl
register: stat_result

- name: reload systemd daemon
shell: "systemctl daemon-reload"
when: stat_result.stat.exists == true

- name: enable filebeat
service:
name: filebeat
state: started
enabled: true

- name: start filebeat
service:
name: filebeat
state: started
when: start_services
9 changes: 9 additions & 0 deletions tasks/redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@
state: present
notify:
- restart filebeat

- name: modify filebeat service file to include environment variables
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably make sense as a drop-in unit instead of modifying the unit directly: https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Description

Along with a unit file foo.service, a "drop-in" directory foo.service.d/ may exist. All files with the suffix ".conf" from this directory will be parsed after the unit file itself is parsed. This is useful to alter or add configuration settings for a unit, without having to modify unit files.

lineinfile:
path: /usr/lib/systemd/system/filebeat.service
regexp: '^EnvironmentFile=/etc/sysconfig/filebeat$'
line: "EnvironmentFile=/etc/sysconfig/filebeat"
insertafter: '^\[Service\]$'
notify:
- restart filebeat