I'm trying to modify a logrotate file on multiple servers. When the line "noolddir" is not present in a block in the file, the line should be added. I wrote this playbook:
- name: Update logrotate files on servers
hosts: all
tasks:
- name: change myapplication
ansible.builtin.replace:
path: /etc/logrotate.d/myapplication
regexp: '(?:noolddir\n)?(rotate 30)$'
replace: ' noolddir\n\1'
but, it is not working.
The logrotate file I need to edit looks like this:
/opt/appvendor/log//myapplication_*.log {
daily
rotate 30
compress
missingok
notifempty
su root appvendor
dateext
postrotate
/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
endscript
}
/opt/otherapplication/instances/*/*/otherapplication/logs/*.log
/opt/otherapplication/instances/*/somefolder/*/*/logs/*.log {
daily
noolddir
rotate 30
compress
missingok
notifempty
copytruncate
su root appvendor
}
The result should be:
/opt/appvendor/log//myapplication_*.log {
daily
noolddir
rotate 30
compress
missingok
notifempty
su root appvendor
dateext
postrotate
/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
endscript
}
/opt/otherapplication/instances/*/*/otherapplication/logs/*.log
/opt/otherapplication/instances/*/somefolder/*/*/logs/*.log {
daily
noolddir
rotate 30
compress
missingok
notifempty
copytruncate
su root appvendor
}
However when I run the playbook, nothing is changed.
Any suggestions?