From 2e4c02f93e554b6b113c8885a7e30bc9f433e411 Mon Sep 17 00:00:00 2001 From: Piotr Kweclich Date: Fri, 22 Mar 2013 11:43:44 +0100 Subject: [PATCH] disabled appending file with garbage when regexp didn't match. --- library/lineinfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/lineinfile b/library/lineinfile index b92c0112b3..2be9d83bce 100644 --- a/library/lineinfile +++ b/library/lineinfile @@ -184,10 +184,14 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu # Add it to the end of the file if requested or # if insertafter=/insertbefore didn't match anything # (so default behaviour is to add at the end) - elif insertafter == 'EOF' or index[1] == -1: + elif insertafter == 'EOF': lines.append(line + os.linesep) msg = 'line added' changed = True + # Do nothing if regexp didn't match + elif index[1] == -1: + msg = '' + changed = False # insertafter/insertbefore= matched else: lines.insert(index[1], line + os.linesep)