reallyenglish.logrotate

ansible-role-logrotate

Installs logrotate.

Requirements

None.

Role Variables

Variable Description Default
logrotate_config Path to logrotate.conf {{ __logrotate_config }}
logrotate_conf_d Path to logrotate.d {{ __logrotate_conf_d }}
logrotate_default_rotate Default value for rotate in logrotate.conf 30
logrotate_default_dateext Default value for dateformat in logrotate.conf true
logrotate_default_dateformat Default value for dateformat in logrotate.conf .%Y%m%d
logrotate_default_freq Default frequency for log rotation in logrotate.conf daily
logrotate_default_su Default value of su in logrotate.conf {{ __logrotate_default_su }}

Debian

Variable Default
__logrotate_config /etc/logrotate.conf
__logrotate_conf_d /etc/logrotate.d
__logrotate_default_su root syslog

FreeBSD

Variable Default
__logrotate_config /usr/local/etc/logrotate.conf
__logrotate_conf_d /usr/local/etc/logrotate.d
__logrotate_default_su root wheel

RedHat

Variable Default
__logrotate_config /etc/logrotate.conf
__logrotate_conf_d /etc/logrotate.d
__logrotate_default_su root root

logrotate module

action_plugins/logrotate.py allows you to create tasks like this:

- name: Rotate logstash.log
  logrotate:
    name: logstash
    files:
      - /var/log/logstash.log
    delaycompress: yes
    compress: yes
    state: present
    frequency: daily

Dependencies

None.

Example Playbook

The following yaml sets up configurations for a default Ubuntu system.

- hosts: localhost
  roles:
    - ansible-role-logrotate
  post_tasks:

    - name: Rotate wtmp
      logrotate:
        name: wtmp
        files:
          - /var/log/wtmp
        frequency: monthly
        missingok: yes
        create: 0664 root utmp
        rotate: 1
        su: root syslog
        state: present

    - name: Rotate btmp
      logrotate:
        name: btmp
        files:
          - /var/log/btmp
        missingok: yes
        frequency: monthly
        create: 0660 root utmp
        rotate: 1
        su: root syslog
        state: present

    - name: Rotate apt logs
      logrotate:
        name: apt
        files:
          - /var/log/apt/term.log
          - /var/log/apt/history.log
        rotate: 12
        frequency: monthly
        compress: yes
        missingok: yes
        notifempty: yes
        state: present

    - name: Rotate dpkg logs
      logrotate: 
        name: dpkg
        files:
          - /var/log/dpkg.log
          - /var/log/alternatives.log
        frequency: monthly
        rotate: 12
        compress: yes
        delaycompress: yes
        missingok: yes
        notifempty: yes
        create: 644 root root
        su: root syslog
        state: present

    - name: Create rsyslog rotation
      logrotate:
        name: rsyslog
        files:
          - /var/log/syslog
        rotate: 7
        frequency: daily
        missingok: yes
        notifempty: yes
        delaycompress: yes
        compress: yes
        su: root syslog
        sharedscripts: no
        postrotate:
          - "reload rsyslog >/dev/null 2>&1 || true"
        state: present
        
    - name: Rotate other rsyslog logs
      logrotate:
        name: rsyslog_others
        files:
          - /var/log/mail.info
          - /var/log/mail.warn
          - /var/log/mail.err
          - /var/log/mail.log
          - /var/log/daemon.log
          - /var/log/kern.log
          - /var/log/auth.log
          - /var/log/user.log
          - /var/log/lpr.log
          - /var/log/cron.log
          - /var/log/debug
          - /var/log/messages
        rotate: 4
        frequency: weekly
        missingok: yes
        notifempty: yes
        compress: yes
        delaycompress: yes
        su: root syslog
        sharedscripts: yes
        postrotate:
          - "reload rsyslog >/dev/null 2>&1 || true"
        state: present

    - name: Rotate unattended-upgrades logs
      logrotate:
        name: unattended-upgrades
        files:
          - /var/log/unattended-upgrades/unattended-upgrades.log
          - /var/log/unattended-upgrades/unattended-upgrades-shutdown.log
        rotate: 6
        frequency: monthly
        compress: yes
        missingok: yes
        notifempty: yes
        state: present

    - name: Rotate upstart logs
      logrotate:
        name: upstart
        files:
          - /var/log/upstart/*.log
        frequency: daily
        missingok: yes
        rotate: 7
        compress: yes
        notifempty: yes
        nocreate: yes
        state: present

  vars:

License

Copyright (c) 2016 Tomoyuki Sakurai <[email protected]>

You can use, copy, modify, and share this software for free, as long as you include this copyright notice.

THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES. THE AUTHOR IS NOT LIABLE FOR ANY DAMAGES RESULTING FROM USING THIS SOFTWARE.

Author Information

Tomoyuki Sakurai tomoyukis@reallyenglish.com

Informazioni sul progetto

Configures logrotate

Installa
ansible-galaxy install reallyenglish.logrotate
Licenza
isc
Download
3.5k
Proprietario