-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a5fcb03
Showing
9 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Jiri Tyr 2016 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
logstash | ||
======== | ||
|
||
Ansible role which helps to install and configure Logstash. | ||
|
||
The configuration of the role is done in such way that it should not be | ||
necessary to change the role for any kind of configuration. All can be | ||
done either by changing role parameters or by declaring completely new | ||
configuration as a variable. That makes this role absolutely | ||
universal. See the examples below for more details. | ||
|
||
Please report any issues or send PR. | ||
|
||
|
||
Examples | ||
-------- | ||
|
||
``` | ||
--- | ||
- name: Example of how to install and configure Logstash | ||
hosts: all | ||
vars: | ||
# Change the starting parameters in the sysconfig file | ||
logstash_sysconfig: | ||
# Change the Java heap size | ||
es_heap_size: 300m | ||
logstash_config: | ||
# This is the file name which will be created in /etc/logstash/conf.d | ||
test1: | ||
# Here starts the Logstash configuration for that file | ||
- :input: | ||
- :file: | ||
path: /var/log/httpd/access_log | ||
start_position: beginning | ||
- :filter: | ||
- ':if [path] =~ "access"': | ||
- :mutate: | ||
replace: | ||
type: apache_access | ||
- :grok: | ||
match: | ||
message: "%{COMBINEDAPACHELOG}" | ||
- :date: | ||
match: | ||
- timestamp | ||
- dd/MMM/yyyy:HH:mm:ss Z | ||
- ':else if [path] =~ "error"': | ||
- :mutate: | ||
replace: | ||
type: "apache_error" | ||
- :else: | ||
- :mutate: | ||
replace: | ||
type: "random_logs" | ||
- :output: | ||
- :elasticsearch: | ||
hosts: | ||
- localhost:9200 | ||
- :stdout: | ||
codec: rubydebug | ||
roles: | ||
- logstash | ||
``` | ||
|
||
|
||
Role variables | ||
-------------- | ||
|
||
``` | ||
# Package to be installed (explicit version can be specified here) | ||
logstash_pkg: logstash | ||
# Additional packages to be installed (e.g. Java) | ||
logstash_additional_pkgs: | ||
- java | ||
# Location of the config file | ||
logstash_config_file: /etc/logstash/logstash.yml | ||
# YUM repo URL | ||
logstash_yum_repo_url: https://packages.elastic.co/logstash/2.4/centos | ||
# YUM repo GPG key | ||
logstash_yum_repo_key: https://packages.elastic.co/GPG-KEY-elasticsearch | ||
# Extra EPEL YUM repo params | ||
logstash_yum_repo_params: {} | ||
# Name of the service | ||
logstash_service: logstash | ||
# Path to the logstash config directory | ||
logstash_config_path: /etc/logstash/conf.d | ||
# Default configuration | ||
logstash_config__default: {} | ||
# Custom configuration | ||
logstash_config__custom: {} | ||
# Final configuration | ||
logstash_config: "{{ | ||
logstash_config__default.update( | ||
logstash_config__custom) }}{{ | ||
logstash_config__default }}" | ||
# Path to the sysconfig file | ||
logstash_sysconfig_file: /etc/sysconfig/logstash | ||
logstash_sysconfig: | ||
kill_on_stop_timeout: 0 | ||
# Possible options: | ||
#logstash_sysconfig: | ||
# javacmd: /usr/bin/java | ||
# ls_home: /var/lib/logstash | ||
# ls_opts: "" | ||
# ls_heap_size: 1g | ||
# ls_java_opts: "-Djava.io.tmpdir: $HOME" | ||
# ls_pidfile: /var/run/logstash.pid | ||
# ls_user: logstash | ||
# ls_log_file: /var/log/logstash/logstash.log | ||
# ls_use_gc_logging: "true" | ||
# ls_gc_log_file: /var/log/logstash/gc.log | ||
# ls_conf_dir: /etc/logstash/conf.d | ||
# ls_open_files: 16384 | ||
# ls_nice: 19 | ||
# kill_on_stop_timeout: 0 | ||
``` | ||
|
||
|
||
Dependencies | ||
------------ | ||
|
||
- [`config_encoder_filters`](https://github.com/jtyr/ansible-config_encoder_filters) | ||
- [`elasticsearch`](https://github.com/jtyr/ansible-elasticsearch) (optional) | ||
- [`filebeat`](https://github.com/jtyr/ansible-filebeat) (optional) | ||
|
||
|
||
License | ||
------- | ||
|
||
MIT | ||
|
||
|
||
Author | ||
------ | ||
|
||
Jiri Tyr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
|
||
# Package to be installed (explicit version can be specified here) | ||
logstash_pkg: logstash | ||
|
||
# Additional packages to be installed (e.g. Java) | ||
logstash_additional_pkgs: | ||
- java | ||
|
||
# Location of the config file | ||
logstash_config_file: /etc/logstash/logstash.yml | ||
|
||
# YUM repo URL | ||
logstash_yum_repo_url: https://packages.elastic.co/logstash/2.4/centos | ||
|
||
# YUM repo GPG key | ||
logstash_yum_repo_key: https://packages.elastic.co/GPG-KEY-elasticsearch | ||
|
||
# Extra EPEL YUM repo params | ||
logstash_yum_repo_params: {} | ||
|
||
# Name of the service | ||
logstash_service: logstash | ||
|
||
|
||
# Path to the Logstash config directory | ||
logstash_config_path: /etc/logstash/conf.d | ||
|
||
# Default configuration | ||
logstash_config__default: {} | ||
|
||
# Custom configuration | ||
logstash_config__custom: {} | ||
|
||
# Final configuration | ||
logstash_config: "{{ | ||
logstash_config__default.update( | ||
logstash_config__custom) }}{{ | ||
logstash_config__default }}" | ||
|
||
|
||
# Path to the sysconfig file | ||
logstash_sysconfig_file: /etc/sysconfig/logstash | ||
|
||
logstash_sysconfig: | ||
kill_on_stop_timeout: 0 | ||
# Possible options: | ||
#logstash_sysconfig: | ||
# javacmd: /usr/bin/java | ||
# ls_home: /var/lib/logstash | ||
# ls_opts: "" | ||
# ls_heap_size: 1g | ||
# ls_java_opts: "-Djava.io.tmpdir: $HOME" | ||
# ls_pidfile: /var/run/logstash.pid | ||
# ls_user: logstash | ||
# ls_log_file: /var/log/logstash/logstash.log | ||
# ls_use_gc_logging: "true" | ||
# ls_gc_log_file: /var/log/logstash/gc.log | ||
# ls_conf_dir: /etc/logstash/conf.d | ||
# ls_open_files: 16384 | ||
# ls_nice: 19 | ||
# kill_on_stop_timeout: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
|
||
- name: Restart Logstash service | ||
service: | ||
name: "{{ logstash_service }}" | ||
state: restarted | ||
when: > | ||
logstash_service_started is not defined or | ||
not logstash_service_started.changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
|
||
galaxy_info: | ||
author: Jiri Tyr | ||
description: A role that installs Logstash. | ||
license: MIT | ||
min_ansible_version: 2.1 | ||
platforms: | ||
- name: EL | ||
versions: | ||
- 6 | ||
- 7 | ||
categories: | ||
- system | ||
dependencies: | ||
- config_encoder_filters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
|
||
- name: Test distribution | ||
assert: | ||
that: ansible_os_family == "RedHat" | ||
|
||
- name: Create Logstash YUM repo file | ||
yum_repository: | ||
name: logstash | ||
description: Logstash YUM repo | ||
file: elastic | ||
baseurl: "{{ logstash_yum_repo_url }}" | ||
gpgkey: "{{ logstash_yum_repo_key }}" | ||
params: "{{ logstash_yum_repo_params }}" | ||
tags: | ||
- logstash_pkg | ||
|
||
- name: Install Logstash package | ||
package: | ||
name: "{{ logstash_pkg }}" | ||
notify: | ||
- Restart Logstash service | ||
tags: | ||
- logstash_pkg | ||
|
||
- name: Install additional Logstash packages | ||
package: | ||
name: "{{ item }}" | ||
with_items: "{{ logstash_additional_pkgs }}" | ||
notify: | ||
- Restart Logstash service | ||
tags: | ||
- logstash_pkg | ||
|
||
- name: Configure Logstash | ||
template: | ||
src: logstash.conf.j2 | ||
dest: "{{ logstash_config_path }}/{{ item.key }}.conf" | ||
with_dict: "{{ logstash_config }}" | ||
notify: | ||
- Restart Logstash service | ||
tags: | ||
- logstash_config | ||
|
||
- name: Configure Logstash sysconfig | ||
template: | ||
src: logstash.sysconfig.j2 | ||
dest: "{{ logstash_sysconfig_file }}" | ||
notify: | ||
- Restart Logstash service | ||
tags: | ||
- logstash_config | ||
|
||
- name: Enable Logstash service | ||
service: | ||
name: "{{ logstash_service }}" | ||
enabled: yes | ||
tags: | ||
- logstash_service | ||
|
||
- name: Start Logstash service | ||
service: | ||
name: "{{ logstash_service }}" | ||
state: started | ||
register: logstash_service_started | ||
tags: | ||
- logstash_service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{ ansible_managed | comment }} | ||
|
||
{{ item.value | encode_logstash }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{ ansible_managed | comment }} | ||
|
||
{{ logstash_sysconfig | encode_ini(ucase_prop=true) }} |