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
ed5ac932
Commit
ed5ac932
authored
Sep 15, 2015
by
Daniel Donckers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport fix for properly use local variables from templates including other templates to 1.9
Fixes #6653
parent
d2d3162a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
2 deletions
+14
-2
lib/ansible/utils/template.py
+14
-2
No files found.
lib/ansible/utils/template.py
View file @
ed5ac932
...
...
@@ -15,12 +15,15 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from
__future__
import
print_function
import
sys
import
os
import
re
import
codecs
import
jinja2
from
jinja2.runtime
import
StrictUndefined
from
jinja2.exceptions
import
TemplateSyntaxError
from
jinja2.utils
import
missing
import
yaml
import
json
from
ansible
import
errors
...
...
@@ -157,16 +160,23 @@ class _jinja2_vars(object):
extras is a list of locals to also search for variables.
'''
def
__init__
(
self
,
basedir
,
vars
,
globals
,
fail_on_undefined
,
*
extras
):
def
__init__
(
self
,
basedir
,
vars
,
globals
,
fail_on_undefined
,
locals
=
None
,
*
extras
):
self
.
basedir
=
basedir
self
.
vars
=
vars
self
.
globals
=
globals
self
.
fail_on_undefined
=
fail_on_undefined
self
.
extras
=
extras
self
.
locals
=
dict
()
if
isinstance
(
locals
,
dict
):
for
key
,
val
in
locals
.
iteritems
():
if
key
[:
2
]
==
'l_'
and
val
is
not
missing
:
self
.
locals
[
key
[
2
:]]
=
val
def
__contains__
(
self
,
k
):
if
k
in
self
.
vars
:
return
True
if
k
in
self
.
locals
:
return
True
for
i
in
self
.
extras
:
if
k
in
i
:
return
True
...
...
@@ -177,6 +187,8 @@ class _jinja2_vars(object):
def
__getitem__
(
self
,
varname
):
from
ansible.runner
import
HostVars
if
varname
not
in
self
.
vars
:
if
varname
in
self
.
locals
:
return
self
.
locals
[
varname
]
for
i
in
self
.
extras
:
if
varname
in
i
:
return
i
[
varname
]
...
...
@@ -200,7 +212,7 @@ class _jinja2_vars(object):
'''
if
locals
is
None
:
return
self
return
_jinja2_vars
(
self
.
basedir
,
self
.
vars
,
self
.
globals
,
self
.
fail_on_undefined
,
locals
,
*
self
.
extras
)
return
_jinja2_vars
(
self
.
basedir
,
self
.
vars
,
self
.
globals
,
self
.
fail_on_undefined
,
locals
=
locals
,
*
self
.
extras
)
class
J2Template
(
jinja2
.
environment
.
Template
):
'''
...
...
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