From 7430f6c8d5427e28a1238cdf3ecf4c0641f77d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Steinm=C3=BCller?= Date: Wed, 19 Sep 2018 20:23:07 +0000 Subject: [PATCH] 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 --- .../roles/elastic_auditbeat/defaults/main.yml | 16 ++++++++++++++++ .../roles/elastic_auditbeat/handlers/main.yml | 4 ++-- .../roles/elastic_auditbeat/tasks/main.yml | 18 ++++++++++++++++++ .../roles/elastic_filebeat/defaults/main.yml | 16 ++++++++++++++++ .../roles/elastic_filebeat/handlers/main.yml | 4 ++-- .../roles/elastic_filebeat/tasks/main.yml | 18 ++++++++++++++++++ .../roles/elastic_heartbeat/defaults/main.yml | 16 ++++++++++++++++ .../roles/elastic_heartbeat/handlers/main.yml | 4 ++-- .../roles/elastic_heartbeat/tasks/main.yml | 18 ++++++++++++++++++ .../elastic_journalbeat/defaults/main.yml | 16 ++++++++++++++++ .../elastic_journalbeat/handlers/main.yml | 2 +- .../roles/elastic_journalbeat/tasks/main.yml | 18 ++++++++++++++++++ .../roles/elastic_metricbeat/defaults/main.yml | 2 ++ .../roles/elastic_metricbeat/handlers/main.yml | 4 ++-- .../roles/elastic_metricbeat/tasks/main.yml | 18 ++++++++++++++++++ .../roles/elastic_packetbeat/defaults/main.yml | 16 ++++++++++++++++ .../roles/elastic_packetbeat/handlers/main.yml | 4 ++-- .../roles/elastic_packetbeat/tasks/main.yml | 18 ++++++++++++++++++ 18 files changed, 201 insertions(+), 11 deletions(-) create mode 100644 elk_metrics_6x/roles/elastic_auditbeat/defaults/main.yml create mode 100644 elk_metrics_6x/roles/elastic_filebeat/defaults/main.yml create mode 100644 elk_metrics_6x/roles/elastic_heartbeat/defaults/main.yml create mode 100644 elk_metrics_6x/roles/elastic_journalbeat/defaults/main.yml create mode 100644 elk_metrics_6x/roles/elastic_packetbeat/defaults/main.yml diff --git a/elk_metrics_6x/roles/elastic_auditbeat/defaults/main.yml b/elk_metrics_6x/roles/elastic_auditbeat/defaults/main.yml new file mode 100644 index 00000000..25ab8922 --- /dev/null +++ b/elk_metrics_6x/roles/elastic_auditbeat/defaults/main.yml @@ -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 diff --git a/elk_metrics_6x/roles/elastic_auditbeat/handlers/main.yml b/elk_metrics_6x/roles/elastic_auditbeat/handlers/main.yml index ccc20d33..bf751755 100644 --- a/elk_metrics_6x/roles/elastic_auditbeat/handlers/main.yml +++ b/elk_metrics_6x/roles/elastic_auditbeat/handlers/main.yml @@ -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' diff --git a/elk_metrics_6x/roles/elastic_auditbeat/tasks/main.yml b/elk_metrics_6x/roles/elastic_auditbeat/tasks/main.yml index e131e1e9..51d7f4cf 100644 --- a/elk_metrics_6x/roles/elastic_auditbeat/tasks/main.yml +++ b/elk_metrics_6x/roles/elastic_auditbeat/tasks/main.yml @@ -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'] diff --git a/elk_metrics_6x/roles/elastic_filebeat/defaults/main.yml b/elk_metrics_6x/roles/elastic_filebeat/defaults/main.yml new file mode 100644 index 00000000..ade4e066 --- /dev/null +++ b/elk_metrics_6x/roles/elastic_filebeat/defaults/main.yml @@ -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 diff --git a/elk_metrics_6x/roles/elastic_filebeat/handlers/main.yml b/elk_metrics_6x/roles/elastic_filebeat/handlers/main.yml index f14aa2c1..76c5a128 100644 --- a/elk_metrics_6x/roles/elastic_filebeat/handlers/main.yml +++ b/elk_metrics_6x/roles/elastic_filebeat/handlers/main.yml @@ -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' diff --git a/elk_metrics_6x/roles/elastic_filebeat/tasks/main.yml b/elk_metrics_6x/roles/elastic_filebeat/tasks/main.yml index 001df996..e6caf1ce 100644 --- a/elk_metrics_6x/roles/elastic_filebeat/tasks/main.yml +++ b/elk_metrics_6x/roles/elastic_filebeat/tasks/main.yml @@ -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'] diff --git a/elk_metrics_6x/roles/elastic_heartbeat/defaults/main.yml b/elk_metrics_6x/roles/elastic_heartbeat/defaults/main.yml new file mode 100644 index 00000000..d6bbf645 --- /dev/null +++ b/elk_metrics_6x/roles/elastic_heartbeat/defaults/main.yml @@ -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 diff --git a/elk_metrics_6x/roles/elastic_heartbeat/handlers/main.yml b/elk_metrics_6x/roles/elastic_heartbeat/handlers/main.yml index 62e57961..6eee1cc2 100644 --- a/elk_metrics_6x/roles/elastic_heartbeat/handlers/main.yml +++ b/elk_metrics_6x/roles/elastic_heartbeat/handlers/main.yml @@ -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' diff --git a/elk_metrics_6x/roles/elastic_heartbeat/tasks/main.yml b/elk_metrics_6x/roles/elastic_heartbeat/tasks/main.yml index bab6835a..7dfdebc6 100644 --- a/elk_metrics_6x/roles/elastic_heartbeat/tasks/main.yml +++ b/elk_metrics_6x/roles/elastic_heartbeat/tasks/main.yml @@ -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'] diff --git a/elk_metrics_6x/roles/elastic_journalbeat/defaults/main.yml b/elk_metrics_6x/roles/elastic_journalbeat/defaults/main.yml new file mode 100644 index 00000000..6dbf010e --- /dev/null +++ b/elk_metrics_6x/roles/elastic_journalbeat/defaults/main.yml @@ -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 diff --git a/elk_metrics_6x/roles/elastic_journalbeat/handlers/main.yml b/elk_metrics_6x/roles/elastic_journalbeat/handlers/main.yml index 938ba819..48f3802b 100644 --- a/elk_metrics_6x/roles/elastic_journalbeat/handlers/main.yml +++ b/elk_metrics_6x/roles/elastic_journalbeat/handlers/main.yml @@ -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' diff --git a/elk_metrics_6x/roles/elastic_journalbeat/tasks/main.yml b/elk_metrics_6x/roles/elastic_journalbeat/tasks/main.yml index c5a0e2dd..b19ebbc6 100644 --- a/elk_metrics_6x/roles/elastic_journalbeat/tasks/main.yml +++ b/elk_metrics_6x/roles/elastic_journalbeat/tasks/main.yml @@ -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'] diff --git a/elk_metrics_6x/roles/elastic_metricbeat/defaults/main.yml b/elk_metrics_6x/roles/elastic_metricbeat/defaults/main.yml index 1a1fd5c4..79fff8e8 100644 --- a/elk_metrics_6x/roles/elastic_metricbeat/defaults/main.yml +++ b/elk_metrics_6x/roles/elastic_metricbeat/defaults/main.yml @@ -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 diff --git a/elk_metrics_6x/roles/elastic_metricbeat/handlers/main.yml b/elk_metrics_6x/roles/elastic_metricbeat/handlers/main.yml index e1cbbd8d..6c28c6d6 100644 --- a/elk_metrics_6x/roles/elastic_metricbeat/handlers/main.yml +++ b/elk_metrics_6x/roles/elastic_metricbeat/handlers/main.yml @@ -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' diff --git a/elk_metrics_6x/roles/elastic_metricbeat/tasks/main.yml b/elk_metrics_6x/roles/elastic_metricbeat/tasks/main.yml index f0e6d267..91c1626c 100644 --- a/elk_metrics_6x/roles/elastic_metricbeat/tasks/main.yml +++ b/elk_metrics_6x/roles/elastic_metricbeat/tasks/main.yml @@ -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'] diff --git a/elk_metrics_6x/roles/elastic_packetbeat/defaults/main.yml b/elk_metrics_6x/roles/elastic_packetbeat/defaults/main.yml new file mode 100644 index 00000000..85f01f0d --- /dev/null +++ b/elk_metrics_6x/roles/elastic_packetbeat/defaults/main.yml @@ -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 diff --git a/elk_metrics_6x/roles/elastic_packetbeat/handlers/main.yml b/elk_metrics_6x/roles/elastic_packetbeat/handlers/main.yml index fa1a0211..512bad0c 100644 --- a/elk_metrics_6x/roles/elastic_packetbeat/handlers/main.yml +++ b/elk_metrics_6x/roles/elastic_packetbeat/handlers/main.yml @@ -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' diff --git a/elk_metrics_6x/roles/elastic_packetbeat/tasks/main.yml b/elk_metrics_6x/roles/elastic_packetbeat/tasks/main.yml index 7cb058e9..6eb5f12a 100644 --- a/elk_metrics_6x/roles/elastic_packetbeat/tasks/main.yml +++ b/elk_metrics_6x/roles/elastic_packetbeat/tasks/main.yml @@ -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']