I'm trying to replicate the following sed snippet in ansible's lineinfile module.
sed -i '/# The named pipe \/dev\/xconsole/,$d' /etc/rsyslog.conf
I know that I can template the file or brute force match the lines but I'd like to learn how to do the sed trick of matching to end of file with ansible. I am also aware the matching blindly to the end of the file isn't great practice either.
This was lifted from this blog post: https://blog.dantup.com/2016/04/removing-rsyslog-spam-on-raspberry-pi-raspbian-jessie/
The aim is to fix this error in rsyslog:
raspberrypi rsyslogd-2007: action 'action 17' suspended, next retry is Sat Apr 2 01:24:21 2016 [try http://www.rsyslog.com/e/2007 ]
This error is caused by section at the end the config file /etc/rsyslog.conf
# The named pipe /dev/xconsole is for the `xconsole' utility. To use it,
# you must invoke `xconsole' with the `-file' option:
#
# $ xconsole -file /dev/xconsole [...]
#
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
# busy site..
#
daemon.*;mail.*;\
news.err;\
*.=debug;*.=info;\
*.=notice;*.=warn |/dev/xconsole
Your
sed
command truncates a file, whereas thelineinfile
module "will search a file for a line, and ensure that it is present or absent. This is primarily useful when you want to change a single line in a file only" (http://docs.ansible.com/ansible/lineinfile_module.html).copy
ortemplate
still sounds like the best alternative here.If you want to play around with
lineinfile
, your ssh server configuration is usually a good start.