Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
8a1741e2
Commit
8a1741e2
authored
Jun 12, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ahtik-fix-lineinfile-eof-newline' into devel
parents
db4a5c60
d90f0bdf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
2 deletions
+58
-2
library/files/lineinfile
+8
-2
test/integration/roles/test_lineinfile/files/testempty.txt
+0
-0
test/integration/roles/test_lineinfile/files/testnoeof.txt
+3
-0
test/integration/roles/test_lineinfile/tasks/main.yml
+47
-0
No files found.
library/files/lineinfile
View file @
8a1741e2
...
...
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# (c) 2012, Daniel Hokka Zakrisson <daniel@hozac.com>
# (c) 2014, Ahti Kitsik <ak@ahtik.com>
#
# This file is part of Ansible
#
...
...
@@ -25,7 +26,7 @@ import tempfile
DOCUMENTATION
=
"""
---
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
existing line using a back-referenced regular expression.
description:
...
...
@@ -110,7 +111,7 @@ options:
validate:
required: false
description:
- validation to run before copying into place. The command is passed
- validation to run before copying into place. The command is passed
securely so shell features like expansion and pipes won't work.
required: false
default: None
...
...
@@ -251,6 +252,11 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create,
# if insertafter=/insertbefore didn't match anything
# (so default behaviour is to add at the end)
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
)
msg
=
'line added'
changed
=
True
...
...
test/integration/roles/test_lineinfile/files/testempty.txt
0 → 100644
View file @
8a1741e2
test/integration/roles/test_lineinfile/files/testnoeof.txt
0 → 100644
View file @
8a1741e2
This is line 1
This is line 2
\ No newline at end of file
test/integration/roles/test_lineinfile/tasks/main.yml
View file @
8a1741e2
...
...
@@ -209,3 +209,50 @@
that
:
-
"
result.stat.md5
==
'fef1d487711facfd7aa2c87d788c19d9'"
# Test EOF in cases where file has no newline at EOF
-
name
:
testnoeof deploy the file for lineinfile
copy
:
src=testnoeof.txt dest={{output_dir}}/testnoeof.txt
register
:
result
-
name
:
testnoeof insert a line at the end of the file
lineinfile
:
dest={{output_dir}}/testnoeof.txt state=present line="New line at the end" insertafter="EOF"
register
:
result
-
name
:
testempty assert that the line was inserted at the end of the file
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'line
added'"
-
name
:
testnoeof stat the no newline EOF test after the insert at the end
stat
:
path={{output_dir}}/testnoeof.txt
register
:
result
-
name
:
testnoeof assert test md5 matches after the insert at the end
assert
:
that
:
-
"
result.stat.md5
==
'f75c9d51f45afd7295000e63ce655220'"
# Test EOF with empty file to make sure no unneccessary newline is added
-
name
:
testempty deploy the testempty file for lineinfile
copy
:
src=testempty.txt dest={{output_dir}}/testempty.txt
register
:
result
-
name
:
testempty insert a line at the end of the file
lineinfile
:
dest={{output_dir}}/testempty.txt state=present line="New line at the end" insertafter="EOF"
register
:
result
-
name
:
testempty assert that the line was inserted at the end of the file
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'line
added'"
-
name
:
testempty stat the test after the insert at the end
stat
:
path={{output_dir}}/testempty.txt
register
:
result
-
name
:
testempty assert test md5 matches after the insert at the end
assert
:
that
:
-
"
result.stat.md5
==
'357dcbee8dfb4436f63bab00a235c45a'"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment