Import github.com/arillso/ansible.logrotate

at version 1.5.2 (commit 038649f
This commit is contained in:
Serge van Ginderachter 2020-09-09 16:17:43 +02:00
parent 008fdbaa1f
commit b0e5245e4e
No known key found for this signature in database
GPG key ID: 3148E9B9232D65E5
9 changed files with 248 additions and 0 deletions

49
defaults/main.yml Normal file
View file

@ -0,0 +1,49 @@
---
# List of global options. If this is empty the default options of the
# distribution are used.
logrotate_options: []
# Path to the include files
logrotate_include_dir: /etc/logrotate.d
# package name to install logrotate.
logrotate_package: logrotate
# Enable hourly rotation with cron.
logrotate_use_hourly_rotation: false
# logroate for wtmp
logrotate_wtmp:
logs:
- /var/log/wtmp
options:
- missingok
- monthly
- create 0664 root utmp
- rotate 1
# logroate for btmp
logrotate_btmp:
logs:
- /var/log/btmp
options:
- missingok
- monthly
- create 0660 root utmp
- rotate 1
# More log files can be added that will log rotate.
# An example of multiple log rotate applications with available settings:
# logrotate_applications:
# - name: name-your-log-rotate-application
# definitions:
# - logs:
# - /var/log/apt/term.log
# - /var/log/apt/history.log
# options:
# - rotate 12
# - monthly
# - missingok
# - notifempty
# - compress
logrotate_applications: []

32
meta/main.yml Normal file
View file

@ -0,0 +1,32 @@
---
galaxy_info:
author: 'stationgroup'
description: |
Ansible role for installings and configuring lograte on Linux, deploying a list of defaults only if the
logfiles are present on the system.
license: MIT
min_ansible_version: 2.8
platforms:
- name: EL
versions:
- 6
- 7
- name: Fedora
versions:
- 29
- name: Ubuntu
versions:
- bionic
- cosmic
- disco
- name: Debian
versions:
- jessie
- stretch
- buster
galaxy_tags:
- system
- logrotate
- log
- rotate

63
tasks/main.yml Normal file
View file

@ -0,0 +1,63 @@
---
- name: add OS specific variables
include_vars: '{{ loop_vars }}'
with_first_found:
- files:
- '{{ distribution }}-{{ distribution_version }}.yml'
- '{{ distribution }}-{{ distribution_major_version }}.yml'
- '{{ distribution }}.yml'
- '{{ ansible_os_family }}.yml'
- '{{ ansible_system }}.yml'
- 'defaults.yml'
paths:
- 'vars'
loop_control:
loop_var: loop_vars
vars:
distribution: '{{ ansible_distribution }}'
distribution_version: '{{ ansible_distribution_version }}'
distribution_major_version: '{{ ansible_distribution_major_version }}'
tags:
- configuration
- packages
- name: 'install logrotate packages'
become: true
package:
name: '{{ logrotate_package }}'
state: present
register: register_install_package
until: register_install_package is succeeded
retries: 3
tags:
- packages
- name: 'create logrotate configuration file'
become: true
template:
src: 'etc/logrotate.conf.j2'
dest: '/etc/logrotate.conf'
owner: root
group: root
mode: 0644
tags:
- configuration
- name: 'create logrotate application configuration files'
become: true
template:
src: 'etc/logrotate.d/application.j2'
dest: '/etc/logrotate.d/{{ item.name }}'
owner: root
group: root
mode: 0644
with_items:
- '{{ logrotate_applications }}'
tags:
- configuration
- name: Symlink for hourly rotation
file:
path: "/etc/cron.hourly/logrotate"
src: "/etc/cron.daily/logrotate"
state: "{{ 'link' if logrotate_use_hourly_rotation else 'absent' }}"

View file

@ -0,0 +1,30 @@
{{ ansible_managed | comment }}
# see "man logrotate" for details
{% if logrotate_options | length > 0 %}
{% for option in logrotate_options %}
{{ option }}
{% endfor %}
{% else %}
{% for option in logrotate_distribution_options | default([]) %}
{{ option }}
{% endfor %}
{% endif %}
# packages drop log rotation information into this directory
include {{ logrotate_include_dir }}
# no packages own wtmp, or btmp -- we'll rotate them here
{{ logrotate_wtmp.logs | join(" ") }} {
{% for option in logrotate_wtmp.options %}
{{ option }}
{% endfor %}
}
{{ logrotate_btmp.logs | join(" ") }} {
{% for option in logrotate_btmp.options %}
{{ option }}
{% endfor %}
}
# system-specific logs may be configured here

View file

@ -0,0 +1,37 @@
{{ ansible_managed | comment }}
{% for definition in item.definitions %}
{{ definition.logs | join(" ") }} {
{% for option in definition.options %}
{{ option }}
{% endfor %}
{% if definition.postrotate|default([]) %}
postrotate
{% for line in definition.postrotate %}
{{ line }}
{% endfor %}
endscript
{% endif %}
{% if definition.preremove|default([]) %}
preremove
{% for line in definition.preremove %}
{{ line }}
{% endfor %}
endscript
{% endif %}
{% if definition.lastaction|default([]) %}
lastaction
{% for line in definition.lastaction %}
{{ line }}
{% endfor %}
endscript
{% endif %}
{% if definition.firstaction|default([]) %}
firstaction
{% for line in definition.firstaction %}
{{ line }}
{% endfor %}
endscript
{% endif %}
}
{% endfor %}

9
vars/CentOS.yml Normal file
View file

@ -0,0 +1,9 @@
---
# vars file for arillso.logrotate
# List of global options for the different systems.
logrotate_distribution_options:
- weekly
- rotate 4
- create
- dateext

9
vars/Debian.yml Normal file
View file

@ -0,0 +1,9 @@
---
# vars file for arillso.logrotate
# List of global options for the different systems.
logrotate_distribution_options:
- weekly
- rotate 4
- create
- dateext

9
vars/RedHat.yml Normal file
View file

@ -0,0 +1,9 @@
---
# vars file for arillso.logrotate
# List of global options for the different systems.
logrotate_distribution_options:
- weekly
- rotate 4
- create
- dateext

10
vars/Ubuntu.yml Normal file
View file

@ -0,0 +1,10 @@
---
# vars file for arillso.logrotate
# List of global options for the different systems.
logrotate_distribution_options:
- weekly
- rotate 4
- create
- dateext
- su root syslog