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
0f170622
Commit
0f170622
authored
Dec 19, 2012
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for using the Jinja2 built-ins such as range
parent
ab9e9486
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
lib/ansible/utils/template.py
+8
-4
No files found.
lib/ansible/utils/template.py
View file @
0f170622
...
@@ -242,14 +242,18 @@ def template(basedir, text, vars, expand_lists=False):
...
@@ -242,14 +242,18 @@ def template(basedir, text, vars, expand_lists=False):
class
_jinja2_vars
(
object
):
class
_jinja2_vars
(
object
):
''' helper class to template all variable content before jinja2 sees it '''
''' helper class to template all variable content before jinja2 sees it '''
def
__init__
(
self
,
basedir
,
vars
):
def
__init__
(
self
,
basedir
,
vars
,
globals
):
self
.
basedir
=
basedir
self
.
basedir
=
basedir
self
.
vars
=
vars
self
.
vars
=
vars
self
.
globals
=
globals
def
__contains__
(
self
,
k
):
def
__contains__
(
self
,
k
):
return
k
in
self
.
vars
return
k
in
self
.
vars
or
k
in
self
.
globals
def
__getitem__
(
self
,
varname
):
def
__getitem__
(
self
,
varname
):
if
varname
not
in
self
.
vars
:
if
varname
not
in
self
.
vars
:
raise
KeyError
(
"undefined variable:
%
s"
%
varname
)
if
varname
in
self
.
globals
:
return
self
.
globals
[
varname
]
else
:
raise
KeyError
(
"undefined variable:
%
s"
%
varname
)
var
=
self
.
vars
[
varname
]
var
=
self
.
vars
[
varname
]
# HostVars is special, return it as-is
# HostVars is special, return it as-is
if
isinstance
(
var
,
dict
)
and
type
(
var
)
!=
dict
:
if
isinstance
(
var
,
dict
)
and
type
(
var
)
!=
dict
:
...
@@ -308,7 +312,7 @@ def template_from_file(basedir, path, vars):
...
@@ -308,7 +312,7 @@ def template_from_file(basedir, path, vars):
# This line performs deep Jinja2 magic that uses the _jinja2_vars object for vars
# This line performs deep Jinja2 magic that uses the _jinja2_vars object for vars
# Ideally, this could use some API where setting shared=True and the object won't get
# Ideally, this could use some API where setting shared=True and the object won't get
# passed through dict(o), but I have not found that yet.
# passed through dict(o), but I have not found that yet.
res
=
jinja2
.
utils
.
concat
(
t
.
root_render_func
(
t
.
new_context
(
_jinja2_vars
(
basedir
,
vars
),
shared
=
True
)))
res
=
jinja2
.
utils
.
concat
(
t
.
root_render_func
(
t
.
new_context
(
_jinja2_vars
(
basedir
,
vars
,
t
.
globals
),
shared
=
True
)))
if
data
.
endswith
(
'
\n
'
)
and
not
res
.
endswith
(
'
\n
'
):
if
data
.
endswith
(
'
\n
'
)
and
not
res
.
endswith
(
'
\n
'
):
res
=
res
+
'
\n
'
res
=
res
+
'
\n
'
...
...
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