Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from bodsch/feature/remove-logrotate-configs
Browse files Browse the repository at this point in the history
implement state to remove configfiles
  • Loading branch information
bodsch authored Sep 14, 2021
2 parents 1b499b3 + c6977ed commit 1d89c75
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 197 deletions.
103 changes: 94 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows

name: CI

on:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
# Trigger the workflow on push or pull request,
# but only for the main branch
pull_request:
Expand All @@ -16,7 +15,7 @@ on:
branches:
- master
schedule:
- cron: "0 2 * * 0"
- cron: "10 2 * * 0"

defaults:
run:
Expand All @@ -42,7 +41,49 @@ jobs:
# VALIDATE_MARKDOWN: trues
VALIDATE_YAML: true

test:
arch_standard:
name: "${{ matrix.image }} / python: ${{ matrix.python-version }}, ansible: ${{ matrix.ansible-version }}"
needs:
- lint
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
image:
- archlinux:latest
python-version:
- '3.8'
- '3.9'
ansible-version:
- '2.9'
- '2.10'

steps:
- name: check out the codebase.
uses: actions/checkout@v2
with:
path: 'ansible-logrotate'

- name: set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: install dependencies
run: |
python -m pip install --upgrade pip
pip install -r test-requirements.txt
- name: test default
run: |
tox -e py$(printf "${{ matrix.python-version }}" | tr -d '.')-ansible$(printf "${{ matrix.ansible-version }}" | tr -d '.') -- \
molecule test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
DISTRIBUTION: ${{ matrix.image }}

deb_standard:
name: "${{ matrix.image }} / python: ${{ matrix.python-version }}, ansible: ${{ matrix.ansible-version }}"
needs:
- lint
Expand All @@ -55,10 +96,52 @@ jobs:
- debian:10
- ubuntu:18.04
- ubuntu:20.04
python-version:
- '3.8'
- '3.9'
ansible-version:
- '2.9'
- '2.10'

steps:
- name: check out the codebase.
uses: actions/checkout@v2
with:
path: 'ansible-logrotate'

- name: set up python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: install dependencies
run: |
python -m pip install --upgrade pip
pip install -r test-requirements.txt
- name: test default
run: |
tox -e py$(printf "${{ matrix.python-version }}" | tr -d '.')-ansible$(printf "${{ matrix.ansible-version }}" | tr -d '.') -- \
molecule test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
DISTRIBUTION: ${{ matrix.image }}

rpm_standard:
name: "${{ matrix.image }} / python: ${{ matrix.python-version }}, ansible: ${{ matrix.ansible-version }}"
needs:
- lint
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
image:
- centos:7
- centos:8
- oraclelinux:7
- oraclelinux:8
python-version:
- '3.7'
- '3.8'
- '3.9'
ansible-version:
Expand All @@ -81,10 +164,10 @@ jobs:
python -m pip install --upgrade pip
pip install -r test-requirements.txt
- name: test with tox
- name: test default
run: |
tox -e py$(printf "${{ matrix.python-version }}" | tr -d '.')-ansible$(printf "${{ matrix.ansible-version }}" | tr -d '.') \
-- molecule test
tox -e py$(printf "${{ matrix.python-version }}" | tr -d '.')-ansible$(printf "${{ matrix.ansible-version }}" | tr -d '.') -- \
molecule test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
Expand All @@ -93,7 +176,9 @@ jobs:
publish:
if: github.ref == 'refs/heads/master'
needs:
- test
- arch_standard
- deb_standard
- rpm_standard
runs-on: ubuntu-18.04
steps:
- name: galaxy
Expand Down
104 changes: 51 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,91 +13,89 @@ specifying a list of directives.
[issues]: https://github.com/bodsch/ansible-logrotate/issues?q=is%3Aopen+is%3Aissue
[releases]: https://github.com/bodsch/ansible-logrotate/releases

## tested operating systems

## Requirements & Dependencies

None

### Operating systems

Tested on

* Debian 9 / 10
* Ubuntu 18.04 / 20.04
* CentOS 8
* Oracle Linux 8
* CentOS 7 / 8
* Oracle Linux 7 / 8
* Arch Linux

## Requirements
## usage

None

## Role Variables
```yaml
logrotate_global:
rotate_log: weekly
rotate_size: ''
su_user: ''
su_group: ''
rotate: 2
create: true
dateext: true
compress: true
tabooext: []
archive_directory: ''

logrotate_conf_dir: "/etc/logrotate.d"

logrotate_scripts: {}

logroate_disable_systemd: true
```
**logrotate_scripts**: A list of logrotate scripts and the directives to use for the rotation.
### **logrotate_scripts**: A dictionary of logrotate scripts and the directives to use for the rotation.
* `name` - The name of the script that goes into /etc/logrotate.d/
* `state` - create (`present`) or remove (`absent`) configuration. default: `present`
* `path` - Path to point logrotate to for the log rotation
* `paths` - A list of paths to point logrotate to for the log rotation.
* `options` - List of directives for logrotate, view the logrotate man page for specifics
* `scripts` - Dict of scripts for logrotate (see Example below)

```yaml
logrotate_scripts:
- name: rails
path: "/srv/current/log/*.log"
audit:
path: /var/log/audit/audit.log
options:
- weekly
- size 25M
- rotate 4
- missingok
- compress
- notifempty
- delaycompress
- copytruncate
scripts:
postrotate: /etc/init.d/auditd restart2> /dev/null
```

```yaml
logrotate_scripts:
- name: rails
nginx:
paths:
- "/srv/current/scare.log"
- "/srv/current/hide.log"
- /var/log/nginx/*/*.log
- /var/log/nginx/*.log
options:
- weekly
- size 25M
- rotate 2
- missingok
- notifempty
- compress
- delaycompress
- copytruncate
- sharedscripts
- create 0644 http log
- su root http
scripts:
postrotate: test ! -r /run/nginx.pid || kill -USR1 $(cat /run/nginx.pid)
```

## Dependencies
None
## Example Playbook

Setting up logrotate for additional Nginx logs, with postrotate script.
see into [molecule test](molecule/default/converge.yml) and [configuration](molecule/default/group_vars/all/vars.yml)


```yaml
- hosts: all
vars:
logrotate_scripts:
- name: nginx-options
path: /var/log/nginx/options.log
options:
- daily
- weekly
- size 25M
- rotate 7
- missingok
- compress
- delaycompress
- copytruncate

- name: nginx-scripts
path: /var/log/nginx/scripts.log
options:
- daily
- weekly
- size 25M
scripts:
postrotate: "echo test"

roles:
- ansible-logrotate
```

## Tests

Expand Down
70 changes: 68 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,84 @@
---

logrotate_global:
# frequency
# - hourly
# Log files are rotated every hour.
# Note that usually logrotate is configured to be run by cron daily.
# You have to change this configuration and run logrotate hourly to be able
# to really rotate logs hourly.
# - daily
# Log files are rotated every day.
# - weekly
# Log files are rotated once each weekday,
# or if the date is advanced by at least 7 days since the last rotation (while ignoring the exact time).
# The weekday interpretation is following:
# 0 means Sunday,
# 1 means Monday,
# ...,
# 6 means Saturday;
# the special value 7 means each 7 days, irrespectively of weekday.
# Defaults to 0 if the weekday argument is omitted.
# - monthly
# Log files are rotated the first time logrotate is run in a month (this is normally on the first day of the month).
# - yearly
# Log files are rotated if the current year is not the same as the last rotation.
#
rotate_log: weekly
rotate_size: 20M
# restrict maximum size of log files
# Log files are rotated only if they grow bigger than size bytes.
# If size is followed by k, the size is assumed to be in kilobytes.
# If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes.
# So size 100, size 100k, size 100M and size 100G are all valid.
# This option is mutually exclusive with the time interval options,
# and it causes log files to be rotated without regard for the last rotation time,
# if specified after the time criteria (the last specified option takes the precedence).
rotate_size: '' # 20M
# Rotate log files set under this user and group instead of using default user/group (usually root)
# su_user specifies the user used for rotation and
# su_group specifies the group used for rotation
su_user: ''
su_group: ''
# Log files are rotated count times before being removed or mailed to the address specified in a mail directive.
# If count is 0, old versions are removed rather than rotated.
# If count is -1, old logs are not removed at all, except they are affected by maxage
# (use with caution, may waste performance and disk space).
rotate: 2
# create new (empty) log files after rotating old ones
create: true
# use date as a suffix of the rotated file
dateext: true
# if you want your log files compressed
compress: true
# taboo extension list
# At startup, the taboo extension list ,
# v, .cfsaved, .disabled, .dpkg-bak, .dpkg-del, .dpkg-dist,
# .dpkg-new, .dpkg-old, .rhn-cfg-tmp-*, .rpmnew, .rpmorig,
# .rpmsave, .swp, .ucf-dist, .ucf-new, .ucf-old, ~
# for arch based distribution, you can add her:
# .pacorig, .pacnew, .pacsave
tabooext: []
# Logs are moved into directory for rotation
# e.g. /var/log/archive
archive_directory: ''

logrotate_conf_dir: "/etc/logrotate.d"
logrotate_scripts: []

logrotate_scripts: {}
# audit:
# path: /var/log/audit/audit.log
# description: |
# rotate all audit logs
# options:
# - weekly
# - rotate 4
# - missingok
# - notifempty
# - delaycompress
# scripts:
# prerotate: systemctl stop auditd.service > /dev/null
# postrotate: systemctl start auditd.service > /dev/null
# foo: failed

logroate_disable_systemd: true

Expand Down
Loading

0 comments on commit 1d89c75

Please sign in to comment.