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
633fdede
Commit
633fdede
authored
Feb 22, 2013
by
Michel Blanc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes duplicate code
Fixed duplicate call for file attributes checking
parent
008dc483
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
library/lineinfile
+7
-7
No files found.
library/lineinfile
View file @
633fdede
...
@@ -103,10 +103,11 @@ examples:
...
@@ -103,10 +103,11 @@ examples:
"""
"""
def
check_file
(
module
,
changed
,
message
=
""
):
def
check_file
_attrs
(
module
,
changed
,
message
):
file_args
=
module
.
load_file_common_arguments
(
module
.
params
)
file_args
=
module
.
load_file_common_arguments
(
module
.
params
)
if
module
.
set_file_attributes_if_different
(
file_args
,
False
):
if
module
.
set_file_attributes_if_different
(
file_args
,
False
):
if
changed
:
if
changed
:
message
+=
" and "
message
+=
" and "
changed
=
True
changed
=
True
...
@@ -130,6 +131,8 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu
...
@@ -130,6 +131,8 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
f
.
close
()
f
.
close
()
msg
=
""
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
)
...
@@ -182,9 +185,6 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu
...
@@ -182,9 +185,6 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu
msg
=
'line added'
msg
=
'line added'
changed
=
True
changed
=
True
file_args
=
module
.
load_file_common_arguments
(
module
.
params
)
changed
=
module
.
set_file_attributes_if_different
(
file_args
,
changed
)
if
changed
and
not
module
.
check_mode
:
if
changed
and
not
module
.
check_mode
:
if
backup
and
os
.
path
.
exists
(
dest
):
if
backup
and
os
.
path
.
exists
(
dest
):
module
.
backup_local
(
dest
)
module
.
backup_local
(
dest
)
...
@@ -192,7 +192,7 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu
...
@@ -192,7 +192,7 @@ def present(module, dest, regexp, line, insertafter, insertbefore, create, backu
f
.
writelines
(
lines
)
f
.
writelines
(
lines
)
f
.
close
()
f
.
close
()
[
msg
,
changed
]
=
check_file
(
module
,
changed
,
msg
)
[
msg
,
changed
]
=
check_file
_attrs
(
module
,
changed
,
msg
)
module
.
exit_json
(
changed
=
changed
,
msg
=
msg
)
module
.
exit_json
(
changed
=
changed
,
msg
=
msg
)
def
absent
(
module
,
dest
,
regexp
,
backup
):
def
absent
(
module
,
dest
,
regexp
,
backup
):
...
@@ -203,6 +203,7 @@ def absent(module, dest, regexp, backup):
...
@@ -203,6 +203,7 @@ def absent(module, dest, regexp, backup):
module
.
exit_json
(
changed
=
False
,
msg
=
"file not present"
)
module
.
exit_json
(
changed
=
False
,
msg
=
"file not present"
)
msg
=
""
msg
=
""
f
=
open
(
dest
,
'rb'
)
f
=
open
(
dest
,
'rb'
)
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
f
.
close
()
f
.
close
()
...
@@ -228,8 +229,7 @@ def absent(module, dest, regexp, backup):
...
@@ -228,8 +229,7 @@ def absent(module, dest, regexp, backup):
if
changed
:
if
changed
:
msg
=
"
%
s line(s) removed"
%
len
(
found
)
msg
=
"
%
s line(s) removed"
%
len
(
found
)
[
msg
,
changed
]
=
check_file
(
module
,
changed
,
msg
)
[
msg
,
changed
]
=
check_file_attrs
(
module
,
changed
,
msg
)
module
.
exit_json
(
changed
=
changed
,
found
=
len
(
found
),
msg
=
msg
)
module
.
exit_json
(
changed
=
changed
,
found
=
len
(
found
),
msg
=
msg
)
def
main
():
def
main
():
...
...
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