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
6d0da41a
Commit
6d0da41a
authored
Oct 28, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No need to template modules with Jinja2 as this can confuse some docstring comments.
parent
3722bebb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
22 deletions
+13
-22
lib/ansible/module_common.py
+13
-22
No files found.
lib/ansible/module_common.py
View file @
6d0da41a
...
...
@@ -19,7 +19,6 @@
from
cStringIO
import
StringIO
import
inspect
import
os
import
jinja2
import
shlex
# from Ansible
...
...
@@ -48,9 +47,7 @@ class ModuleReplacer(object):
from ansible.module_utils.basic import *
will result in a template evaluation of
{{ include 'basic.py' }}
will result in a slurping in of basic.py
from the module_utils/ directory in the source tree.
...
...
@@ -67,6 +64,16 @@ class ModuleReplacer(object):
# ******************************************************************************
def
slurp
(
self
,
path
):
if
not
os
.
path
.
exists
(
path
):
raise
errors
.
AnsibleError
(
"imported module support code does not exist at
%
s"
%
path
)
fd
=
open
(
path
)
data
=
fd
.
read
()
fd
.
close
()
return
data
# ******************************************************************************
def
_find_snippet_imports
(
self
,
module_data
,
module_path
):
"""
Given the source of the module, convert it to a Jinja2 template to insert
...
...
@@ -88,7 +95,7 @@ class ModuleReplacer(object):
for
line
in
lines
:
if
line
.
find
(
REPLACER
)
!=
-
1
:
output
.
write
(
"{
%
include 'basic.py'
%
}
\n\n
"
)
output
.
write
(
self
.
slurp
(
os
.
path
.
join
(
self
.
snippet_path
,
"basic.py"
))
)
snippet_names
.
append
(
'basic'
)
elif
line
.
startswith
(
'from ansible.module_utils.'
):
tokens
=
line
.
split
(
"."
)
...
...
@@ -101,7 +108,7 @@ class ModuleReplacer(object):
raise
errors
.
AnsibleError
(
"error importing module in
%
s, expecting format like 'from ansible.module_utils.basic import *'"
%
module_path
)
snippet_name
=
tokens
[
2
]
.
split
()[
0
]
snippet_names
.
append
(
snippet_name
)
output
.
write
(
"{
%
include '"
+
snippet_name
+
".py'
%
}
\n\n
"
)
output
.
write
(
self
.
slurp
(
os
.
path
.
join
(
self
.
snippet_path
,
snippet_name
+
".py"
))
)
else
:
if
self
.
strip_comments
and
line
.
startswith
(
"#"
)
or
line
==
''
:
pass
...
...
@@ -115,21 +122,6 @@ class ModuleReplacer(object):
# ******************************************************************************
def
_template_imports
(
self
,
module_data
):
loader
=
jinja2
.
FileSystemLoader
([
self
.
snippet_path
])
environment
=
jinja2
.
Environment
(
loader
=
loader
)
# trim_blocks=True)
t
=
environment
.
from_string
(
module_data
)
vars_input
=
{}
try
:
return
t
.
render
(
vars_input
)
except
jinja2
.
TemplateNotFound
,
tnf
:
raise
errors
.
AnsibleError
(
"failure to find one of the imported module utilities, an ansible.module_utils import is likely referencing a module that does not exist. Original exception was:
%
s"
%
str
(
tnf
))
# ******************************************************************************
def
modify_module
(
self
,
module_path
,
complex_args
,
module_args
,
inject
):
with
open
(
module_path
)
as
f
:
...
...
@@ -138,7 +130,6 @@ class ModuleReplacer(object):
module_data
=
f
.
read
()
(
module_data
,
module_style
)
=
self
.
_find_snippet_imports
(
module_data
,
module_path
)
module_data
=
self
.
_template_imports
(
module_data
)
complex_args_json
=
utils
.
jsonify
(
complex_args
)
# We force conversion of module_args to str because module_common calls shlex.split,
...
...
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