If you get duplicate lines, it is because the regexp doesn’t match any lines. To allow it to be more flexible, use wildcards… yet not too much that it finds multiple entries (as always with regex).
It should be noted that I tested with 0.7. However, I can’t see any difference in the code between current devel and 0.7 that would suggest that things have changed.
if you have for example :
127.0.0.1 localhost project1
and you want to add “newproject” it basically replace the line with :
127.0.0.1 localhost newproject
so it doesn’t add to the end of the line.
It sounds like you missed project1 in your line=. For above try:
regexp=“127.0.0.1.*” line=“127.0.0.1\tlocalhost\tproject1\tnewproject”
Michael:
In regards to templates, I think it depends a bit on how you decide to handle system files and who the audience is:
a) by having a central, version controlled repository of the actual files and copy them out.
b) assembling fragments of files to build them up.
c) using regex to find/add/modify entries in the file.
Both (a) and (b) would require you to verify each file every time you apply patches to the system that affects the specific file, while (c) would work regardless of changes in the files, but makes it more complicated to handle/update for people who aren’t familiar with ansible.
Because of the latter and because it’s easier to see who changed what in an easier way, we’re leaning towards going with option (a).
Absolutely. This is why I resisted including lineinfile in the first
place. While it has uses, it should be a last resort, and only when
you need to have the user be able to edit the file and also centrally
manage it. This is ALWAYS going to be dangerous (not just in
Ansible, in any tool) as the user can break the file and you won't be
able to fix it because you aren't representing the entire
state of the file.