ansible-logrotate Role

repository·master·Indexed 42 days ago

https://github.com/nickhammond/ansible-logrotate

An Ansible role that installs logrotate and allows users to define custom log rotation configurations via the logrotate_scripts variable, supporting custom directives, multiple log paths, and postrotate/prerotate scripts.

Tokens
672
Snippets
3
Records
3
Agent score
3%

What's inside ansible-logrotate

  1. Configure logrotate scripts via logrotate_scripts

    master

    The ansible-logrotate role uses the logrotate_scripts variable to define log rotation configurations. You can provide a list of scripts, where each script defines the filename in /etc/logrotate.d/ and the rotation directives.

    Supported keys per script entry:

    • name: The name of the script file that will be created in /etc/logrotate.d/.
    • path: A single string path to the log file(s) for rotation.
    • paths: A list of strings representing multiple paths for rotation.
    • options: A list of logrotate directives (e.g., weekly, compress, size 25M). Refer to the logrotate man page for valid directive values.
    • scripts: A dictionary of logrotate scripts (e.g., postrotate, prerotate).
    logrotate_scripts:
      - name: rails
        path: "/srv/current/log/*.log"
        options:
          - weekly
          - size 25M
          - missingok
          - compress
          - delaycompress
          - copytruncate
  2. Use multiple paths and postrotate scripts in logrotate

    master

    You can configure multiple log paths for a single script entry using the paths key, and execute commands after rotation using the scripts dictionary.

    Example of configuring Nginx logs with a postrotate command:

    - hosts: all
      vars:
        logrotate_scripts:
          - name: nginx-options
            path: /var/log/nginx/options.log
            options:
              - daily
              - weekly
              - size 25M
              - rotate 7
              - missingok
              - compress
              - delaycompress
              - copytruncate
    
          - name: nginx-scripts
            path: /var/log/nginx/scripts.log
            options:
              - daily
              - weekly
              - size 25M
            scripts:
              postrotate: "echo test"
    
      roles:
        - ansible-logrotate