I am having a requirement where I need to replace/comment a line from rsyslog.conf file
I am unable to correctly state the regexp. Please Help.
INADEQUATE INFORMATION AVAILABLE ONLINE.
I have been testing the following script which is failing:
YAML using “lineinfile”
(attachments)
Your regex has a closing parenthesis but no starting one.
Also, the wildcard character needs to be escaped.
If your goal is to comment out whatever you matched first, then it
makes sense to use backrefs in the substituted line.
You should also use the $ to match the end of the string.
In this specific case it won't be a problem (i.e. there are probably
no instances like *.*@10.1.0.1000), but suppose you wanted to match:
*.*@10.1.0.10
then without the $ this would also match *.*@10.1.0.100, *.*@10.1.0.104, etc
This should work for you:
- name: Comment out *.*@10.1.0.100 line in /etc/rsyslog.conf
lineinfile:
path: /etc/rsyslog.conf
regexp: '^(\*\.\*@10\.1\.0\.100)'
line: '#\1'
backrefs: yes
BTW that screen capture is huge and makes it hard to read the
message... you might want to just copy/paste the text next time...
Dick