I am using lineinfile
to insert line in syslog file. Here is my syslog:
/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
}
I would like to add compress
and delaycompress
after missingok
. Here is my code:
- 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
But its adding both at the end of the file(at last lines).
Note: I have added 4 spaces before compress
and delaycompress
.