buluma.logrotate
Ansible 角色 logrotate
在您的系统上安装和配置 logrotate。
GitHub | 版本 | 问题 | 拉取请求 | 下载 |
---|---|---|---|---|
示例剧本
此示例来自 molecule/default/converge.yml
,并在每次提交、拉取请求和发布时进行测试。
---
- name: Converge
hosts: all
become: true
gather_facts: true
vars:
logrotate_frequency: daily
logrotate_keep: 7
logrotate_compress: true
logrotate_entries:
- name: example
path: "/var/log/example/*.log"
- name: example-frequency
path: "/var/log/example-frequency/*.log"
frequency: weekly
- name: example-keep
path: "/var/log/example-keep/*.log"
keep: 14
- name: example-compress
path: "/var/log/example-compress/*.log"
compress: true
- name: example-copylog
path: "/var/log/example-copylog/*.log"
copylog: true
- name: example-copytruncate
path: "/var/log/example-copytruncate/*.log"
copytruncate: true
- name: example-delaycompress
path: "/var/log/example-delaycompress/*.log"
delaycompress: true
- name: example-script
path: "/var/log/example-script/*.log"
postrotate: killall -HUP some_process_name
- name: btmp
path: /var/log/btmp
missingok: true
frequency: monthly
create: true
create_mode: "0660"
create_user: root
create_group: utmp
dateext: true
dateformat: "-%Y-%m-%d"
keep: 1
- name: wtmp
path: /var/log/wtmp
missingok: true
frequency: monthly
create: true
create_mode: "0664"
create_user: root
create_group: utmp
minsize: 1M
maxsize: 128M
dateext: true
dateformat: "-%Y%m%d"
keep: 1
- name: dnf
path: /var/log/hawkey.log
missingok: true
notifempty: true
keep: 4
frequency: weekly
create: true
- name: example-sharedscripts
path: "/var/log/example-sharedscripts/*.log"
sharedscripts: true
- name: example-dateyesterday
state: present
path: "/var/log/example-dateyesterday/*.log"
dateyesterday: true
- name: example-absent
state: absent
# 负值在某些发行版上有效: `error: example-negative:10 bad rotation count '-1'`
# - name: example-negative
# path: "/var/log/example-keep-negative/*.log"
# keep: -1
roles:
- role: buluma.logrotate
机器需要准备。在 CI 中,这可以通过 molecule/default/prepare.yml
完成:
---
- name: Prepare
hosts: all
become: true
gather_facts: false
roles:
- role: buluma.bootstrap
- role: buluma.cron
post_tasks:
- name: 创建日志目录
ansible.builtin.file:
path: "{{ item }}"
state: directory
mode: "0755"
loop:
- /var/log/example
- /var/log/example-frequency
- /var/log/example-keep
- /var/log/example-compress
- /var/log/example-copylog
- /var/log/example-copytruncate
- /var/log/example-delaycompress
- /var/log/example-script
- /var/log/example-sharedscripts
- /var/log/example-dateyesterday
- name: 创建日志文件
ansible.builtin.copy:
dest: "{{ item }}"
content: "example"
mode: "0644"
loop:
- /var/log/example/app.log
- /var/log/example-frequency/app.log
- /var/log/example-keep/app.log
- /var/log/example-compress/app.log
- /var/log/example-copylog/app.log
- /var/log/example-copytruncate/app.log
- /var/log/example-delaycompress/app.log
- /var/log/example-script/app.log
- /var/log/example-sharedscripts/app.log
- /var/log/example-dateyesterday/app.log
- /var/log/btmp
- /var/log/wtmp
- /var/log/hawkey.log
更多详细说明和示例请参见 如何使用这些角色的完整说明。
角色变量
变量的默认值在 defaults/main.yml
中设置:
---
# logrotate 的默认文件
# 日志轮换的频率,可以是 daily(每日)、weekly(每周)或 monthly(每月)。
logrotate_frequency: weekly
# 保留多少个文件。
logrotate_keep: 4
# 是否应压缩轮换的日志文件?
logrotate_compress: true
# 在日志文件名上使用日期扩展
logrotate_dateext: false
# 轮换日志文件的用户/组(如果找到则由特定操作系统的变量加载,也可以手动设置)
logrotate_user: "{{ _logrotate_user[ansible_distribution] | default(_logrotate_user['default']) }}"
logrotate_group: "{{ _logrotate_group[ansible_distribution] | default(_logrotate_group['default']) }}"
# 设置服务的状态
logrotate_service_state: "started"
logrotate_service_enabled: true
要求
- 在 requirements.txt 中列出的 pip 包。
已使用角色的状态
以下角色用于准备系统。您可以以其他方式准备系统。
需求 | GitHub | 版本 |
---|---|---|
buluma.bootstrap | ||
buluma.cron | ||
buluma.epel |
上下文
此角色是许多兼容角色的一部分。有关更多信息,请查看 这些角色的文档。
这是相关角色的概览:
兼容性
该角色已在以下 容器镜像 中进行了测试:
容器 | 标签 |
---|---|
Alpine | all |
EL | 8, 9 |
Debian | all |
Fedora | all |
opensuse | all |
Ubuntu | all |
Kali | all |
所需的最小 Ansible 版本为 2.12,已针对:
- 之前的版本。
- 当前版本。
- 开发版本。
如果您发现问题,请在 GitHub 上提交。