reallyenglish.logrotate

ansible-role-logrotate

安装 logrotate

要求

角色变量

变量 描述 默认值
logrotate_config logrotate.conf 的路径 {{ __logrotate_config }}
logrotate_conf_d logrotate.d 的路径 {{ __logrotate_conf_d }}
logrotate_default_rotate logrotate.confrotate 的默认值 30
logrotate_default_dateext logrotate.confdateformat 的默认值 true
logrotate_default_dateformat logrotate.confdateformat 的默认值 .%Y%m%d
logrotate_default_freq logrotate.conf 中日志旋转的默认频率 daily
logrotate_default_su logrotate.confsu 的默认值 {{ __logrotate_default_su }}

Debian

变量 默认值
__logrotate_config /etc/logrotate.conf
__logrotate_conf_d /etc/logrotate.d
__logrotate_default_su root syslog

FreeBSD

变量 默认值
__logrotate_config /usr/local/etc/logrotate.conf
__logrotate_conf_d /usr/local/etc/logrotate.d
__logrotate_default_su root wheel

RedHat

变量 默认值
__logrotate_config /etc/logrotate.conf
__logrotate_conf_d /etc/logrotate.d
__logrotate_default_su root root

logrotate 模块

action_plugins/logrotate.py 可以创建类似于以下的任务。

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

依赖

示例剧本

以下 yaml 为默认的 Ubuntu 创建配置。

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

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

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

    - name: 旋转 apt
      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: 旋转 dpkg
      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: 创建 rsyslog
      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: 旋转其他 rsyslog 日志
      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: 旋转 unattended-upgrades-shutdown.log
      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: 旋转 upstart
      logrotate:
        name: upstart
        files:
          - /var/log/upstart/*.log
        frequency: daily
        missingok: yes
        rotate: 7
        compress: yes
        notifempty: yes
        nocreate: yes
        state: present

  vars:

许可证

版权 (c) 2016 Tomoyuki Sakurai <tomoyukis@reallyenglish.com>

特此授予使用、复制、修改和分发本软件的权利,可以带或不带费用,前提是上面的版权声明和本许可证声明出现在所有副本中。

本软件按“原样”提供,作者对本软件不做任何保证,包括对适销性和适合特定用途的所有隐含保证。在任何情况下,作者都不对因使用本软件或与本软件的使用或性能有关的任何特殊、直接、间接或后果性损害或其他任何损害负责。

作者信息

Tomoyuki Sakurai tomoyukis@reallyenglish.com

关于项目

Configures logrotate

安装
ansible-galaxy install reallyenglish.logrotate
许可证
isc
下载
3.5k
拥有者