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
48dbb79f
Commit
48dbb79f
authored
Jun 20, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue_5679_lineinfile' into fix_lineinfile_newlines
parents
3c3c710a
567f3819
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
4 deletions
+48
-4
library/files/lineinfile
+9
-3
test/integration/roles/test_lineinfile/tasks/main.yml
+39
-1
No files found.
library/files/lineinfile
View file @
48dbb79f
...
...
@@ -19,6 +19,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import
pipes
import
re
import
os
import
tempfile
...
...
@@ -359,9 +360,14 @@ def main():
if
ins_bef
is
None
and
ins_aft
is
None
:
ins_aft
=
'EOF'
# Replace the newline character with an actual newline. Don't replace
# escaped \\n, hence sub and not str.replace.
line
=
re
.
sub
(
r'\n'
,
os
.
linesep
,
params
[
'line'
])
# Replace escape sequences like '\n' while being sure
# not to replace octal escape sequences (\ooo) since they
# match the backref syntax
if
backrefs
:
line
=
re
.
sub
(
r'(\\[0-9]{1,3})'
,
r'\\\1'
,
params
[
'line'
])
else
:
line
=
params
[
'line'
]
line
=
module
.
safe_eval
(
pipes
.
quote
(
line
))
present
(
module
,
dest
,
params
[
'regexp'
],
line
,
ins_aft
,
ins_bef
,
create
,
backup
,
backrefs
)
...
...
test/integration/roles/test_lineinfile/tasks/main.yml
View file @
48dbb79f
...
...
@@ -114,7 +114,7 @@
-
"
result.stat.md5
==
'd5955ee042139dfef16dbe3a7334475f'"
-
name
:
replace a line with backrefs
lineinfile
:
dest={{output_dir}}/test.txt state=present line="This is line 3" backrefs=yes regexp="^(REF) .* \1$"
lineinfile
:
dest={{output_dir}}/test.txt state=present line="This is line 3" backrefs=yes regexp="^(REF) .* \
\
1$"
register
:
result
-
name
:
assert that the line with backrefs was changed
...
...
@@ -224,6 +224,16 @@
-
"
result.changed
==
true"
-
"
result.msg
==
'line
added'"
-
name
:
insert a multiple lines at the end of the file
lineinfile
:
dest={{output_dir}}/test.txt state=present line="This is a line\nwith \\\n character" insertafter="EOF"
register
:
result
-
name
:
assert that the multiple lines was inserted
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
...
...
@@ -256,3 +266,31 @@
assert
:
that
:
-
"
result.stat.md5
==
'357dcbee8dfb4436f63bab00a235c45a'"
-
stat
:
path={{output_dir}}/test.txt
register
:
result
-
name
:
assert test md5 matches after insert the multiple lines
assert
:
that
:
-
"
result.stat.md5
==
'c2510d5bc8fdef8e752b8f8e74c784c2'"
-
name
:
replace a line with backrefs included in the line
lineinfile
:
dest={{output_dir}}/test.txt state=present line="New \\1 created with the backref" backrefs=yes regexp="^This is (line 4)$"
register
:
result
-
name
:
assert that the line with backrefs was changed
assert
:
that
:
-
"
result.changed
==
true"
-
"
result.msg
==
'line
replaced'"
-
name
:
stat the test after the backref line was replaced
stat
:
path={{output_dir}}/test.txt
register
:
result
-
name
:
assert test md5 matches after backref line was replaced
assert
:
that
:
-
"
result.stat.md5
==
'65f955c2a9722fd43d07103d7756ff9b'"
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