Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Suarez committed Dec 5, 2019
2 parents 2134202 + 539619c commit c8e5873
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 64 deletions.
64 changes: 45 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,36 @@ Role Variables

| Variable | Value | Description |
| :--- | :--- | :--- |
| papertrail_version | "0.20" | Version to install. 0.20 is the latest at the moment |
| papertrail_config_file_path | /etc/papertrail_conf.yml | Name of the configuration file for remote_syslog |
| papertrail_service_enabled | true | Configure remote_syslog for starting when the system is booted |
| papertrail_service_started | true | The role will start the service after applying the configuration |
| papertrail_managed_conf_file | true | If disabled, no configuration will be applied (None of the following variables will be used). Just the installation so far |
| papertrail_custom_hostname | "" | By default remote_syslog2 uses the hostname of the node. This can be this can be overwritten here |
| papertrail_destination_host | "" | The papertrail destination host to send the logs to. Check your papertrail account for it |
| papertrail_version | "0.20" | Version to install. 0.20 is the latest at the moment. |
| papertrail_config_file_path | /etc/papertrail_conf.yml | Name of the configuration file for remote_syslog. |
| papertrail_service_enabled | true | Configure remote_syslog for starting when the system is booted. |
| papertrail_service_started | true | The role will start the service after applying the configuration. |
| papertrail_managed_conf_file | true | If disabled, no configuration will be applied (None of the following variables will be used). Just the installation and nothing else. |
| papertrail_custom_hostname | "" | By default remote_syslog2 uses the hostname of the node. This can be this can be overwritten here. |
| papertrail_destination_host | "" | The papertrail destination host to send the logs to. Check your papertrail account for it. |
| papertrail_destination_port | "" | The papertrail destination port to connect to the destination host. Check your papertrail account for it |
| papertrail_destination_protocol | tls | This value can be tls(encrypted) or tcp (unencrypted) |
| papertrail_destination_protocol | tls | This value can be tls(encrypted) or tcp (unencrypted). |
| papertrail_log_facility | "" | The syslog facility to use. See https://en.wikipedia.org/wiki/Syslog#Facility |
| papertrail_log_severity | "" | The syslog severity to use. See https://en.wikipedia.org/wiki/Syslog#Severity_level |
| papertrail_new_file_check_interval | "" | If a glob pattern for logs files is used this parameter controls the frecuency of checking for new log files in the directory |
| papertrail_files_to_log | [] | The file or globs to read |
| papertrail_files_to_exclude | [] | Files to exclude in a directory |
| papertrail_new_file_check_interval | "" | If a glob pattern for logs files is used this parameter controls the frecuency of checking for new log files in the directory. |
| papertrail_files_to_log | [] | The file or globs to read. **See notes below**|
| papertrail_files_to_exclude | [] | Files to exclude in a directory. **See notes below** |
| papertrail_common_files_to_log | [] | Defines common files or globs to read and send to Papertrail. Tipically you will declare this variable in the `all` metagroup. |
| papertrail_common_files_to_exclude | [] | Defines common files to exclude. Tipically you will declare this variable in the `all` metagroup. |
| papertrail_group_files_to_log | [] | Defines group files or globs to read and send to Papertrail. Tipically you will declare this variable in a metagroup or group like `webservers` or `databases`. |
| papertrail_group_files_to_exclude | [] | Defines files to exlude per group. Same as previous `papertrail_group_files_to_log` but for excluding files to be logged. |
| papertrail_host_files_to_log | [] | Defines host files or globs to read and send to Papertrail. Tipically you will declare this variable in a hostvar to be applied in a specific host. |
| papertrail_host_files_to_exclude | [] | Defines files to exlude per host. Same as previous `papertrail_host_files_to_log` but for excluding files to be logged. |
| papertrail_exclude_patterns | [] | The pattern in the log file you are reading you want to ignore. |

> For more detailed information about remote_syslog2 configuration see https://github.com/papertrail/remote_syslog2/blob/master/README.md
> This role also provides the possibility of overwriting any variable in the **vars/** directory. You **never should do it**. This feature only exists for covering any unexpected scenario you might find. For doing it, just declare the variable/variables without the double underscore on your group_vars, host_vars, command line etc as you would do for a variable in defaults/.
Notes:
- In previous versions of this role only `papertrail_files_to_log` and `papertrail_files_to_exclude` where the way for declaring files to log and exclude respectively. After using this role for a while in real scenarios I realize that three levels of configuration (common, group, host) are much better and clean. I am keeping this variables for retro compatibility reasons having this way the same behaviour this role had since the beggining.


Dependencies
------------

Expand All @@ -44,21 +54,37 @@ None.
Example Playbook
----------------

- group_vars/all/papertrail.yml:
```yaml
papertrail_common_files_to_log:
- path: /var/log/messages
tag: messages
- path: /var/log/secure
tag: secure
```
- group_vars/webservers/papertrail.yml:
```yaml
papertrail_group_files_to_log:
- path: /var/log/httpd.log
tag: apache
```
- host_vars/www.foo.bar/papertrail.yml:
```yaml

papertrail_custom_hostname: "problematic-host-01"
papertrail_host_files_to_log:
- /var/log/dmesg
```
```yaml
- hosts: servers
vars:
papertrail_version: "0.19"
papertrail_destination_host: logs.papertrailapp.com
papertrail_destination_port: 12345
papertrail_custom_hostname: "host-01"
papertrail_destination_protocol: tls
papertrail_files_to_log:
- path: /var/log/httpd.log
tag: apache
- /var/log/audit/*.log
- /var/log/nginx/*.log
papertrail_files_to_exclude:
- /var/log/nginx/access.log
papertrail_log_facility: local7
papertrail_log_severity: warn
roles:
Expand Down
25 changes: 24 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,39 @@
papertrail_version: "0.20"

papertrail_service_enabled: true

papertrail_service_started: true

papertrail_managed_conf_file: true

papertrail_custom_hostname: ""

papertrail_destination_host: ""

papertrail_destination_port: ""

papertrail_destination_protocol: tls

papertrail_log_facility: ""

papertrail_log_severity: ""

papertrail_new_file_check_interval: ""

papertrail_exclude_patterns: []

papertrail_files_to_log: []

papertrail_files_to_exclude: []
papertrail_exclude_patterns: []

papertrail_common_files_to_log: []

papertrail_common_files_to_exclude: []

papertrail_group_files_to_log: []

papertrail_group_files_to_exclude: []

papertrail_host_files_to_log: []

papertrail_host_files_to_exclude: []
22 changes: 14 additions & 8 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@
papertrail_destination_port: 12345
papertrail_custom_hostname: "host-01"
papertrail_destination_protocol: tls
papertrail_files_to_log:
- path: /var/log/nginx.log
tag: nginx
- path: /var/log/httpd.log
papertrail_common_files_to_log:
- path: /var/log/messages
tag: messages
- path: /var/log/secure
tag: secure
papertrail_group_files_to_log:
- path: /var/log/*
tag: apache
- /var/log/yum.log
- /var/log/audit/*.log
papertrail_files_to_exclude:
- /var/log/yum.log
papertrail_group_files_to_exclude:
- /var/log/*.old
papertrail_host_files_to_log:
- path: /var/log/yum.log
tag: yum
- /var/log/dmesg

papertrail_log_facility: local7
papertrail_log_severity: warn
papertrail_exclude_patterns:
Expand Down
17 changes: 16 additions & 1 deletion molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,26 @@ def test_papertrail_conf_file(host):
assert f.group == 'root'


def test_papertrail_conf_file_content(host):
def test_papertrail_files_to_log(host):
f = host.file('/etc/log_files.yml')

assert f.contains('/var/log/dmesg')


def test_papertrail_files_to_exclude(host):
f = host.file('/etc/log_files.yml')

assert f.contains(r'/var/log/\*.old')


def test_papertrail_exclude_patterns(host):
f = host.file('/etc/log_files.yml')

assert f.contains('this is a test')


def test_papertrail_service(host):
s = host.service('remote_syslog')

assert s.is_enabled
assert s.is_running
37 changes: 16 additions & 21 deletions tasks/variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,22 @@
include_vars:
file: "{{ ansible_os_family }}.yml"

- name: Set papertrail download url
- name: Converge files to log
set_fact:
papertrail_download_url: "{{ __papertrail_download_url }}"
when: papertrail_download_url is not defined
files_to_log: >
{{
papertrail_files_to_log | default([]) |
union(papertrail_common_files_to_log | default([])) |
union(papertrail_group_files_to_log | default([])) |
union(papertrail_host_files_to_log | default([]))
}}
- name: Set papertrail config file path
- name: Converge files to exclude
set_fact:
papertrail_config_file_path: "{{ __papertrail_config_file_path }}"
when: papertrail_config_file_path is not defined

- name: Set papertrail config file name
set_fact:
papertrail_config_file_name: "{{ __papertrail_config_file_name }}"
when: papertrail_config_file_name is not defined

- name: Set papertrail package name
set_fact:
papertrail_package_name: "{{ __papertrail_package_name }}"
when: papertrail_package_name is not defined

- name: Set papertrail service name
set_fact:
papertrail_service_name: "{{ __papertrail_service_name }}"
when: papertrail_service_name is not defined
files_to_exclude: >
{{
papertrail_files_to_log | default([]) |
union(papertrail_common_files_to_exclude | default([])) |
union(papertrail_group_files_to_exclude | default([])) |
union(papertrail_host_files_to_exclude | default([]))
}}
17 changes: 9 additions & 8 deletions templates/papertrail_conf.yml.j2
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
# {{ ansible_managed }}

{% if papertrail_custom_hostname is defined and papertrail_custom_hostname | length %}
hostname: {{ papertrail_custom_hostname }}
{% endif %}
destination:
host: {{ papertrail_destination_host }}
port: {{ papertrail_destination_port }}
protocol: {{ papertrail_destination_protocol }}
{% if papertrail_files_to_log is defined and papertrail_files_to_log | length %}
{% if files_to_log | length %}
files:
{% for log_file in papertrail_files_to_log %}
{% if log_file is mapping %}
{% for key, value in log_file.items() %}
{% for file in files_to_log %}
{% if file is mapping %}
{% for key, value in file.items() %}
{% if key == "path" %}
- {{ key }}: {{ value }}
{% else %}
{{ key }}: {{ value }}
{% endif %}
{% endfor %}
{% else %}
- {{ log_file }}
- {{ file }}
{% endif %}
{% endfor %}
{% endif %}
{% if papertrail_files_to_exclude is defined and papertrail_files_to_exclude | length %}
{% if files_to_exclude | length %}
exclude_files:
{% for file_to_exclude in papertrail_files_to_exclude %}
- {{ file_to_exclude }}
{% for file in files_to_exclude %}
- {{ file }}
{% endfor %}
{% endif %}
{% if papertrail_exclude_patterns is defined and papertrail_exclude_patterns | length %}
Expand Down
2 changes: 1 addition & 1 deletion vars/Debian.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
__papertrail_package_name: "remote-syslog2_{{ papertrail_version }}_{{ installer_arch }}.deb"
papertrail_package_name: "remote-syslog2_{{ papertrail_version }}_{{ installer_arch }}.deb"
2 changes: 1 addition & 1 deletion vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
__papertrail_package_name: "remote_syslog2-{{ papertrail_version }}-1.{{ ansible_architecture }}.rpm"
papertrail_package_name: "remote_syslog2-{{ papertrail_version }}-1.{{ ansible_architecture }}.rpm"
8 changes: 4 additions & 4 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
__papertrail_download_url: "https://github.com/papertrail/remote_syslog2/releases/download/v{{ papertrail_version }}"
__papertrail_config_file_path: /etc
__papertrail_config_file_name: log_files.yml
__papertrail_service_name: remote_syslog
papertrail_download_url: "https://github.com/papertrail/remote_syslog2/releases/download/v{{ papertrail_version }}"
papertrail_config_file_path: /etc
papertrail_config_file_name: log_files.yml
papertrail_service_name: remote_syslog

0 comments on commit c8e5873

Please sign in to comment.