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
df3c4849
Commit
df3c4849
authored
Apr 28, 2013
by
Stoned Elipot
Committed by
Michael DeHaan
Apr 28, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Also load Jinja2 extensions when processing template from string
parent
d7933522
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
15 deletions
+20
-15
lib/ansible/utils/template.py
+20
-15
No files found.
lib/ansible/utils/template.py
View file @
df3c4849
...
...
@@ -49,6 +49,23 @@ def _get_filters():
return
Globals
.
FILTERS
def
_get_extensions
():
''' return jinja2 extensions to load '''
'''
if some extensions are set via jinja_extensions in ansible.cfg, we try
to load them with the jinja environment
'''
jinja_exts
=
[]
if
C
.
DEFAULT_JINJA2_EXTENSIONS
:
'''
Let's make sure the configuration directive doesn't contain spaces
and split extensions in an array
'''
jinja_exts
=
C
.
DEFAULT_JINJA2_EXTENSIONS
.
replace
(
" "
,
""
)
.
split
(
','
)
return
jinja_exts
class
Flags
:
LEGACY_TEMPLATE_WARNING
=
False
...
...
@@ -375,22 +392,10 @@ def template_from_file(basedir, path, vars):
realpath
=
utils
.
path_dwim
(
basedir
,
path
)
loader
=
jinja2
.
FileSystemLoader
([
basedir
,
os
.
path
.
dirname
(
realpath
)])
'''
if some extensions are set via jinja_extensions in ansible.cfg, we try
to load them with the jinja environment
'''
jinja_exts
=
[]
if
C
.
DEFAULT_JINJA2_EXTENSIONS
:
'''
Let's make sure the configuration directive doesn't contain spaces
and split extensions in an array
'''
jinja_exts
=
C
.
DEFAULT_JINJA2_EXTENSIONS
.
replace
(
" "
,
""
)
.
split
(
','
)
def
my_lookup
(
*
args
,
**
kwargs
):
return
lookup
(
*
args
,
basedir
=
basedir
,
**
kwargs
)
environment
=
jinja2
.
Environment
(
loader
=
loader
,
trim_blocks
=
True
,
extensions
=
jinja_exts
)
environment
=
jinja2
.
Environment
(
loader
=
loader
,
trim_blocks
=
True
,
extensions
=
_get_extensions
()
)
environment
.
filters
.
update
(
_get_filters
())
environment
.
globals
[
'lookup'
]
=
my_lookup
...
...
@@ -445,12 +450,12 @@ def template_from_file(basedir, path, vars):
return
template
(
basedir
,
res
,
vars
)
def
template_from_string
(
basedir
,
data
,
vars
):
''' run a
file
through the (Jinja2) templating engine '''
''' run a
string
through the (Jinja2) templating engine '''
try
:
if
type
(
data
)
==
str
:
data
=
unicode
(
data
,
'utf-8'
)
environment
=
jinja2
.
Environment
(
trim_blocks
=
True
,
undefined
=
StrictUndefined
)
environment
=
jinja2
.
Environment
(
trim_blocks
=
True
,
undefined
=
StrictUndefined
,
extensions
=
_get_extensions
())
environment
.
filters
.
update
(
_get_filters
())
environment
.
template_class
=
J2Template
...
...
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