我正在使用lineinfile
在系统日志文件中插入行。这是我的系统日志:
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
missingok
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
我想compress
在delaycompress
. missingok
这是我的代码:
- name: "Adding compress line in /etc/logrotate.d/syslog"
lineinfile:
path: /etc/logrotate.d/syslog
insertafter: "^missingok"
line: " compress"
firstmatch: yes
state: present
- name: "Adding delaycompress line in /etc/logrotate.d/syslog"
lineinfile:
path: /etc/logrotate.d/syslog
insertbefore: "^sharedscripts"
line: " delaycompress"
firstmatch: yes
state: present
但是它在文件的末尾添加了两者(在最后几行)。
注意:我在compress
and之前添加了 4 个空格delaycompress
。