### Example Playbook for Nginx Log Rotation (YAML) Source: https://github.com/nickhammond/ansible-logrotate/blob/master/README.md An example Ansible playbook demonstrating the configuration of logrotate for Nginx logs. It includes two script configurations: one with standard rotation options and another that incorporates a custom postrotate script. ```yaml - 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 ``` -------------------------------- ### Configure Multi-Application Logrotate Setup with Ansible Source: https://context7.com/nickhammond/ansible-logrotate/llms.txt Manages log rotation for multiple applications like Rails, Apache, and Syslog within a single Ansible playbook. Each configuration in `logrotate_scripts` operates independently with its own schedule and policies. ```yaml - hosts: production_servers become: true vars: logrotate_scripts: - name: rails-app path: "/srv/rails/current/log/*.log" options: - daily - rotate 30 - size 25M - missingok - compress - delaycompress - copytruncate - name: apache paths: - "/var/log/apache2/access.log" - "/var/log/apache2/error.log" options: - weekly - rotate 52 - compress - delaycompress - notifempty - sharedscripts scripts: postrotate: "/usr/sbin/apache2ctl graceful" - name: syslog path: /var/log/syslog options: - daily - rotate 7 - compress - missingok - notifempty - create 0640 syslog adm roles: - ansible-logrotate ``` -------------------------------- ### Logrotate with Post-Rotation Scripts (Ansible) Source: https://context7.com/nickhammond/ansible-logrotate/llms.txt Enables execution of commands after log rotation using the `scripts` parameter. This example demonstrates a post-rotate script to reload Nginx and another to send a notification via curl after log rotation. ```yaml - hosts: all become: true vars: logrotate_scripts: - name: nginx-reload path: /var/log/nginx/*.log options: - daily - rotate 7 - compress - delaycompress - missingok - notifempty - sharedscripts scripts: postrotate: "/usr/sbin/nginx -s reload" - name: application-notify path: /var/log/myapp/app.log options: - size 50M - rotate 5 - compress scripts: postrotate: "curl -X POST https://monitoring.example.com/log-rotated" roles: - ansible-logrotate ``` -------------------------------- ### Configure Single Path Logrotate (Ansible) Source: https://context7.com/nickhammond/ansible-logrotate/llms.txt Sets up logrotate for a single log file or glob pattern using the `path` parameter. This example shows how to configure logrotate for Nginx access logs with specific rotation policies and file permissions. ```yaml - hosts: webservers become: true vars: logrotate_scripts: - name: nginx-access path: /var/log/nginx/access.log options: - daily - rotate 30 - size 100M - compress - delaycompress - missingok - notifempty - create 0640 www-data adm roles: - ansible-logrotate ``` -------------------------------- ### Local Testing with Vagrant (Shell) Source: https://github.com/nickhammond/ansible-logrotate/blob/master/README.md Command to initiate local testing of the Ansible logrotate role using Vagrant. This command navigates to the 'tests' directory and provisions a virtual machine with the role configured. ```shell cd tests vagrant up --provision ``` -------------------------------- ### Configure Multiple Paths Logrotate (Ansible) Source: https://context7.com/nickhammond/ansible-logrotate/llms.txt Configures logrotate for multiple specific log files using the `paths` parameter with a list. This is useful when several files require identical rotation settings, avoiding configuration duplication. ```yaml - hosts: appservers become: true vars: logrotate_scripts: - name: application-suite paths: - "/var/log/app/frontend.log" - "/var/log/app/backend.log" - "/var/log/app/worker.log" options: - weekly - rotate 52 - compress - missingok - notifempty roles: - ansible-logrotate ``` -------------------------------- ### Test Logrotate Configuration Syntax with Ansible Source: https://context7.com/nickhammond/ansible-logrotate/llms.txt Verifies logrotate configurations without performing actual rotations using Ansible. It utilizes logrotate's debug mode to validate syntax and behavior, suitable for CI/CD pipelines. ```yaml # tests/test.yml - hosts: all become: true vars: logrotate_scripts: - name: test-config path: /var/log/test.log options: - daily - rotate 7 - compress roles: - ansible-logrotate tasks: - name: Verify logrotate config check passes shell: logrotate -d "{{ logrotate_conf_dir }}{{ item.name }}" with_items: "{{ logrotate_scripts }}" register: logrotate_tests failed_when: "'error' in logrotate_tests.stderr" # Manual testing with debug mode # ansible-playbook playbook.yml # ssh target-host # logrotate -d /etc/logrotate.d/test-config ``` -------------------------------- ### Configure Advanced PostgreSQL and Audit Log Rotation with Ansible Source: https://context7.com/nickhammond/ansible-logrotate/llms.txt Sets up advanced log rotation policies for PostgreSQL and audit logs using the ansible-logrotate role. It includes daily rotation for PostgreSQL logs with size limits and weekly rotation for audit logs with date extensions. ```yaml - hosts: database_servers become: true vars: logrotate_scripts: - name: postgresql path: /var/log/postgresql/postgresql-*.log options: - daily - rotate 90 - size 500M - compress - delaycompress - missingok - notifempty - create 0640 postgres postgres - sharedscripts scripts: postrotate: "systemctl reload postgresql" - name: audit-logs path: /var/log/audit/audit.log options: - weekly - rotate 156 - minsize 10M - compress - dateext - dateformat -%Y%m%d-%s - notifempty - create 0600 root root roles: - ansible-logrotate ``` -------------------------------- ### Configure Logrotate Default Variables (Ansible) Source: https://context7.com/nickhammond/ansible-logrotate/llms.txt Defines default logrotate configuration directory and a list of logrotate scripts. The `logrotate_scripts` variable accepts a list of dictionaries, where each dictionary defines a logrotate configuration including name, path, and options. ```yaml # defaults/main.yml or playbook vars logrotate_conf_dir: "/etc/logrotate.d/" logrotate_scripts: - name: application-logs path: "/var/log/myapp/*.log" options: - daily - rotate 14 - compress - delaycompress - missingok - notifempty - copytruncate ``` -------------------------------- ### Configure Logrotate Scripts with Multiple Paths (YAML) Source: https://github.com/nickhammond/ansible-logrotate/blob/master/README.md Defines a logrotate script named 'rails' that targets multiple log files using a list of paths. This configuration is useful when logs are scattered or have distinct names within a directory, while still applying the same rotation policies. ```yaml logrotate_scripts: - name: rails paths: - "/srv/current/scare.log" - "/srv/current/hide.log" options: - weekly - size 25M - missingok - compress - delaycompress - copytruncate ``` -------------------------------- ### Configure Logrotate Scripts with Options (YAML) Source: https://github.com/nickhammond/ansible-logrotate/blob/master/README.md Defines a logrotate script named 'rails' with a single log path and various rotation options. This snippet demonstrates how to specify weekly rotation, size limits, compression, and error handling for log files. ```yaml logrotate_scripts: - name: rails path: "/srv/current/log/*.log" options: - weekly - size 25M - missingok - compress - delaycompress - copytruncate ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.