如何使用ansible设置logrotation?
我的剧本里有这样的内容:如何使用ansible设置logrotation?,ansible,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
---
- 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
错误!加载YAML时出现语法错误。
该错误似乎出现在“/apps/cman/scripts/ansible/playbooks/syslog-ng_server.yaml”中:第11行第13列,但可能发生
根据确切的语法问题,在文件中的其他位置。
令人不快的一行似乎是:
logrotate:name=man_vc.log path=“/var/log/man_vc.log”
args:
^这里
异常类型:
例外:在此上下文中不允许映射值
在“”中,第11行第13列
您是否尝试了“选项”而不是“参数”?见下文
这是我的建议。那对我不起作用。看起来我必须安装logrotate ansible软件包。我没有这样做,而是抓取了
/etc/logrotate.d/syslog
文件,添加了我需要的行,并将其转换为ansible j2模板。
logrotate_scripts:
- name: nginx-options
path: /var/log/nginx/options.log
options:
- daily
- weekly
- size 25M
- rotate 7
- missingok
- compress
- delaycompress
- copytruncate