Commit 560e8607 authored by hadret's avatar hadret

feat: initial commit.

parents
MIT License
Copyright (c) 2019 Filip Chabik
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.
# Ansible Role: Rsyslog
This is a internal role for deploying `rsyslog` configuration for both server
and client. Server need to be part of a `syslog-servers` host group in order for
it to receive proper configuration. All of the other servers are treated as
clients. Some of them **can** have tailored configuration, it is however handled
by the template of the client configuration file.
## Requirements
None.
## Role variables
Here are available variables with their default values (as in
[defaults/main.yml](defaults/main.yml)):
## Dependencies
None.
## Example playbook
```
hosts: all
roles:
- hadret.rsyslog
```
## License
MIT.
## Authors
This role was somewhat assembled in 2019 by [Filip Chabik](https://chabik.com).
---
rsyslog_action_file_default_template: "RSYSLOG_TraditionalFileFormat"
rsyslog_repeated_msg_reduction: 'off'
rsyslog_server: 127.0.0.1
rsyslog_port: 514
rsyslog_pkgs:
- rsyslog-elasticsearch
- rsyslog-mmnormalize
rsyslog_service_state: started
rsyslog_service_enabled: true
rsyslog_conf_template: "rsyslog.conf.j2"
rsyslog_rules_template: "rules.conf.j2"
rsyslog_rules: []
# - rule_name: "remote-relp" # name of the rule
# priority: 99 # order of the rules may be important
# ruleset: |
# module(load="omrelp")
# action(type="omrelp" target="{{ rsyslog_server }}" port="{{ rsyslog_port }}")
# # Properties that are only added if defined:
# filename: "99-remote-relp.conf" # default: "$priority-$rule_name.conf"
# template: "" # override the `rsyslog_template` per ruleset
# state: "absent" # remove the ruleset configuration
/var/log/remote/*/*.log
{
rotate 7
daily
missingok
notifempty
compress
compresscmd /usr/bin/pixz
uncompresscmd /usr/bin/pixz
compressext .xz
delaycompress
postrotate
invoke-rc.d rsyslog rotate >/dev/null
endscript
}
/var/log/remote/*/platform/*.log
{
rotate 13
daily
missingok
notifempty
compress
compresscmd /usr/bin/pixz
uncompresscmd /usr/bin/pixz
compressext .xz
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog rotate >/dev/null
endscript
}
---
- name: restart rsyslog
service: name=rsyslog state=restarted
---
- name: include OS-specific variables
include_vars: "{{ ansible_os_family }}.yml"
- name: define rsyslog_user
set_fact:
rsyslog_user: "{{ __rsyslog_user }}"
when: rsyslog_user is not defined
- name: define rsyslog_group
set_fact:
rsyslog_user: "{{ __rsyslog_group }}"
when: rsyslog_group is not defined
- name: define rsyslog_file_create_mode
set_fact:
rsyslog_file_create_mode: "{{ __rsyslog_file_create_mode }}"
when: rsyslog_file_create_mode is not defined
- name: define rsyslog_dir_create_mode
set_fact:
rsyslog_dir_create_mode: "{{ __rsyslog_dir_create_mode }}"
when: rsyslog_dir_create_mode is not defined
- name: define rsyslog_umask
set_fact:
rsyslog_umask: "{{ __rsyslog_umask }}"
when: rsyslog_umask is not defined
- include_tasks: setup-Ubuntu.yml
when: ansible_distribution == 'Ubuntu'
# rules configuration
# - import_tasks: rules.yml
# rsyslog setup
- name: copy main rsyslog config file
template:
src: "{{ rsyslog_conf_template }}"
dest: "{{ rsyslog_conf_file_path }}"
owner: root
group: "{{ root_group }}"
mode: 0644
validate: /usr/sbin/rsyslogd -N1 -f %s
notify:
- restart rsyslog
- name: ensure rsyslog is up and enabled on boot
service:
name: rsyslog
state: "{{ rsyslog_service_state }}"
enabled: "{{ rsyslog_service_enabled }}"
---
- name: ensure rsyslog_conf_path exists
file:
path: "{{ rsyslog_conf_path }}"
state: directory
- name: add managed rsyslog rules
template:
src: "{{ item.template|default(rsyslog_template) }}"
dest: "{{ rsyslog_conf_path }}/{{ item.filename|default(item.priority ~ '-' ~ item.rule_name ~ '.conf') }}"
force: true
owner: root
group: "{{ root_group }}"
mode: 0644
when: item.state|default('present') != 'absent'
loop: "{{ rsyslog_rules }}"
notify: restart rsyslog
tags:
- skip_ansible_lint
- name: remove managed rsyslog rules
file:
path: "{{ rsyslog_conf_path }}/{{ item.filename|default(item.priority ~ '-' ~ item.rule_name ~ '.conf') }}"
state: absent
when: item.state|default('present') == 'absent'
loop: "{{ rsyslog_rules }}"
notify: restart rsyslog
tags:
- skip_ansible_lint
---
- name: add PPA for rsyslog
apt_repository:
repo: 'ppa:adiscon/{{ rsyslog_ppa_version }}'
state: present
update_cache: true
register: rsyslog_ppa_added
when: rsyslog_ppa_use | bool
- name: upgrade rsyslog to version from PPA
apt:
name: rsyslog
state: latest
when: rsyslog_ppa_added.changed
tags: ['skip_ansible_lint']
# {{ ansible_managed }}
# {{ rsyslog_conf_file_path }} Configuration file for rsyslog.
#
# For more information see
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#
# Default logging rules can be found in {{ rsyslog_conf_path }}/50-default.conf
#################
#### MODULES ####
#################
$ModLoad imuxsock # provides support for local system logging
$ModLoad imklog # provides kernel logging support (previously done by rklogd)
#$ModLoad immark # provides --MARK-- message capability
# provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
# provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
###########################
#### GLOBAL DIRECTIVES ####
###########################
#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate {{ rsyslog_action_file_default_template }}
# Filter duplicated messages
$RepeatedMsgReduction {{ rsyslog_repeated_msg_reduction }}
#
# Set the default permissions for all log files.
#
$FileOwner {{ rsyslog_user }}
$FileGroup {{ rsyslog_group }}
$FileCreateMode {{ rsyslog_file_create_mode }}
$DirCreateMode {{ rsyslog_dir_create_mode }}
$Umask {{ rsyslog_umask }}
$PrivDropToUser {{ rsyslog_user }}
$PrivDropToGroup {{ rsyslog_user }}
#
# Where to place spool files
#
$WorkDirectory {{ rsyslog_spool_path }}
#
# Include all config files in {{ rsyslog_conf_path }}/
#
$IncludeConfig {{ rsyslog_conf_path }}/*.conf
# {{ ansible_managed }}
{% if item.ruleset is defined %}
{{ item.ruleset }}
{% endif %}
---
root_group: root
rsyslog_conf_path: /etc/rsyslog.d
rsyslog_conf_file_path: /etc/rsyslog.conf
rsyslog_spool_path: /var/spool/rsyslog
__rsyslog_user: "syslog"
__rsyslog_group: "adm"
__rsyslog_file_create_mode: "0640"
__rsyslog_dir_create_mode: "0755"
__rsyslog_umask: "0022"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment