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
fb7716bd
Commit
fb7716bd
authored
Jun 17, 2012
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a Jinja2 environment allowing includes
parent
09901f41
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
18 deletions
+15
-18
lib/ansible/runner/__init__.py
+1
-2
lib/ansible/utils.py
+14
-16
No files found.
lib/ansible/runner/__init__.py
View file @
fb7716bd
...
@@ -586,8 +586,7 @@ class Runner(object):
...
@@ -586,8 +586,7 @@ class Runner(object):
# template the source data locally
# template the source data locally
try
:
try
:
resultant
=
utils
.
template_from_file
(
utils
.
path_dwim
(
self
.
basedir
,
source
),
resultant
=
utils
.
template_from_file
(
self
.
basedir
,
source
,
inject
,
self
.
setup_cache
)
inject
,
self
.
setup_cache
,
no_engine
=
False
)
except
Exception
,
e
:
except
Exception
,
e
:
result
=
dict
(
failed
=
True
,
msg
=
str
(
e
))
result
=
dict
(
failed
=
True
,
msg
=
str
(
e
))
return
ReturnData
(
host
=
conn
.
host
,
comm_ok
=
False
,
result
=
result
)
return
ReturnData
(
host
=
conn
.
host
,
comm_ok
=
False
,
result
=
result
)
...
...
lib/ansible/utils.py
View file @
fb7716bd
...
@@ -265,35 +265,33 @@ def varReplace(raw, vars):
...
@@ -265,35 +265,33 @@ def varReplace(raw, vars):
return
''
.
join
(
done
)
return
''
.
join
(
done
)
def
_template
(
text
,
vars
,
setup_cache
=
None
,
no_engine
=
True
):
def
_template
(
text
,
vars
,
setup_cache
=
None
):
''' run a text buffer through the templating engine '''
''' run a text buffer through the templating engine '''
vars
=
vars
.
copy
()
vars
=
vars
.
copy
()
vars
[
'hostvars'
]
=
setup_cache
vars
[
'hostvars'
]
=
setup_cache
text
=
varReplace
(
unicode
(
text
),
vars
)
text
=
varReplace
(
unicode
(
text
),
vars
)
if
no_engine
:
return
text
# used when processing include: directives so that Jinja is evaluated
# in a later context when more variables are available
return
text
else
:
template
=
jinja2
.
Template
(
text
)
res
=
template
.
render
(
vars
)
if
text
.
endswith
(
'
\n
'
)
and
not
res
.
endswith
(
'
\n
'
):
res
=
res
+
'
\n
'
return
res
def
template
(
text
,
vars
,
setup_cache
=
None
,
no_engine
=
True
):
def
template
(
text
,
vars
,
setup_cache
=
None
):
''' run a text buffer through the templating engine
''' run a text buffer through the templating engine
until it no longer changes '''
until it no longer changes '''
prev_text
=
''
prev_text
=
''
while
prev_text
!=
text
:
while
prev_text
!=
text
:
prev_text
=
text
prev_text
=
text
text
=
_template
(
text
,
vars
,
setup_cache
,
no_engine
)
text
=
_template
(
text
,
vars
,
setup_cache
)
return
text
return
text
def
template_from_file
(
path
,
vars
,
setup_cache
,
no_engine
=
Tru
e
):
def
template_from_file
(
basedir
,
path
,
vars
,
setup_cach
e
):
''' run a file through the templating engine '''
''' run a file through the templating engine '''
data
=
codecs
.
open
(
path
,
encoding
=
"utf8"
)
.
read
()
environment
=
jinja2
.
Environment
(
loader
=
jinja2
.
FileSystemLoader
(
basedir
),
trim_blocks
=
False
)
return
template
(
data
,
vars
,
setup_cache
,
no_engine
=
no_engine
)
data
=
codecs
.
open
(
path_dwim
(
basedir
,
path
),
encoding
=
"utf8"
)
.
read
()
template
=
environment
.
from_string
(
data
)
vars
=
vars
.
copy
()
vars
[
'hostvars'
]
=
setup_cache
res
=
template
.
render
(
vars
)
if
data
.
endswith
(
'
\n
'
)
and
not
res
.
endswith
(
'
\n
'
):
res
=
res
+
'
\n
'
return
res
def
parse_yaml
(
data
):
def
parse_yaml
(
data
):
return
yaml
.
load
(
data
)
return
yaml
.
load
(
data
)
...
...
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