I have the following in a playbook to uncomment a line. The first time I run it everything works fine. If I run it again it inserts a “Banner /etc/issue.net” at the EOF. Is there a better way to do this?
- name: uncomment a line
lineinfile: backup=yes state=present dest=/etc/ssh/sshd_config regexp=‘^#Banner’ line=‘Banner /etc/issue.net’
I understand the functionality of lineinfile a bit better now and solved this with…
- name: uncomment a line
lineinfile: backup=yes state=present dest=/etc/ssh/sshd_config regexp=‘^#?Banner’ line=‘Banner /etc/issue.net’
Also, it appears I can utilize the original regexp with a backrefs=yes to achieve the desired result as well.
Either way I am moving towards using a template.