As it is implemented now, the lineinfile module replaces only the last matching line in the given file. I guess the requirement for the line argument (“Must match the value given to regexp”) is there to guarantee idempotence if there are multiple matching lines in the file.
If I’m not mistaken, this requirement would not be necessary if replacing ALL matching lines in the file, would it?
Are there any other reasons for the limitation to the last match?
I’m asking because I just stumbled upon a use case for both the replacement of all matching lines and the replacement line not matching the original expression - we have a file with the same key=value line occuring multiple times where the key should be renamed…
On a sidenote: would it be difficult to have the replacement line include text “captured” from the original line (via regular expression capturing groups)? (I’m a bit reluctant to start developing Ansible modules myself at this time - but I hope this will change