Feature 1/path testing #2
|
@ -1,2 +1,9 @@
|
||||||
# ansible-logrotate-plusplus
|
# ansible-logrotate-plusplus
|
||||||
Ansible role which installs and configures logrotate
|
Ansible role which installs and configures logrotate
|
||||||
|
It can test if paths exist before writing a logrotate config to the server.
|
||||||
|
Load the roles default vars with custom paths and per path parameters, and run the playbook across a dynamic
|
||||||
|
infrastructure and only write logerotate rules to the appropriate system with the correct paths present.
|
||||||
|
|
||||||
|
This project was based of https://github.com/arillso/ansible.logrotate 1.5.2
|
||||||
|
(https://github.com/arillso/ansible.logrotate/commit/038649f7933c21ba9f1f2c8363bfb4d49aaf46f2)
|
||||||
|
|
||||||
|
|
|
@ -36,14 +36,50 @@ logrotate_btmp:
|
||||||
# An example of multiple log rotate applications with available settings:
|
# An example of multiple log rotate applications with available settings:
|
||||||
# logrotate_applications:
|
# logrotate_applications:
|
||||||
# - name: name-your-log-rotate-application
|
# - name: name-your-log-rotate-application
|
||||||
# definitions:
|
# logs:
|
||||||
# - logs:
|
# - /var/log/apt/term.log
|
||||||
# - /var/log/apt/term.log
|
# - /var/log/apt/history.log
|
||||||
# - /var/log/apt/history.log
|
# options:
|
||||||
# options:
|
# - rotate 12
|
||||||
# - rotate 12
|
# - monthly
|
||||||
# - monthly
|
# - missingok
|
||||||
# - missingok
|
# - notifempty
|
||||||
# - notifempty
|
# - compress
|
||||||
# - compress
|
logrotate_applications:
|
||||||
logrotate_applications: []
|
- name: nextcloud-snap-apache-php_errors
|
||||||
|
logs:
|
||||||
|
- /var/snap/nextcloud/current/apache/logs/*.log
|
||||||
|
options:
|
||||||
|
- daily
|
||||||
|
- compress
|
||||||
|
- rotate 6
|
||||||
|
- missingok
|
||||||
|
- copytruncate
|
||||||
|
- delaycompress
|
||||||
|
|
||||||
|
- name: nextcloud-snap-apache-error_log"
|
||||||
|
logs:
|
||||||
|
- /var/snap/nextcloud/current/apache/logs/error_log
|
||||||
|
options:
|
||||||
|
- daily
|
||||||
|
- compress
|
||||||
|
- rotate 6
|
||||||
|
- missingok
|
||||||
|
- copytruncate
|
||||||
|
- delaycompress
|
||||||
|
|
||||||
|
- name: custom
|
||||||
|
logs:
|
||||||
|
- /var/log/custom/*_log
|
||||||
|
options:
|
||||||
|
- daily
|
||||||
|
- compress
|
||||||
|
- rotate 6
|
||||||
|
|
||||||
|
- name : dpkg
|
||||||
|
logs:
|
||||||
|
- /var/log/dpkg.log
|
||||||
|
options:
|
||||||
|
- daily
|
||||||
|
- compress
|
||||||
|
- rotate 6
|
||||||
|
|
22
tasks/create-logrotate-application-configuration-files.yml
Normal file
22
tasks/create-logrotate-application-configuration-files.yml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
---
|
||||||
|
- name: 'check if there exist log files for {{ item.name }}'
|
||||||
|
shell:
|
||||||
|
cmd: "ls -l {{ item.logs|join(' ') }}"
|
||||||
|
changed_when: false
|
||||||
|
register: _available_logs
|
||||||
|
check_mode: false
|
||||||
|
failed_when: false
|
||||||
|
tags:
|
||||||
|
- configuration
|
||||||
|
|
||||||
|
- name: 'create logrotate configuration file for {{ item.name }}'
|
||||||
|
become: true
|
||||||
|
template:
|
||||||
|
src: 'etc/logrotate.d/application.j2'
|
||||||
|
dest: '/etc/logrotate.d/{{ item.name }}'
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
when: _available_logs.stdout_lines|length() > 0
|
||||||
|
tags:
|
||||||
|
- configuration
|
|
@ -44,15 +44,10 @@
|
||||||
- configuration
|
- configuration
|
||||||
|
|
||||||
- name: 'create logrotate application configuration files'
|
- name: 'create logrotate application configuration files'
|
||||||
become: true
|
include_tasks: create-logrotate-application-configuration-files.yml
|
||||||
template:
|
loop: '{{ logrotate_applications }}'
|
||||||
src: 'etc/logrotate.d/application.j2'
|
loop_control:
|
||||||
dest: '/etc/logrotate.d/{{ item.name }}'
|
label: "{{ item.name }}"
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0644
|
|
||||||
with_items:
|
|
||||||
- '{{ logrotate_applications }}'
|
|
||||||
tags:
|
tags:
|
||||||
- configuration
|
- configuration
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,35 @@
|
||||||
{{ ansible_managed | comment }}
|
{{ ansible_managed | comment }}
|
||||||
|
|
||||||
{% for definition in item.definitions %}
|
{{ item.logs | join(" ") }} {
|
||||||
{{ definition.logs | join(" ") }} {
|
{% for option in item.options %}
|
||||||
{% for option in definition.options %}
|
|
||||||
{{ option }}
|
{{ option }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if definition.postrotate|default([]) %}
|
{% if item.postrotate|default([]) %}
|
||||||
postrotate
|
postrotate
|
||||||
{% for line in definition.postrotate %}
|
{% for line in item.postrotate %}
|
||||||
{{ line }}
|
{{ line }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
endscript
|
endscript
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if definition.preremove|default([]) %}
|
{% if item.preremove|default([]) %}
|
||||||
preremove
|
preremove
|
||||||
{% for line in definition.preremove %}
|
{% for line in item.preremove %}
|
||||||
{{ line }}
|
{{ line }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
endscript
|
endscript
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if definition.lastaction|default([]) %}
|
{% if item.lastaction|default([]) %}
|
||||||
lastaction
|
lastaction
|
||||||
{% for line in definition.lastaction %}
|
{% for line in item.lastaction %}
|
||||||
{{ line }}
|
{{ line }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
endscript
|
endscript
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if definition.firstaction|default([]) %}
|
{% if item.firstaction|default([]) %}
|
||||||
firstaction
|
firstaction
|
||||||
{% for line in definition.firstaction %}
|
{% for line in item.firstaction %}
|
||||||
{{ line }}
|
{{ line }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
endscript
|
endscript
|
||||||
{% endif %}
|
{% endif %}
|
||||||
}
|
}
|
||||||
{% endfor %}
|
|
||||||
|
|
Loading…
Reference in a new issue