ihrwein / ansible-syslog-ng

The source code of an Ansible syslog-ng role
GNU General Public License v2.0
6 stars 9 forks source link

Syslog-ng Ansible role

Build Status

A role for managing syslog-ng on your computers.

Requirements & Dependencies

Ansible

It was tested on the following versions:

Minimal requirement: 1.4

Syslog-ng

The module works with syslog-ng >= 3.3 versions, it has configurations for each version.

Operating systems

Currently the module was only tested on Ubuntu, but it should work on other Debian based systems, too.

Operating modes

It supports the following modes:

The default mode is local.

Variables

This module uses YAML syntax to define variables. You must explicitly care about the quotation and some values.

If you assign yes or no to a variable, YAML treats it as a boolean value. In most cases you don't want this, so place these words between single or double quotes: 'yes', 'no'.

When you want to write a string into syslog-ng.conf (for example a hostname), you must double quote it ('"secure.example.com"') to get the right string in the config ("secure.example.com"). You can swap the inner an outer quotation marks.

You can find examples in the defaults/main.yml file.

Global variables

Almost all of them has default values in defaults/main.yml.

Mode specific variables

Local

In this mode syslog-ng collects all of your local logs and writes them into files on your local filesystem. It uses the system() and internal() sources. For most systems, this is the default configuration.

Variables:

Client

In this mode, syslog-ng collects all logs from your system and sends them to one or more syslog-ng servers.

Variables:

Examples:

syslog_ng_client_destinations:
  - "candrop.example.com":
      proto: udp
      port: 1234
      filters:
        - filter_name_1
        - filter_name_2
  - "secure.example.com":
      proto: tls
      port: 10514
      ca_dir: /opt/syslog-ng/etc/syslog-ng/ca.d
      key_file: /opt/syslog-ng/etc/syslog-ng/key.d/client.key
      cert_file: /opt/syslog-ng/etc/syslog-ng/cert.d/client_cert.pem
  - "tcp.example.com":
      proto: udp
      port: 1234
  - "syslog.example.com"
      proto: syslog
      port: 601
      extra:
        transport: tcp
        so-keepalive: yes
        so-sndbuf: 1024000

The port field has a default value, but the keys under tls don't.

NOTE: each item in syslog_ng_client_destinationsis a dictionary with only one key - the actual hostname. The proto, port, etc. fields are not on the same level, as the hostname!

NOTE: you have to define all filter statements before you reference them. One way of doing this is to add a filename into syslog_ng_config_includes list, which makes syslog-ng include the contents of this file at be beginning of syslog-ng.conf.

Server

The module receives log messages from network sources in this mode. The local logs are also stored among the received logs.

Variables:

syslog_ng_server_sources:
 - "candrop.example.com":
     proto: udp
     port: 1234
     filters:
       - f_error
       - f_kern
 - "secure.example.com":
     proto: tls
     port: 10514
     ca_dir: /opt/syslog-ng/etc/syslog-ng/ca.d
     key_file: /opt/syslog-ng/etc/syslog-ng/key.d/client.key
     cert_file: /opt/syslog-ng/etc/syslog-ng/cert.d/client_cert.pem
 - "tcp.example.com":
     proto: udp
     port: 1234
 - "syslog.example.com":
     proto: syslog
     port: 601
     extra:
       transport: tcp
       so-keepalive: yes
 syslog_ng_server_file_macro: $YEAR.$MONTH.$DAY/$HOST.log

Manual

This role was designed with simplicity in mind to be easy to use and provide the most basic functionalities without manually touching syslog-ng.conf.

For that very reason you can use this mode to use syslog-ng in the normal way, by manually defining sources, destination, filters and so on.

The templates/manual/syslog-ng/[YOUR_SYSLOG-NG_VERSION]/syslog-ng.j2 file includes a copy of a stock Debian syslog-ng.conf. You can use Jinja expressions in it and you have access to the defined variables as well. Tweak it as you want, by applying this role the modified configuration will be automatically 'copied' to your server.

Development

Contribution

If you find a bug, please open an issue on GitHub.

If you want to hack some features into this role, please open an issue and we will talk about that.