Skip to content

darkwizard242/ansible-role-logrotate

Repository files navigation

build-test release Ansible Role Maintainability Rating Reliability Rating Security Rating GitHub tag (latest SemVer) GitHub repo size

Ansible Role: logrotate

Role to install (by default) logrotate package or uninstall (if passed as var) as well as configure for any number of logrotate configurations on Debian based and EL based systems.

Requirements

None.

Role Variables

Available variables are listed below (located in defaults/main.yml):

Variables list:

logrotate_app: logrotate
logrotate_desired_state: present
logrotate_config_dir: /etc/logrotate.d
logrotate_configs: []
logrotate_template: conf.j2

Variables table:

Variable Description
logrotate_app Defines the app to install i.e. logrotate
logrotate_desired_state Defined to dynamically chose whether to install (i.e. either present or latest) or uninstall (i.e. absent) the package. Defaults to present.
logrotate_config_dir Directory to place logrotate configuration into i.e. /etc/logrotate.d
logrotate_configs Pass desired logrotate configurations. Playbook example provided.
logrotate_template Template used as source.

Dependencies

None

Example Playbook

For default behaviour of role (i.e. installation of logrotate package) in ansible playbooks.

- hosts: servers
  roles:
    - darkwizard242.logrotate

For customizing behavior of role (i.e. custom config of logrotate ) in ansible playbooks.

- hosts: servers
  roles:
    - darkwizard242.logrotate
  vars:
    logrotate_configs:
      - name: ansible
        path: /var/log/ansible.log
        options:
          - weekly
          - create 0644 root root
          - size 10M
          - rotate 5
          - dateext
          - dateformat -%Y_%m_%d
          - notifempty
          - missingok
          - compress
          - delaycompress
          - copytruncate

For customizing behavior of role (i.e. custom config and postrotate scripts of logrotate ) in ansible playbooks.

- hosts: servers
  roles:
    - darkwizard242.logrotate
  vars:
    logrotate_configs:
      - name: ansible
        path: /var/log/ansible.log
        options:
          - weekly
          - create 0644 root root
          - size 10M
          - rotate 5
          - dateext
          - dateformat -%Y_%m_%d
          - notifempty
          - missingok
          - compress
          - delaycompress
          - copytruncate

      - name: ansible-script
        path: /var/log/ansible.log
        options:
          - weekly
          - create 0644 root root
          - size 10M
          - rotate 5
          - dateext
          - dateformat -%Y_%m_%d
          - notifempty
          - missingok
          - compress
          - delaycompress
          - copytruncate
        scripts:
          postrotate: 'echo "Ansible log has been rotated" > ~/rotation.txt'

License

MIT

Author Information

This role was created by Ali Muhammad.