Line cookbook add_to_list same entry every time it runs

I am using the line cookbook and i want to add these 2 lines:

  •   soft    nofile  2048
    
  •   hard    nofile  3072
    

between 2 lines in /etc/security/limits.conf so i am using:
add_to_list “add entry to a list” do
path “/etc/security/limits.conf"
pattern “#@student - maxlogins 4"
delim [”
”]
entry "* soft nofile 2048

  •   hard    nofile  3072"
    

end
but every time it runs its duplicating the lines, how can i make sure it adds it only once?
Thanks in advance.

First of all: I’d suggest managing the whole file. Trying to manage files line by line misses the point of idempotence which is one of chef’s real strengths.
Along that line, I’d recommend the limits cookbook: https://supermarket.chef.io/cookbooks/limits

It works well.

–Jp Robinson

1 Like

I am managing the whole file now with cookbook_file Thank you for your quick response.