# Lineinfile creates duplicates entries when running playbook multiple times

**URL:** <https://forum.ansible.com/t/lineinfile-creates-duplicates-entries-when-running-playbook-multiple-times/34822>\
**Category:** Ansible Developer\
**Created:** [March 22, 2021, 4:07am UTC](https://forum.ansible.com/t/lineinfile-creates-duplicates-entries-when-running-playbook-multiple-times/34822 "2021-03-22T04:07:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![janaki\_raman](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@janaki\_raman](https://forum.ansible.com/u/janaki_raman)\
**Post date:** [March 22, 2021, 4:07am UTC](https://forum.ansible.com/t/lineinfile-creates-duplicates-entries-when-running-playbook-multiple-times/34822/1 "2021-03-22T04:07:08Z")

</div>

Hi All,

lineinfile duplicates the entry… I am trying to append a line based on the regex… but if i run the playbook again, it keeps adding the lines…

- name: “Updating /etc/default/grub with security parameters”

lineinfile:  
path: /etc/default/grub\_new  
backrefs: yes  
state: present  
regexp: ‘(^GRUB\_CMDLINE\_LINUX\_DEFAULT=.\*)$’  
line: ‘\1\nnuma\_balancing=disable’

I tried the same with replace module, still got the same result… Not sure what am i missing here

---

<div class="post-metadata">

**Author:** ![vikinggeek](https://avatars.discourse-cdn.com/v4/letter/v/e19b73/32.png) [@vikinggeek](https://forum.ansible.com/u/vikinggeek)\
**Post date:** [March 22, 2021, 4:43am UTC](https://forum.ansible.com/t/lineinfile-creates-duplicates-entries-when-running-playbook-multiple-times/34822/2 "2021-03-22T04:43:02Z")

</div>

Try taking our the \n. I have just had a similar problem with blockinfile. Last I checked, there is an open bug for the issue.
