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
83ce1b2d
Commit
83ce1b2d
authored
Feb 12, 2013
by
Yves Dorfsman
Committed by
Michael DeHaan
Feb 16, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified to follow Daniel Hokka Zakrisson's recommendations.
parent
4de1b4e8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
17 deletions
+11
-17
library/lineinfile
+11
-17
No files found.
library/lineinfile
View file @
83ce1b2d
...
@@ -64,17 +64,14 @@ options:
...
@@ -64,17 +64,14 @@ options:
after the specified regular expression. A special value is
after the specified regular expression. A special value is
available; C(EOF) for inserting the line at the end of the file.
available; C(EOF) for inserting the line at the end of the file.
choices: [ EOF, *regex* ]
choices: [ EOF, *regex* ]
default: EOF
insertbefore:
insertbefore:
required: false
required: false
default: BOF
description:
description:
- Used with C(state=present). If specified, the line will be inserted
- Used with C(state=present). If specified, the line will be inserted
before the specified regular expression. A value is available;
before the specified regular expression. A value is available;
C(BOF) for inserting the line at the beginning of the
C(BOF) for inserting the line at the beginning of the
file.
file.
choices: [ BOF, *regex* ]
choices: [ BOF, *regex* ]
default: BOF
create:
create:
required: false
required: false
choices: [ yes, no ]
choices: [ yes, no ]
...
@@ -116,18 +113,13 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu
...
@@ -116,18 +113,13 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu
mre
=
re
.
compile
(
regexp
)
mre
=
re
.
compile
(
regexp
)
if
not
mre
.
search
(
line
):
if
not
mre
.
search
(
line
):
module
.
fail_json
(
msg
=
"usage error: line= doesn't match regexp (
%
s)"
%
regexp
)
module
.
fail_json
(
msg
=
"usage error: line= doesn't match regexp (
%
s)"
%
regexp
)
if
insertbefore
and
insertafter
:
module
.
fail_json
(
msg
=
"usage error:
\"
insertbefore
\"
and
\"
insertafter
\"
cannot be combined"
)
if
insertafter
in
(
'BOF'
,
'EOF'
,
False
):
if
insertafter
is
not
None
and
insertafter
not
in
(
'BOF'
,
'EOF'
):
if
insertbefore
in
(
'BOF'
,
False
):
insre
=
None
else
:
insre
=
re
.
compile
(
insertbefore
)
else
:
insre
=
re
.
compile
(
insertafter
)
insre
=
re
.
compile
(
insertafter
)
elif
insertbefore
is
not
None
and
insertbefore
not
in
(
'BOF'
):
insre
=
re
.
compile
(
insertbefore
)
else
:
insre
=
None
# index[0] is the line num where regexp has been found
# index[0] is the line num where regexp has been found
# index[1] is the line num where insertafter/inserbefore has been found
# index[1] is the line num where insertafter/inserbefore has been found
...
@@ -153,12 +145,13 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu
...
@@ -153,12 +145,13 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu
msg
=
'line replaced'
msg
=
'line replaced'
changed
=
True
changed
=
True
# Add it to the beginning of the file
# Add it to the beginning of the file
# we keep insertafter == 'BOF' for backwards compatibility, but it should be removed eventually
elif
insertbefore
==
'BOF'
or
insertafter
==
'BOF'
:
elif
insertbefore
==
'BOF'
or
insertafter
==
'BOF'
:
lines
.
insert
(
0
,
line
+
os
.
linesep
)
lines
.
insert
(
0
,
line
+
os
.
linesep
)
msg
=
'line added'
msg
=
'line added'
changed
=
True
changed
=
True
# Add it to the end of the file if requested or if insertafter=/insertbefore didn't match
# 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'
or
index
[
1
]
==
-
1
:
lines
.
append
(
line
+
os
.
linesep
)
lines
.
append
(
line
+
os
.
linesep
)
msg
=
'line added'
msg
=
'line added'
...
@@ -209,11 +202,12 @@ def main():
...
@@ -209,11 +202,12 @@ def main():
state
=
dict
(
default
=
'present'
,
choices
=
[
'absent'
,
'present'
]),
state
=
dict
(
default
=
'present'
,
choices
=
[
'absent'
,
'present'
]),
regexp
=
dict
(
required
=
True
),
regexp
=
dict
(
required
=
True
),
line
=
dict
(
aliases
=
[
'value'
]),
line
=
dict
(
aliases
=
[
'value'
]),
insertafter
=
dict
(
default
=
Fals
e
),
insertafter
=
dict
(
default
=
Non
e
),
insertbefore
=
dict
(
default
=
Fals
e
),
insertbefore
=
dict
(
default
=
Non
e
),
create
=
dict
(
default
=
False
,
choices
=
BOOLEANS
),
create
=
dict
(
default
=
False
,
choices
=
BOOLEANS
),
backup
=
dict
(
default
=
False
,
choices
=
BOOLEANS
),
backup
=
dict
(
default
=
False
,
choices
=
BOOLEANS
),
),
),
mutually_exclusive
=
[[
'insertbefore'
,
'insertafter'
]]
)
)
params
=
module
.
params
params
=
module
.
params
...
...
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