Import the old rsyslog role.
This commit is contained in:
parent
b23413d6d3
commit
9e5937ac13
56
README.md
56
README.md
|
@ -1,38 +1,56 @@
|
|||
Role Name
|
||||
=========
|
||||
|
||||
A brief description of the role goes here.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
|
||||
A role that configures rsyslog
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
|
||||
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
|
||||
The most important variables are listed below:
|
||||
|
||||
``` yaml
|
||||
rsyslog_enable_remote_socket: False
|
||||
rsyslog_enable_remote_udp: 'enabled'
|
||||
rsyslog_enable_remote_tcp: 'disabled'
|
||||
|
||||
rsyslog_remote_path: /var/log/remote
|
||||
rsyslog_tls_status: 'disabled'
|
||||
rsyslog_tls_deb_pkgs:
|
||||
- 'rsyslog-gnutls'
|
||||
|
||||
rsyslog_tls_rh_pkgs:
|
||||
- 'rsyslog-gnutls'
|
||||
|
||||
rsyslog_udp_port: 514
|
||||
rsyslog_tcp_port: 514
|
||||
|
||||
rsyslog_send_to_remote: False
|
||||
|
||||
rsyslog_firewalld_services:
|
||||
- { service: 'syslog', state: '{{ rsyslog_enable_remote_udp }}', zone: '{{ firewalld_default_zone }}' }
|
||||
- { service: 'syslog-tls', state: '{{ rsyslog_tls_status }}', zone: '{{ firewalld_default_zone }}' }
|
||||
|
||||
rsyslog_firewalld_ports:
|
||||
- { port: '{{ rsyslog_tcp_port }}', protocol: 'tcp', state: '{{ rsyslog_enable_remote_tcp }}', zone: '{{ firewalld_default_zone }}' }
|
||||
|
||||
rsyslog_send_to_elasticsearch: False
|
||||
|
||||
rsyslog_use_inotify: True
|
||||
# Not used when inotify is enabled
|
||||
rsyslog_file_polling_interval: 10
|
||||
```
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
|
||||
|
||||
Example Playbook
|
||||
----------------
|
||||
|
||||
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
|
||||
|
||||
- hosts: servers
|
||||
roles:
|
||||
- { role: username.rolename, x: 42 }
|
||||
None
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
BSD
|
||||
EUPL-1.2
|
||||
|
||||
Author Information
|
||||
------------------
|
||||
|
||||
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
|
||||
Andrea Dell'Amico, <andrea.dellamico@isti.cnr.it>
|
||||
|
|
|
@ -1,2 +1,65 @@
|
|||
---
|
||||
# defaults file for ansible-role-template
|
||||
rsyslog_enable_remote_socket: False
|
||||
rsyslog_enable_send_to_remote: False
|
||||
rsyslog_enable_remote_udp: 'enabled'
|
||||
rsyslog_udp_port: 514
|
||||
rsyslog_enable_remote_tcp: 'disabled'
|
||||
rsyslog_tcp_port: 514
|
||||
|
||||
rsyslog_remote_path: /var/log/remote
|
||||
# RELP, actually. Plain TLS is unreliable
|
||||
rsyslog_tls_status: 'disabled'
|
||||
rsyslog_tls_deb_pkgs:
|
||||
- 'rsyslog-gnutls'
|
||||
|
||||
rsyslog_tls_rh_pkgs:
|
||||
- 'rsyslog-gnutls'
|
||||
|
||||
rsyslog_relp_port: '20514'
|
||||
rsyslog_tls_certs_dir: /etc/pki/rsyslog
|
||||
rsyslog_tls_ca: "{{ rsyslog_tls_certs_dir }}/ca.pem"
|
||||
rsyslog_tls_cert: "{{ rsyslog_tls_certs_dir }}/cert.pem"
|
||||
rsyslog_tls_key: "{{ rsyslog_tls_certs_dir }}/cert.key"
|
||||
|
||||
rsyslog_remote_collector: '127.0.0.1'
|
||||
|
||||
rsyslog_firewalld_services:
|
||||
- { service: 'syslog', state: '{{ rsyslog_enable_remote_udp }}', zone: '{{ firewalld_default_zone }}' }
|
||||
# - { service: 'syslog-tls', state: '{{ rsyslog_tls_status }}', zone: '{{ firewalld_default_zone }}' }
|
||||
|
||||
rsyslog_firewalld_ports:
|
||||
- { port: '{{ rsyslog_tcp_port }}', protocol: 'tcp', state: '{{ rsyslog_enable_remote_tcp }}', zone: '{{ firewalld_default_zone }}' }
|
||||
- { port: '{{ rsyslog_relp_port }}', protocol: 'tcp', state: '{{ rsyslog_tls_status }}', zone: '{{ firewalld_default_zone }}' }
|
||||
|
||||
rsyslog_send_to_elasticsearch: False
|
||||
|
||||
rsyslog_use_inotify: True
|
||||
# Not used when inotify is enabled
|
||||
rsyslog_file_polling_interval: 10
|
||||
|
||||
# We use logstash if the elastisearch module is not enabled
|
||||
#rsys_logstash_collector_host: logstash.t.hadoop.research-infrastructures.eu
|
||||
rsys_logstash_collector_host: logstash
|
||||
rsys_logstash_collector_port: 5544
|
||||
|
||||
# IMPORTANT: the log_state_file names must be unique
|
||||
#rsys_logfiles:
|
||||
# - { logfile: '/var/log/tomcat7/catalina.log', log_tag: 'solr-state', log_state_file: 'solr-state'}
|
||||
# - { logfile: '/var/log/tomcat7/localhost_access.log', log_tag: 'solr-access', log_state_file: 'solr-access'}
|
||||
|
||||
rsyslog_use_queues: False
|
||||
rsyslog_main_queue_size: 1000000
|
||||
rsyslog_main_queue_debatchsize: 256
|
||||
rsyslog_main_queue_workerthreads: 2
|
||||
rsyslog_action_queue_debatchsize: 1024
|
||||
rsyslog_action_queue_size: 100000
|
||||
rsyslog_action_queue_workerthreads: 5
|
||||
# -1 means retry indefinitely if ES is unreachable
|
||||
rsyslog_action_resumeretrycount: -1
|
||||
|
||||
# The elasticsearch module bypasses logstash and talks directly to elasticsearch
|
||||
rsyslog_use_elasticsearch_module: True
|
||||
#rsys_elasticsearch_collector_host: logstash.t.hadoop.research-infrastructures.eu
|
||||
rsys_elasticsearch_collector_host: logstash
|
||||
rsys_elasticsearch_collector_port: 9200
|
||||
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
---
|
||||
# handlers file for ansible-role-template
|
||||
- name: Restart rsyslog
|
||||
service: name=rsyslog state=restarted
|
||||
|
||||
|
||||
|
|
|
@ -1,61 +1,26 @@
|
|||
galaxy_info:
|
||||
author: your name
|
||||
description: your description
|
||||
author: Andrea Dell'Amico
|
||||
description: Systems Architect
|
||||
company: ISTI-CNR
|
||||
|
||||
# If the issue tracker for your role is not on github, uncomment the
|
||||
# next line and provide a value
|
||||
issue_tracker_url: https://redmine-s2i2s.isti.cnr.it/projects/provisioning
|
||||
|
||||
# Some suggested licenses:
|
||||
# - BSD (default)
|
||||
# - MIT
|
||||
# - GPLv2
|
||||
# - GPLv3
|
||||
# - Apache
|
||||
# - CC-BY
|
||||
license: EUPL 1.2+
|
||||
|
||||
min_ansible_version: 2.8
|
||||
|
||||
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
||||
# min_ansible_container_version:
|
||||
|
||||
# Optionally specify the branch Galaxy will use when accessing the GitHub
|
||||
# repo for this role. During role install, if no tags are available,
|
||||
# Galaxy will use this branch. During import Galaxy will access files on
|
||||
# this branch. If Travis integration is configured, only notifications for this
|
||||
# branch will be accepted. Otherwise, in all cases, the repo's default branch
|
||||
# (usually master) will be used.
|
||||
#github_branch:
|
||||
|
||||
#
|
||||
# Provide a list of supported platforms, and for each platform a list of versions.
|
||||
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
|
||||
# To view available platforms and versions (or releases), visit:
|
||||
# https://galaxy.ansible.com/api/v1/platforms/
|
||||
#
|
||||
# platforms:
|
||||
# - name: Fedora
|
||||
# versions:
|
||||
# - all
|
||||
# - 25
|
||||
# - name: SomePlatform
|
||||
# versions:
|
||||
# - all
|
||||
# - 1.0
|
||||
# - 7
|
||||
# - 99.99
|
||||
platforms:
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- bionic
|
||||
- name: EL
|
||||
versions:
|
||||
- 7
|
||||
|
||||
galaxy_tags: []
|
||||
# List tags for your role here, one per line. A tag is a keyword that describes
|
||||
# and categorizes the role. Users find roles by searching for tags. Be sure to
|
||||
# remove the '[]' above, if you add tags to this list.
|
||||
#
|
||||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
||||
# Maximum 20 tags per role.
|
||||
galaxy_tags:
|
||||
- users
|
||||
|
||||
dependencies: []
|
||||
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||
# if you add dependencies to this list.
|
||||
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
---
|
||||
# tasks file for ansible-role-template
|
||||
- import_tasks: rsyslog-server.yml
|
||||
- import_tasks: rsyslog-logstash.yml
|
||||
when: rsyslog_send_to_elasticsearch
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
- name: Add the syslog user to the adm group so it can read all the log files
|
||||
user: name=syslog groups=adm
|
||||
tags: [ 'rsyslog', 'logstash' ]
|
||||
|
||||
- name: Upgrade rsyslog and install the elasticsearch module
|
||||
apt: pkg={{ item }} state={{ rsyslog_pkg_status }} update_cache=yes cache_valid_time=1800
|
||||
with_items:
|
||||
- rsyslog
|
||||
- rsyslog-elasticsearch
|
||||
tags: [ 'rsyslog', 'logstash' ]
|
||||
|
||||
- name: Add a rsyslog configuration to send logfiles data to a logstash collector or directly to elasticsearch
|
||||
template: src=rsyslog-logstash.conf.j2 dest=/etc/rsyslog.d/90-rsyslog-logstash.conf owner=root group=root mode=0444
|
||||
when: rsyslog_send_to_elasticsearch | bool
|
||||
notify: Restart rsyslog
|
||||
tags: [ 'rsyslog', 'logstash' ]
|
||||
|
||||
- name: Remove the rsyslog configuration to send logfiles data to a logstash collector or directly to elasticsearch
|
||||
file: dest=/etc/rsyslog.d/90-rsyslog-logstash.conf state=absent
|
||||
when: not rsyslog_send_to_elasticsearch | bool
|
||||
notify: Restart rsyslog
|
||||
tags: [ 'rsyslog', 'logstash' ]
|
||||
|
|
@ -0,0 +1,101 @@
|
|||
---
|
||||
- name: Manage the rsyslog packages and service
|
||||
block:
|
||||
- name: Ensure that the rsyslog package is installed. deb/ubuntu
|
||||
apt: pkg=rsyslog state=present cache_valid_time=1800
|
||||
when: ansible_distribution_file_variety == "Debian"
|
||||
|
||||
- name: Ensure that the rsyslog package is installed. centos/rhel
|
||||
yum: pkg=rsyslog state=present
|
||||
when: ansible_distribution_file_variety == "RedHat"
|
||||
|
||||
- name: Create the target logs rsyslog directory
|
||||
file: dest={{ rsyslog_remote_path }} state=directory owner=syslog group=adm
|
||||
|
||||
- name: Ensure that rsyslog is running and enabled
|
||||
service: name=rsyslog state=started enabled=yes
|
||||
|
||||
when: rsyslog_enable_remote_socket or rsyslog_enable_send_to_remote
|
||||
tags: [ 'syslog', 'rsyslog', 'remote_syslog' ]
|
||||
|
||||
- name: Install the rsyslog TLS package on deb/ubuntu
|
||||
block:
|
||||
- name: Install the rsyslog TLS support
|
||||
apt: pkg={{ rsyslog_tls_deb_pkgs }} state=present cache_valid_time=1800
|
||||
notify: Restart rsyslog
|
||||
|
||||
when:
|
||||
- rsyslog_enable_remote_socket or rsyslog_enable_send_to_remote
|
||||
- rsyslog_tls_status == 'enabled'
|
||||
- ansible_distribution_file_variety == "Debian"
|
||||
tags: [ 'syslog', 'rsyslog', 'remote_syslog' ]
|
||||
|
||||
- name: Install the rsyslog TLS package on RHEL/CentOS
|
||||
block:
|
||||
- name: Install the rsyslog TLS support
|
||||
yum: pkg={{ rsyslog_tls_rh_pkgs }} state=present
|
||||
notify: Restart rsyslog
|
||||
|
||||
when:
|
||||
- rsyslog_enable_remote_socket or rsyslog_enable_send_to_remote
|
||||
- rsyslog_tls_status == 'enabled'
|
||||
- ansible_distribution_file_variety == "RedHat"
|
||||
tags: [ 'syslog', 'rsyslog', 'remote_syslog' ]
|
||||
|
||||
- name: Install the rsyslog TLS package on RHEL/CentOS
|
||||
block:
|
||||
- name: Install the rsyslog TLS support
|
||||
yum: pkg={{ rsyslog_tls_rh_pkgs }} state=present
|
||||
notify: Restart rsyslog
|
||||
|
||||
when:
|
||||
- rsyslog_enable_remote_socket or rsyslog_enable_send_to_remote
|
||||
- rsyslog_tls_status == 'enabled'
|
||||
- ansible_distribution_file_variety == "RedHat"
|
||||
tags: [ 'syslog', 'rsyslog', 'remote_syslog' ]
|
||||
|
||||
- name: Configure rsyslog so that it accepts logs from remote services
|
||||
block:
|
||||
- name: Install the rsyslog configuration that enables the remote socket
|
||||
template: src=rsyslog-remote-socket.conf.j2 dest=/etc/rsyslog.d/10-rsyslog-remote-socket.conf
|
||||
notify: Restart rsyslog
|
||||
|
||||
when: rsyslog_enable_remote_socket
|
||||
tags: [ 'syslog', 'rsyslog', 'remote_syslog', 'rsyslog_conf' ]
|
||||
|
||||
- name: Configure rsyslog to send logs to a remote collector
|
||||
block:
|
||||
- name: Install the rsyslog client configuration
|
||||
template: src=rsyslog-send-to-remote.conf.j2 dest=/etc/rsyslog.d/10-rsyslog-send-to-remote.conf
|
||||
notify: Restart rsyslog
|
||||
|
||||
when: rsyslog_enable_send_to_remote
|
||||
tags: [ 'syslog', 'rsyslog', 'remote_syslog', 'rsyslog_conf' ]
|
||||
|
||||
|
||||
- name: Configure SELinux and firewalld on RHEL/CentOS
|
||||
block:
|
||||
- name: SELinux udp port
|
||||
seport: ignore_selinux_state=yes ports={{ rsyslog_udp_port }} proto=udp setype=syslogd_port_t state=present
|
||||
when: rsyslog_enable_remote_udp == 'enabled'
|
||||
|
||||
- name: SELinux tcp port
|
||||
seport: ignore_selinux_state=yes ports={{ rsyslog_udp_port }} proto=tcp setype=syslogd_port_t state=present
|
||||
when: rsyslog_enable_remote_tcp == 'enabled'
|
||||
|
||||
- name: SELinux RELP port
|
||||
seport: ignore_selinux_state=yes ports={{ rsyslog_relp_port }} proto=tcp setype=syslogd_port_t state=present
|
||||
when: rsyslog_tls_status == 'enabled'
|
||||
|
||||
- name: rsyslog firewalld services
|
||||
firewalld: service={{ item.service }} zone={{ item.zone }} permanent={{ item.permanent | default(True) }} state={{ item.state }} immediate=True
|
||||
with_items: '{{ rsyslog_firewalld_services }}'
|
||||
|
||||
- name: rsyslog firewalld ports
|
||||
firewalld: port={{ item.port }}/{{ item.protocol }} zone={{ item.zone }} permanent={{ item.permanent | default(False) }} state={{ item.state }} immediate=True
|
||||
with_items: '{{ rsyslog_firewalld_ports }}'
|
||||
|
||||
when:
|
||||
- rsyslog_enable_remote_socket
|
||||
- ansible_distribution_file_variety == "RedHat"
|
||||
tags: [ 'syslog', 'rsyslog', 'remote_syslog', 'selinux', 'firewalld' ]
|
|
@ -0,0 +1,13 @@
|
|||
$ModLoad imfile
|
||||
|
||||
{% for log in rsys_logfiles %}
|
||||
$InputFileName {{ log.logfile }}
|
||||
$InputFileTag {{ log.log_tag }}
|
||||
$InputFileStateFile {{ log.log_state_file }}
|
||||
$InputRunFileMonitor
|
||||
|
||||
{% endfor %}
|
||||
|
||||
# Send all to the logstash server
|
||||
*.* @@{{ rsys_logstash_collector_host }}:{{ rsys_logstash_collector_port }}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
{% if rsys_logfiles is defined %}
|
||||
{% if rsyslog_use_inotify %}
|
||||
module(load="imfile" mode="inotify" )
|
||||
{% else %}
|
||||
module(load="imfile" mode="polling" PollingInterval="10" )
|
||||
{% endif %}
|
||||
{% for log in rsys_logfiles %}
|
||||
input(
|
||||
Type="imfile"
|
||||
File="{{ log.logfile }}"
|
||||
Tag="{{ log.log_tag }}"
|
||||
)
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if rsyslog_use_elasticsearch_module %}
|
||||
module(load="omelasticsearch")
|
||||
|
||||
{% if rsyslog_use_queues %}
|
||||
main_queue(
|
||||
queue.size="{{ rsyslog_main_queue_size }}" # capacity of the main queue
|
||||
queue.debatchsize="{{ rsyslog_main_queue_debatchsize }}" # process messages in batches of 1000 and move them to the action queues
|
||||
queue.workerthreads="{{ rsyslog_main_queue_workerthreads }}" # threads for the main queue
|
||||
)
|
||||
{% endif %}
|
||||
|
||||
template(name="logstash-index"
|
||||
type="list") {
|
||||
constant(value="logstash-")
|
||||
property(name="timereported" dateFormat="rfc3339" position.from="1" position.to="4")
|
||||
constant(value=".")
|
||||
property(name="timereported" dateFormat="rfc3339" position.from="6" position.to="7")
|
||||
constant(value=".")
|
||||
property(name="timereported" dateFormat="rfc3339" position.from="9" position.to="10")
|
||||
}
|
||||
|
||||
# this is for formatting our syslog in JSON with @timestamp
|
||||
template(name="plain-syslog"
|
||||
type="list") {
|
||||
constant(value="{")
|
||||
constant(value="\"@timestamp\":\"") property(name="timereported" dateFormat="rfc3339")
|
||||
constant(value="\"received_at\":\"") property(name="timereported" dateFormat="rfc3339")
|
||||
constant(value="\",\"host\":\"") property(name="hostname")
|
||||
constant(value="\",\"received_from\":\"") property(name="hostname")
|
||||
constant(value="\",\"severity\":\"") property(name="syslogseverity-text")
|
||||
constant(value="\",\"facility\":\"") property(name="syslogfacility-text")
|
||||
constant(value="\",\"tag\":\"") property(name="syslogtag" format="json")
|
||||
constant(value="\",\"message\":\"") property(name="msg" format="json")
|
||||
constant(value="\"}")
|
||||
}
|
||||
# this is where we actually send the logs to Elasticsearch ({{ rsys_elasticsearch_collector_host }}:{{ rsys_elasticsearch_collector_port }})
|
||||
*.* action(type="omelasticsearch"
|
||||
template="plain-syslog"
|
||||
searchIndex="logstash-index"
|
||||
dynSearchIndex="on"
|
||||
{% if rsyslog_use_queues %}
|
||||
bulkmode="on"
|
||||
queue.dequeuebatchsize="{{ rsyslog_action_queue_debatchsize }}" # ES bulk size
|
||||
queue.size="{{ rsyslog_action_queue_size }}" # capacity of the action queue
|
||||
queue.workerthreads="{{ rsyslog_action_queue_workerthreads }}" # workers for the action
|
||||
action.resumeretrycount="{{ rsyslog_action_resumeretrycount }}"
|
||||
{% endif %}
|
||||
server="{{ rsys_elasticsearch_collector_host }}"
|
||||
serverport="{{ rsys_elasticsearch_collector_port }}"
|
||||
)
|
||||
{% else %}
|
||||
# Send all to the logstash server
|
||||
*.* @@{{ rsys_logstash_collector_host }}:{{ rsys_logstash_collector_port }}
|
||||
{% endif %}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
{% if rsyslog_enable_remote_socket %}
|
||||
#
|
||||
# The order counts
|
||||
#
|
||||
{% if rsyslog_tls_status != 'disabled ' %}
|
||||
module(load="imuxsock")
|
||||
module(load="imrelp" ruleset="relp")
|
||||
input(type="imrelp" port="{{ rsyslog_relp_port }}"
|
||||
tls="on"
|
||||
tls.caCert="{{ rsyslog_tls_ca }}"
|
||||
tls.myCert="{{ rsyslog_tls_cert }}"
|
||||
tls.myPrivKey="{{ rsyslog_tls_key }}"
|
||||
#tls.authMode="name"
|
||||
#tls.permittedpeer=["client1","client2","client3"] )
|
||||
template (name="remote" type="string" string="{{ rsyslog_remote_path }}/%HOSTNAME%/%HOSTNAME%-syslog.log")
|
||||
ruleset (name="relp") { action(type="omfile" Template="remote") }
|
||||
{% endif %}
|
||||
|
||||
{% if rsyslog_enable_remote_udp == 'enabled' %}
|
||||
# Provides UDP syslog reception
|
||||
module(load="imudp")
|
||||
input(type="imudp" port="{{ rsyslog_udp_port }}")
|
||||
{% endif %}
|
||||
|
||||
{% if rsyslog_enable_remote_tcp == 'enabled' %}
|
||||
module(load="imtcp")
|
||||
input(type="imtcp" port="{{ rsyslog_tcp_port }}")
|
||||
{% endif %}
|
||||
module(load="impstats")
|
||||
#
|
||||
{% endif %}
|
|
@ -0,0 +1,9 @@
|
|||
{% if rsyslog_enable_send_to_remote %}
|
||||
#
|
||||
# The order counts
|
||||
# We use RELP
|
||||
module(load="imuxsock")
|
||||
module(load="omrelp")
|
||||
action(type="omrelp" target="{{ rsyslog_remote_collector }}" port="{{ rsyslog_relp_port }}" tls="on" tls.caCert="{{ rsyslog_tls_ca }}" )
|
||||
#
|
||||
{% endif %}
|
Loading…
Reference in New Issue