如何使用ansible设置logrotation?

时间:2019-01-30 23:16:07

标签: ansible

我的剧本中有这个

---
- name: Set Up syslog-ng Server
  hosts: localhost
  tasks:
    - name: Log Rotation for log
      logrotate: name=man_vc.log path="/var/log/man_vc.log"
        args:
          options:
            - daily
            - size 25M
            - rotate 8
            - missingok
            - compress
            - delaycompress
            - copytruncate

当我运行它时,出现此错误:

ERROR! Syntax Error while loading YAML.


The error appears to have been in '/apps/cman/scripts/ansible/playbooks/syslog-ng_server.yaml': line 11, column 13, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

      logrotate: name=man_vc.log path="/var/log/man_vc.log"
        args:
            ^ here

exception type: <class 'yaml.scanner.ScannerError'>
exception: mapping values are not allowed in this context
  in "<unicode string>", line 11, column 13

1 个答案:

答案 0 :(得分:1)

您尝试使用“选项”而不是“参数”吗?请参见下面的https://github.com/nickhammond/ansible-logrotate

logrotate_scripts:
  - name: nginx-options
    path: /var/log/nginx/options.log
    options:
      - daily
      - weekly
      - size 25M
      - rotate 7
      - missingok
      - compress
      - delaycompress
      - copytruncate