Lineinfile creates duplicates entries when running playbook multiple times

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

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.