Document lineinfile regexp gotcha

You typically want the lineinfile module to operate in an indempotent way, similar to using "sed -i", so your regexp needs to match the line to edit both before and after the edit, otherwise on a second run the regexp will no longer match the original text line and you will end up with a second copy of the replacement line at the top/bottom of the file.
pull/47912/head
jfpanisset 6 years ago committed by GitHub
parent 8e561d1eb4
commit e4a2d2423a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -48,6 +48,8 @@ options:
- If the regular expression is not matched, the line will be - If the regular expression is not matched, the line will be
added to the file in keeping with`insertbefore` or `insertafter` added to the file in keeping with`insertbefore` or `insertafter`
settings. settings.
- When modifying a line the regexp should typically match both the initial state of
the line as well as its state after replacement by C(line) to ensure idempotence.
- Uses Python regular expressions. See U(http://docs.python.org/2/library/re.html). - Uses Python regular expressions. See U(http://docs.python.org/2/library/re.html).
version_added: '1.7' version_added: '1.7'
state: state:

Loading…
Cancel
Save