# lineinfile unexpected behavior

**URL:** <https://forum.ansible.com/t/lineinfile-unexpected-behavior/21144>\
**Category:** Ansible Project\
**Created:** [April 12, 2016, 8:03pm UTC](https://forum.ansible.com/t/lineinfile-unexpected-behavior/21144 "2016-04-12T20:03:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam.frederick](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@adam.frederick](https://forum.ansible.com/u/adam.frederick)\
**Post date:** [April 12, 2016, 8:03pm UTC](https://forum.ansible.com/t/lineinfile-unexpected-behavior/21144/1 "2016-04-12T20:03:51Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![adam.frederick](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@adam.frederick](https://forum.ansible.com/u/adam.frederick)\
**Post date:** [April 13, 2016, 12:12am UTC](https://forum.ansible.com/t/lineinfile-unexpected-behavior/21144/2 "2016-04-13T00:12:53Z")

</div>

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.
