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
df136769
Commit
df136769
authored
Aug 11, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure we only use unquote on quoted lines in lineinfile when needed
parent
f1f88f89
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
6 deletions
+17
-6
lib/ansible/module_utils/splitter.py
+4
-1
library/files/lineinfile
+13
-5
No files found.
lib/ansible/module_utils/splitter.py
View file @
df136769
...
...
@@ -187,9 +187,12 @@ def split_args(args):
return
params
def
is_quoted
(
data
):
return
len
(
data
)
>
0
and
(
data
[
0
]
==
'"'
and
data
[
-
1
]
==
'"'
or
data
[
0
]
==
"'"
and
data
[
-
1
]
==
"'"
)
def
unquote
(
data
):
''' removes first and last quotes from a string, if the string starts and ends with the same quotes '''
if
len
(
data
)
>
0
and
(
data
[
0
]
==
'"'
and
data
[
-
1
]
==
'"'
or
data
[
0
]
==
"'"
and
data
[
-
1
]
==
"'"
):
if
is_quoted
(
data
):
return
data
[
1
:
-
1
]
return
data
library/files/lineinfile
View file @
df136769
...
...
@@ -363,14 +363,22 @@ def main():
if
ins_bef
is
None
and
ins_aft
is
None
:
ins_aft
=
'EOF'
line
=
params
[
'line'
]
# The safe_eval call will remove some quoting, but not others,
# so we need to know if we should specifically unquote it.
should_unquote
=
not
is_quoted
(
line
)
# Replace escape sequences like '\n' while being sure
# not to replace octal escape sequences (\ooo) since they
# match the backref syntax
# match the backref syntax
.
if
backrefs
:
line
=
re
.
sub
(
r'(\\[0-9]{1,3})'
,
r'\\\1'
,
params
[
'line'
])
else
:
line
=
params
[
'line'
]
line
=
unquote
(
module
.
safe_eval
(
pipes
.
quote
(
line
)))
line
=
re
.
sub
(
r'(\\[0-9]{1,3})'
,
r'\\\1'
,
line
)
line
=
module
.
safe_eval
(
pipes
.
quote
(
line
))
# Now remove quotes around the string, if needed
if
should_unquote
:
line
=
unquote
(
line
)
present
(
module
,
dest
,
params
[
'regexp'
],
line
,
ins_aft
,
ins_bef
,
create
,
backup
,
backrefs
)
...
...
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