首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ansible中rsyslog的Logrotate

Ansible中rsyslog的Logrotate
EN

Stack Overflow用户
提问于 2020-02-04 04:28:07
回答 1查看 644关注 0票数 0

我正在尝试使用Ansible更改rsyslog logrotate配置,但在运行任务时:

代码语言:javascript
复制
- name: Setup logrotate.d scripts
  template:
    src: logrotate.d.j2
    dest: "{{ logrotate_conf_dir }}{{ item.name }}"
  with_items: "{{ logrotate_scripts }}"
  when: logrotate_scripts is defined

它正在添加这种配置:

代码语言:javascript
复制
logrotate_scripts:
  - name: rsyslog
    path: 
        - "/var/log/syslog.log"
        - "/var/log/daemon.log"
        - "/var/log/kern.log"
        - "/var/log/mail.log"
        - "/var/log/user.log"
        - "/var/log/lpr.log"
        - "/var/log/auth.log"
        - "/var/log/cron.log"
        - "/var/log/debug"
        - "/var/log/messages"
    options:
      - daily
      - missingok
      - maxsize 100M
      - rotate 14
      - compress
      - compresscmd /bin/bzip2
      - compressoptions -4
      - compressext .bz2      
      - notifempty

我得到了错误的格式:

代码语言:javascript
复制
['/var/log/syslog.log', '/var/log/daemon.log', '/var/log/kern.log', '/var/log/mail.log', '/var/log/user.log', '/var/log/lpr.log', '/var/log/auth.log', '/var/log/cron.log', '/var/log/debug', '/var/log/messages'] {
  daily
  missingok
  maxsize 100M
  rotate 14
  compress
  compresscmd /bin/bzip2
  compressoptions -4
  compressext .bz2
  notifempty
  }

这是我用于所有logrotate脚本(nginx、php等)的模板,但对于rsyslog不能正常工作。

代码语言:javascript
复制
{{ item.path }} {
  {% if item.options is defined -%}
  {% for option in item.options -%}
  {{ option }}
  {% endfor -%}
  {% endif %}
  {%- if item.scripts is defined -%}
  {%- for name, script in item.scripts.iteritems() -%}
  {{ name }}
    {{ script }}
  endscript
  {% endfor -%}
  {% endif -%}
}

我应该如何正确地传递路径列表才能获得此效果?

代码语言:javascript
复制
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
{
  daily
  missingok
  maxsize 100M
  rotate 14
  compress
  compresscmd /bin/bzip2
  compressoptions -4
  compressext .bz2
  notifempty
  }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-04 05:56:23

您没有共享您的模板文件,但您可能需要在其中包含类似以下内容:

代码语言:javascript
复制
{% for path in item.path %}
path
{% endfor %}

获取您的路径列表。

除非您正在编辑多个文件,否则这样使用with_items似乎是错误的。使用lineinfile根据您的设置自定义标准logrotate配置可能会更好。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60046701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档