Skip to content

Commit 767d1a6

Browse files
committed
Introduce logrotate_create (global) variable. Fixes #26.
1 parent ed1dadb commit 767d1a6

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This example is taken from [`molecule/default/converge.yml`](https://github.com/
2121
logrotate_frequency: daily
2222
logrotate_keep: 7
2323
logrotate_compress: true
24+
logrotate_create: false
2425
logrotate_entries:
2526
- name: example
2627
path: "/var/log/example/*.log"
@@ -180,6 +181,9 @@ logrotate_compress: true
180181
# Use date extension on log file names
181182
logrotate_dateext: false
182183
184+
# Enable the global `create` directive in /etc/logrotate.conf.
185+
logrotate_create: true
186+
183187
# User/Group for rotated log files (Loaded by OS-Specific vars if found, or and can be set manually)
184188
logrotate_user: "{{ _logrotate_user[ansible_distribution] | default(_logrotate_user['default']) }}"
185189
logrotate_group: "{{ _logrotate_group[ansible_distribution] | default(_logrotate_group['default']) }}"

defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ logrotate_compress: true
1313
# Use date extension on log file names
1414
logrotate_dateext: false
1515

16+
# Enable the global `create` directive in /etc/logrotate.conf.
17+
logrotate_create: true
18+
1619
# User/Group for rotated log files (Loaded by OS-Specific vars if found, or and can be set manually)
1720
logrotate_user: "{{ _logrotate_user[ansible_distribution] | default(_logrotate_user['default']) }}"
1821
logrotate_group: "{{ _logrotate_group[ansible_distribution] | default(_logrotate_group['default']) }}"

meta/argument_specs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ argument_specs:
2828
type: bool
2929
description: "Use date extension on log file names"
3030
default: false
31+
logrotate_create:
32+
type: bool
33+
description: "Enable the global `create` directive in /etc/logrotate.conf."
34+
default: true
3135
logrotate_user:
3236
type: str
3337
description: "User for rotated log files. Automatically determined, but overridable."

molecule/default/converge.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
logrotate_frequency: daily
99
logrotate_keep: 7
1010
logrotate_compress: true
11+
logrotate_create: false
1112
logrotate_entries:
1213
- name: example
1314
path: "/var/log/example/*.log"

tasks/assert.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
- logrotate_dateext is boolean
2929
quiet: true
3030

31+
- name: assert | Test logrotate_create
32+
ansible.builtin.assert:
33+
that:
34+
- logrotate_create is defined
35+
- logrotate_create is boolean
36+
quiet: true
37+
3138
- name: assert | Test logrotate_user
3239
ansible.builtin.assert:
3340
that:

templates/logrotate.conf.j2

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ su {{ logrotate_user }} {{ logrotate_group }}
1212
rotate {{ logrotate_keep }}
1313

1414
# create new (empty) log files after rotating old ones
15+
{% if logrotate_create %}
1516
create
17+
{% else %}
18+
#create
19+
{% endif %}
1620

17-
# add dateext
1821
{% if logrotate_dateext %}
1922
dateext
2023
{% else %}
2124
#dateext
2225
{% endif %}
2326

24-
# uncomment this if you want your log files compressed
2527
{% if logrotate_compress %}
2628
compress
2729
{% else %}

0 commit comments

Comments
 (0)