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
768d2939
Commit
768d2939
authored
Oct 30, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1488 from dagwieers/lineinfile-create
Add option create= to lineinfile module
parents
91cf257e
aef9a95c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
5 deletions
+26
-5
library/lineinfile
+26
-5
No files found.
library/lineinfile
View file @
768d2939
...
@@ -65,6 +65,14 @@ options:
...
@@ -65,6 +65,14 @@ options:
file, and C(EOF) for inserting the line at the end of the file.
file, and C(EOF) for inserting the line at the end of the file.
choices: [ BOF, EOF ]
choices: [ BOF, EOF ]
default: EOF
default: EOF
create:
required: false
choices: [ yes, no ]
default: no
description:
- Used with C(state=present). If specified, the file will be created
if it does not already exist. By default it will fail if the file
is missing.
backup:
backup:
required: false
required: false
default: no
default: no
...
@@ -76,10 +84,21 @@ examples:
...
@@ -76,10 +84,21 @@ examples:
- code: 'lineinfile: dest=/etc/sudoers state=absent regexp="^
%
wheel"'
- code: 'lineinfile: dest=/etc/sudoers state=absent regexp="^
%
wheel"'
'''
'''
def
present
(
module
,
dest
,
regexp
,
line
,
insertafter
,
backup
):
def
present
(
module
,
dest
,
regexp
,
line
,
insertafter
,
create
,
backup
):
f
=
open
(
dest
,
'rb'
)
lines
=
f
.
readlines
()
if
os
.
path
.
isdir
(
dest
):
f
.
close
()
module
.
fail_json
(
rc
=
256
,
msg
=
'Destination
%
s is a directory !'
%
dest
)
elif
not
os
.
path
.
exists
(
dest
):
if
not
create
:
module
.
fail_json
(
rc
=
257
,
msg
=
'Destination
%
s does not exist !'
%
dest
)
destpath
=
os
.
path
.
dirname
(
dest
)
if
not
os
.
path
.
exists
(
destpath
):
os
.
makedirs
(
destpath
)
lines
=
[]
else
:
f
=
open
(
dest
,
'rb'
)
lines
=
f
.
readlines
()
f
.
close
()
mre
=
re
.
compile
(
regexp
)
mre
=
re
.
compile
(
regexp
)
if
not
mre
.
search
(
line
):
if
not
mre
.
search
(
line
):
...
@@ -162,18 +181,20 @@ def main():
...
@@ -162,18 +181,20 @@ def main():
regexp
=
dict
(
required
=
True
),
regexp
=
dict
(
required
=
True
),
line
=
dict
(
aliases
=
[
'value'
]),
line
=
dict
(
aliases
=
[
'value'
]),
insertafter
=
dict
(
default
=
'EOF'
),
insertafter
=
dict
(
default
=
'EOF'
),
create
=
dict
(
default
=
False
,
choices
=
BOOLEANS
),
backup
=
dict
(
default
=
False
,
choices
=
BOOLEANS
),
backup
=
dict
(
default
=
False
,
choices
=
BOOLEANS
),
),
),
)
)
params
=
module
.
params
params
=
module
.
params
create
=
module
.
boolean
(
module
.
params
.
get
(
'create'
,
False
))
backup
=
module
.
boolean
(
module
.
params
.
get
(
'backup'
,
False
))
backup
=
module
.
boolean
(
module
.
params
.
get
(
'backup'
,
False
))
if
params
[
'state'
]
==
'present'
:
if
params
[
'state'
]
==
'present'
:
if
'line'
not
in
params
:
if
'line'
not
in
params
:
module
.
fail_json
(
msg
=
'line= is required with state=present'
)
module
.
fail_json
(
msg
=
'line= is required with state=present'
)
present
(
module
,
params
[
'dest'
],
params
[
'regexp'
],
params
[
'line'
],
present
(
module
,
params
[
'dest'
],
params
[
'regexp'
],
params
[
'line'
],
params
[
'insertafter'
],
backup
)
params
[
'insertafter'
],
create
,
backup
)
else
:
else
:
absent
(
module
,
params
[
'dest'
],
params
[
'regexp'
],
backup
)
absent
(
module
,
params
[
'dest'
],
params
[
'regexp'
],
backup
)
...
...
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