On 16 August 2018 at 08:30, Kanhaiya Ashtekar
<[email protected]> wrote:
>
> 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"
> ---
> - name: Comment out *.*@10.1.0.100 line in /etc/rsyslog.conf
> lineinfile:
> path: /etc/rsyslog.conf
> regexp: '^*\.*@10\.1\.0\.100)'
> line: '# *.* @10.1.0.100'
>
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
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAL8fbwN%3D5TowJYYtfW7Y5sAhUoxE8E17AS_79X8aCJZTqaDmzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.