ansible-logrotate icon indicating copy to clipboard operation
ansible-logrotate copied to clipboard

support for multiple commands in a single script

Open oebeledrijfhout opened this issue 7 years ago • 2 comments

This commit makes it possible to have multiple actions in a script, eg. like this:

"/var/log/php-application/*.log" { daily rotate 0 create ifempty su apache apache lastaction /usr/bin/find -type f -mtime +7 -delete /usr/bin/find -type f -mtime +1 -exec gzip -q {} ; endscript }

oebeledrijfhout avatar Jul 21 '17 11:07 oebeledrijfhout

Please add a test for this demonstrating two different script types.

nickhammond avatar Feb 08 '18 11:02 nickhammond

This should already work using multi-line YAML entries, e.g. like this:

logrotate_scripts:
  - name: php-application
    paths:
      - "/var/log/php-application/*.log"
    options:
      - daily
      - rotate 0
      - create
      - ifempty
      - su apache apache      
    scripts:
      lastaction: |
        /usr/bin/find -type f -mtime +7 -delete
        /usr/bin/find -type f -mtime +1 -exec gzip -q {} ;

The | (pipe) symbol allows to have multiple lines joined by newline characters. This produces the desired results.

nwinkler avatar Sep 13 '18 09:09 nwinkler