added managing of logrotate.conf (#6)
* added managing of logrotate.conf for possibility enable globally compress or change keep period
* add missed file
* add config section to readme
* renamed variable for better representation, old name was a bit confusing
diff --git a/README.rst b/README.rst
index ad9cdbb..84984ce 100644
--- a/README.rst
+++ b/README.rst
@@ -52,6 +52,19 @@
- compress
- postrotate: "reload rsyslog >/dev/null 2>&1 || true"
+Change parameters in main logrotate.conf file:
+
+.. code-block:: yaml
+
+ logrotate:
+ server:
+ enabled: true
+ global_conf:
+ compress: true
+ rotate: daily
+ keep_rotate: 6
+ dateext: true
+
Cross-formula relationship
==========================
diff --git a/logrotate/files/logrotate.conf b/logrotate/files/logrotate.conf
new file mode 100644
index 0000000..023cc70
--- /dev/null
+++ b/logrotate/files/logrotate.conf
@@ -0,0 +1,53 @@
+{%- from "logrotate/map.jinja" import server with context -%}
+# see "man logrotate" for details
+# rotate log files weekly
+{{ server.global_conf.rotate }}
+
+{%- if grains['os_family'] == "Debian" %}
+
+# use the syslog group by default, since this is the owning group
+# of /var/log/syslog.
+su root syslog
+{%- endif %}
+
+# keep 4 weeks worth of backlogs
+rotate {{ server.global_conf.keep_rotate }}
+
+# create new (empty) log files after rotating old ones
+create
+
+{%- if server.global_conf.dateext %}
+
+# use date as a suffix of the rotated file
+dateext
+{%- endif %}
+
+# uncomment this if you want your log files compressed
+{%- if server.global_conf.compress %}
+compress
+{%- else %}
+#compress
+{%- endif %}
+
+# packages drop log rotation information into this directory
+include /etc/logrotate.d
+
+# no packages own wtmp, or btmp -- we'll rotate them here
+/var/log/wtmp {
+ missingok
+ monthly
+ create 0664 root utmp
+ rotate 1
+}
+
+/var/log/btmp {
+ missingok
+ monthly
+ create 0660 root utmp
+ rotate 1
+}
+
+# system-specific logs may be configured here
+{#-
+vim: syntax=jinja
+-#}
diff --git a/logrotate/map.jinja b/logrotate/map.jinja
index 473917e..dfedd16 100644
--- a/logrotate/map.jinja
+++ b/logrotate/map.jinja
@@ -4,6 +4,23 @@
- logrotate
config_dir: /etc/logrotate.d
config: /etc/logrotate.conf
+ global_conf:
+ compress: false
+ rotate: weekly
+ keep_rotate: 4
+ dateext: false
+
+RedHat:
+ pkgs:
+ - logrotate
+ config_dir: /etc/logrotate.d
+ config: /etc/logrotate.conf
+ global_conf:
+ compress: true
+ rotate: weekly
+ keep_rotate: 4
+ dateext: true
+
{%- endload %}
{%- set server = salt['grains.filter_by'](server_defaults, merge=salt['pillar.get']('logrotate:server')) %}
diff --git a/logrotate/server.sls b/logrotate/server.sls
index 18dd045..b45df64 100644
--- a/logrotate/server.sls
+++ b/logrotate/server.sls
@@ -31,4 +31,12 @@
{%- endfor %}
+logrotate_conf:
+ file.managed:
+ - name: {{ server.config }}
+ - source: salt://logrotate/files/logrotate.conf
+ - template: jinja
+ - require:
+ - pkg: logrotate_packages
+
{%- endif %}