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
09901f41
Commit
09901f41
authored
Jun 16, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #482 from dhozac/iterative-template
Iterative template
parents
ce838e07
682e728e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
4 deletions
+21
-4
lib/ansible/runner/__init__.py
+1
-1
lib/ansible/utils.py
+9
-3
test/TestUtils.py
+11
-0
No files found.
lib/ansible/runner/__init__.py
View file @
09901f41
...
...
@@ -648,7 +648,7 @@ class Runner(object):
inject
.
update
(
host_variables
)
inject
.
update
(
self
.
module_vars
)
conditional
=
utils
.
double_
template
(
self
.
conditional
,
inject
,
self
.
setup_cache
)
conditional
=
utils
.
template
(
self
.
conditional
,
inject
,
self
.
setup_cache
)
if
not
eval
(
conditional
):
result
=
utils
.
smjson
(
dict
(
skipped
=
True
))
self
.
callbacks
.
on_skipped
(
host
)
...
...
lib/ansible/utils.py
View file @
09901f41
...
...
@@ -265,7 +265,7 @@ def varReplace(raw, vars):
return
''
.
join
(
done
)
def
template
(
text
,
vars
,
setup_cache
=
None
,
no_engine
=
True
):
def
_
template
(
text
,
vars
,
setup_cache
=
None
,
no_engine
=
True
):
''' run a text buffer through the templating engine '''
vars
=
vars
.
copy
()
vars
[
'hostvars'
]
=
setup_cache
...
...
@@ -281,8 +281,14 @@ def template(text, vars, setup_cache=None, no_engine=True):
res
=
res
+
'
\n
'
return
res
def
double_template
(
text
,
vars
,
setup_cache
):
return
template
(
template
(
text
,
vars
,
setup_cache
),
vars
,
setup_cache
)
def
template
(
text
,
vars
,
setup_cache
=
None
,
no_engine
=
True
):
''' run a text buffer through the templating engine
until it no longer changes '''
prev_text
=
''
while
prev_text
!=
text
:
prev_text
=
text
text
=
_template
(
text
,
vars
,
setup_cache
,
no_engine
)
return
text
def
template_from_file
(
path
,
vars
,
setup_cache
,
no_engine
=
True
):
''' run a file through the templating engine '''
...
...
test/TestUtils.py
View file @
09901f41
...
...
@@ -236,6 +236,17 @@ class TestUtils(unittest.TestCase):
assert
res
==
u'hello wórld'
def
test_template_varReplace_iterated
(
self
):
template
=
'hello $who'
vars
=
{
'who'
:
'oh great $person'
,
'person'
:
'one'
,
}
res
=
ansible
.
utils
.
template
(
template
,
vars
)
assert
res
==
u'hello oh great one'
#####################################
### key-value parsing
...
...
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