|
|
@ -2,6 +2,7 @@
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
# (c) 2012, Daniel Hokka Zakrisson <daniel@hozac.com>
|
|
|
|
# (c) 2012, Daniel Hokka Zakrisson <daniel@hozac.com>
|
|
|
|
|
|
|
|
# (c) 2014, Ahti Kitsik <ak@ahtik.com>
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
#
|
|
|
@ -25,7 +26,7 @@ import tempfile
|
|
|
|
DOCUMENTATION = """
|
|
|
|
DOCUMENTATION = """
|
|
|
|
---
|
|
|
|
---
|
|
|
|
module: lineinfile
|
|
|
|
module: lineinfile
|
|
|
|
author: Daniel Hokka Zakrisson
|
|
|
|
author: Daniel Hokka Zakrisson, Ahti Kitsik
|
|
|
|
short_description: Ensure a particular line is in a file, or replace an
|
|
|
|
short_description: Ensure a particular line is in a file, or replace an
|
|
|
|
existing line using a back-referenced regular expression.
|
|
|
|
existing line using a back-referenced regular expression.
|
|
|
|
description:
|
|
|
|
description:
|
|
|
@ -251,6 +252,11 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create,
|
|
|
|
# if insertafter=/insertbefore didn't match anything
|
|
|
|
# if insertafter=/insertbefore didn't match anything
|
|
|
|
# (so default behaviour is to add at the end)
|
|
|
|
# (so default behaviour is to add at the end)
|
|
|
|
elif insertafter == 'EOF':
|
|
|
|
elif insertafter == 'EOF':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# If the file is not empty then ensure there's a newline before the added line
|
|
|
|
|
|
|
|
if len(lines)>0 and not (lines[-1].endswith('\n') or lines[-1].endswith('\r')):
|
|
|
|
|
|
|
|
lines.append(os.linesep)
|
|
|
|
|
|
|
|
|
|
|
|
lines.append(line + os.linesep)
|
|
|
|
lines.append(line + os.linesep)
|
|
|
|
msg = 'line added'
|
|
|
|
msg = 'line added'
|
|
|
|
changed = True
|
|
|
|
changed = True
|
|
|
|