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
2a614c1c
Commit
2a614c1c
authored
Sep 21, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close module file once we're done reading from it
parent
3f5ea43f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
37 deletions
+37
-37
lib/ansible/executor/module_common.py
+37
-37
No files found.
lib/ansible/executor/module_common.py
View file @
2a614c1c
...
...
@@ -156,49 +156,49 @@ def modify_module(module_path, module_args, task_vars=dict(), strip_comments=Fal
# minifier output)
# * Only split into lines and recombine into strings once
# * Cache the modified module? If only the args are different and we do
# that as the last step we could cache
s
ll the work up to that point.
# that as the last step we could cache
a
ll the work up to that point.
with
open
(
module_path
)
as
f
:
# read in the module source
module_data
=
f
.
read
()
(
module_data
,
module_style
)
=
_find_snippet_imports
(
module_data
,
module_path
,
strip_comments
)
module_args_json
=
json
.
dumps
(
module_args
)
.
encode
(
'utf-8'
)
python_repred_args
=
repr
(
module_args_json
)
# these strings should be part of the 'basic' snippet which is required to be included
module_data
=
module_data
.
replace
(
REPLACER_VERSION
,
repr
(
__version__
))
module_data
=
module_data
.
replace
(
REPLACER_COMPLEX
,
python_repred_args
)
module_data
=
module_data
.
replace
(
REPLACER_WINARGS
,
module_args_json
)
module_data
=
module_data
.
replace
(
REPLACER_JSONARGS
,
module_args_json
)
if
module_style
==
'new'
:
facility
=
C
.
DEFAULT_SYSLOG_FACILITY
if
'ansible_syslog_facility'
in
task_vars
:
facility
=
task_vars
[
'ansible_syslog_facility'
]
module_data
=
module_data
.
replace
(
'syslog.LOG_USER'
,
"syslog.
%
s"
%
facility
)
lines
=
module_data
.
split
(
b
"
\n
"
,
1
)
shebang
=
None
if
lines
[
0
]
.
startswith
(
b
"#!"
):
shebang
=
lines
[
0
]
.
strip
()
args
=
shlex
.
split
(
str
(
shebang
[
2
:]))
interpreter
=
args
[
0
]
interpreter_config
=
'ansible_
%
s_interpreter'
%
os
.
path
.
basename
(
interpreter
)
if
interpreter_config
in
task_vars
:
interpreter
=
to_bytes
(
task_vars
[
interpreter_config
],
errors
=
'strict'
)
lines
[
0
]
=
shebang
=
b
"#!{0} {1}"
.
format
(
interpreter
,
b
" "
.
join
(
args
[
1
:]))
if
os
.
path
.
basename
(
interpreter
)
.
startswith
(
'python'
):
lines
.
insert
(
1
,
ENCODING_STRING
)
else
:
# No shebang, assume a binary module?
pass
(
module_data
,
module_style
)
=
_find_snippet_imports
(
module_data
,
module_path
,
strip_comments
)
module_args_json
=
json
.
dumps
(
module_args
)
.
encode
(
'utf-8'
)
python_repred_args
=
repr
(
module_args_json
)
# these strings should be part of the 'basic' snippet which is required to be included
module_data
=
module_data
.
replace
(
REPLACER_VERSION
,
repr
(
__version__
))
module_data
=
module_data
.
replace
(
REPLACER_COMPLEX
,
python_repred_args
)
module_data
=
module_data
.
replace
(
REPLACER_WINARGS
,
module_args_json
)
module_data
=
module_data
.
replace
(
REPLACER_JSONARGS
,
module_args_json
)
if
module_style
==
'new'
:
facility
=
C
.
DEFAULT_SYSLOG_FACILITY
if
'ansible_syslog_facility'
in
task_vars
:
facility
=
task_vars
[
'ansible_syslog_facility'
]
module_data
=
module_data
.
replace
(
'syslog.LOG_USER'
,
"syslog.
%
s"
%
facility
)
lines
=
module_data
.
split
(
b
"
\n
"
,
1
)
shebang
=
None
if
lines
[
0
]
.
startswith
(
b
"#!"
):
shebang
=
lines
[
0
]
.
strip
()
args
=
shlex
.
split
(
str
(
shebang
[
2
:]))
interpreter
=
args
[
0
]
interpreter_config
=
'ansible_
%
s_interpreter'
%
os
.
path
.
basename
(
interpreter
)
if
interpreter_config
in
task_vars
:
interpreter
=
to_bytes
(
task_vars
[
interpreter_config
],
errors
=
'strict'
)
lines
[
0
]
=
shebang
=
b
"#!{0} {1}"
.
format
(
interpreter
,
b
" "
.
join
(
args
[
1
:]))
if
os
.
path
.
basename
(
interpreter
)
.
startswith
(
'python'
):
lines
.
insert
(
1
,
ENCODING_STRING
)
else
:
# No shebang, assume a binary module?
pass
module_data
=
b
"
\n
"
.
join
(
lines
)
module_data
=
b
"
\n
"
.
join
(
lines
)
return
(
module_data
,
module_style
,
shebang
)
return
(
module_data
,
module_style
,
shebang
)
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