Add variable to define a beat service state

This patch aims to provide the user a way to enable/disable
beats by overriding {beatname}_service_state variable accordingly
to the beats that the users wants to be receiving data.

There are some use cases that users just wants a subset of the
beats provided, mostly to avoid unecessary use of bandwidth
with data that woudn't be used. So the way that this patch proposes
this use case is just enable/disable after install, keeping the service
installed in case of the users needs it.

Change-Id: I2251095d7fcfc48a239fe9d4984269503cc835da
This commit is contained in:
Guilherme Steinmüller 2018-09-19 20:23:07 +00:00
parent 94d8f09b74
commit 7430f6c8d5
18 changed files with 201 additions and 11 deletions

View File

@ -0,0 +1,16 @@
---
# Copyright 2018, Vexxhost, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
auditbeat_service_state: restarted

View File

@ -17,7 +17,7 @@
systemd:
name: "auditbeat"
enabled: true
state: restarted
state: "{{ auditbeat_service_state }}"
daemon_reload: true
when:
- ansible_service_mgr == 'systemd'
@ -26,7 +26,7 @@
- name: Enable and restart auditbeat (upstart)
service:
name: "auditbeat"
state: restarted
state: "{{ auditbeat_service_state }}"
enabled: yes
when:
- ansible_service_mgr == 'upstart'

View File

@ -73,3 +73,21 @@
- name: Force beat handlers
meta: flush_handlers
- name: set auditbeat service state (upstart)
service:
name: "auditbeat"
state: "{{ auditbeat_service_state }}"
enabled: "{{ auditbeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'upstart'
- auditbeat_service_state in ['started', 'stopped']
- name: set auditbeat service state (systemd)
systemd:
name: "auditbeat"
state: "{{ auditbeat_service_state }}"
enabled: "{{ auditbeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'systemd'
- auditbeat_service_state in ['started', 'stopped']

View File

@ -0,0 +1,16 @@
---
# Copyright 2018, Vexxhost, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
filebeat_service_state: restarted

View File

@ -17,7 +17,7 @@
systemd:
name: "filebeat"
enabled: true
state: restarted
state: "{{ filebeat_service_state }}"
daemon_reload: true
when:
- ansible_service_mgr == 'systemd'
@ -26,7 +26,7 @@
- name: Enable and restart filebeat (upstart)
service:
name: "filebeat"
state: restarted
state: "{{ filebeat_service_state }}"
enabled: yes
when:
- ansible_service_mgr == 'upstart'

View File

@ -183,3 +183,21 @@
- name: Force beat handlers
meta: flush_handlers
- name: set filebeat service state (upstart)
service:
name: "filebeat"
state: "{{ filebeat_service_state }}"
enabled: "{{ filebeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'upstart'
- filebeat_service_state in ['started', 'stopped']
- name: set filebeat service state (systemd)
systemd:
name: "filebeat"
state: "{{ filebeat_service_state }}"
enabled: "{{ filebeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'systemd'
- filebeat_service_state in ['started', 'stopped']

View File

@ -0,0 +1,16 @@
---
# Copyright 2018, Vexxhost, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
heartbeat_service_state: restarted

View File

@ -17,7 +17,7 @@
systemd:
name: "heartbeat-elastic"
enabled: true
state: restarted
state: "{{ heartbeat_service_state }}"
daemon_reload: true
when:
- ansible_service_mgr == 'systemd'
@ -26,7 +26,7 @@
- name: Enable and restart heartbeat (upstart)
service:
name: "heartbeat-elastic"
state: restarted
state: "{{ heartbeat_service_state }}"
enabled: yes
when:
- ansible_service_mgr == 'upstart'

View File

@ -79,3 +79,21 @@
- name: Force beat handlers
meta: flush_handlers
- name: set heartbeat service state (upstart)
service:
name: "heartbeat-elastic"
state: "{{ heartbeat_service_state }}"
enabled: "{{ heartbeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'upstart'
- heartbeat_service_state in ['started', 'stopped']
- name: set heartbeat service state (systemd)
systemd:
name: "heartbeat-elastic"
state: "{{ heartbeat_service_state }}"
enabled: "{{ heartbeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'systemd'
- heartbeat_service_state in ['started', 'stopped']

View File

@ -0,0 +1,16 @@
---
# Copyright 2018, Vexxhost, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
journalbeat_service_state: restarted

View File

@ -17,7 +17,7 @@
systemd:
name: "journalbeat"
enabled: true
state: restarted
state: "{{ journalbeat_service_state }}"
daemon_reload: yes
when:
- (elk_package_state | default('present')) != 'absent'

View File

@ -145,3 +145,21 @@
- name: Force beat handlers
meta: flush_handlers
- name: set journalbeat service state (upstart)
service:
name: "journalbeat"
state: "{{ journalbeat_service_state }}"
enabled: "{{ journalbeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'upstart'
- journalbeat_service_state in ['started', 'stopped']
- name: set journalbeat service state (systemd)
systemd:
name: "journalbeat"
state: "{{ journalbeat_service_state }}"
enabled: "{{ journalbeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'systemd'
- journalbeat_service_state in ['started', 'stopped']

View File

@ -16,3 +16,5 @@
#metricbeats monitoring endpoints
elastic_metricbeat_rabbitmq_monitoring_hosts: '"localhost:15672"'
elastic_metricbeat_haproxy_monitoring_hosts: '"unix:///var/run/haproxy.stat"'
metricbeat_service_state: restarted

View File

@ -17,7 +17,7 @@
systemd:
name: "metricbeat"
enabled: true
state: restarted
state: "{{ metricbeat_service_state }}"
daemon_reload: true
when:
- ansible_service_mgr == 'systemd'
@ -26,7 +26,7 @@
- name: Enable and restart metricbeat (upstart)
service:
name: "elasticsearch"
state: restarted
state: "{{ metricbeat_service_state }}"
enabled: yes
when:
- ansible_service_mgr == 'upstart'

View File

@ -253,3 +253,21 @@
- name: Force beat handlers
meta: flush_handlers
- name: set metricbeat service state (upstart)
service:
name: "metricbeat"
state: "{{ metricbeat_service_state }}"
enabled: "{{ metricbeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'upstart'
- metricbeat_service_state in ['started', 'stopped']
- name: set metricbeat service state (systemd)
systemd:
name: "metricbeat"
state: "{{ metricbeat_service_state }}"
enabled: "{{ metricbeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'systemd'
- metricbeat_service_state in ['started', 'stopped']

View File

@ -0,0 +1,16 @@
---
# Copyright 2018, Vexxhost, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
packetbeat_service_state: restarted

View File

@ -17,7 +17,7 @@
systemd:
name: "packetbeat"
enabled: true
state: restarted
state: "{{ packetbeat_service_state }}"
daemon_reload: true
when:
- ansible_service_mgr == 'systemd'
@ -26,7 +26,7 @@
- name: Enable and restart packetbeat (upstart)
service:
name: "elasticsearch"
state: restarted
state: "{{ packetbeat_service_state }}"
enabled: yes
when:
- ansible_service_mgr == 'upstart'

View File

@ -77,3 +77,21 @@
- name: Force beat handlers
meta: flush_handlers
- name: set packetbeat service state (upstart)
service:
name: "packetbeat"
state: "{{ packetbeat_service_state }}"
enabled: "{{ packetbeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'upstart'
- packetbeat_service_state in ['started', 'stopped']
- name: set packetbeat service state (systemd)
systemd:
name: "packetbeat"
state: "{{ packetbeat_service_state }}"
enabled: "{{ packetbeat_service_state in ['running', 'started', 'restarted'] }}"
when:
- ansible_service_mgr == 'systemd'
- packetbeat_service_state in ['started', 'stopped']