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
2a8b9295
Commit
2a8b9295
authored
Sep 04, 2012
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add backups to lineinfile
parent
dfcb9d3c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
+10
-4
library/lineinfile
+10
-4
No files found.
library/lineinfile
View file @
2a8b9295
...
...
@@ -21,7 +21,7 @@
import
re
import
os
def
present
(
module
,
name
,
regexp
,
line
,
insertafter
):
def
present
(
module
,
name
,
regexp
,
line
,
insertafter
,
backup
):
f
=
open
(
name
,
'rb'
)
lines
=
f
.
readlines
()
f
.
close
()
...
...
@@ -69,13 +69,15 @@ def present(module, name, regexp, line, insertafter):
changed
=
True
if
changed
:
if
backup
:
module
.
backuplocal
(
name
)
f
=
open
(
name
,
'wb'
)
f
.
writelines
(
lines
)
f
.
close
()
module
.
exit_json
(
changed
=
changed
,
msg
=
msg
)
def
absent
(
module
,
name
,
regexp
):
def
absent
(
module
,
name
,
regexp
,
backup
):
f
=
open
(
name
,
'rb'
)
lines
=
f
.
readlines
()
f
.
close
()
...
...
@@ -90,6 +92,8 @@ def absent(module, name, regexp):
lines
=
filter
(
matcher
,
lines
)
changed
=
len
(
found
)
>
0
if
changed
:
if
backup
:
module
.
backuplocal
(
name
)
f
=
open
(
name
,
'wb'
)
f
.
writelines
(
lines
)
f
.
close
()
...
...
@@ -103,18 +107,20 @@ def main():
regexp
=
dict
(
required
=
True
),
line
=
dict
(
aliases
=
[
'value'
]),
insertafter
=
dict
(
default
=
'EOF'
),
backup
=
dict
(
default
=
False
,
choices
=
BOOLEANS
),
),
)
params
=
module
.
params
backup
=
module
.
boolean
(
module
.
params
.
get
(
'backup'
,
False
))
if
params
[
'state'
]
==
'present'
:
if
'line'
not
in
params
:
module
.
fail_json
(
msg
=
'line= is required with state=present'
)
present
(
module
,
params
[
'name'
],
params
[
'regexp'
],
params
[
'line'
],
params
[
'insertafter'
])
params
[
'insertafter'
]
,
backup
)
else
:
absent
(
module
,
params
[
'name'
],
params
[
'regexp'
])
absent
(
module
,
params
[
'name'
],
params
[
'regexp'
]
,
backup
)
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
...
...
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