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
efe83daf
Commit
efe83daf
authored
Oct 30, 2012
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ${var.$other_var} and add test cases for it
parent
fb27cb45
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
lib/ansible/template.py
+3
-3
test/TestUtils.py
+22
-0
No files found.
lib/ansible/template.py
View file @
efe83daf
...
...
@@ -40,7 +40,7 @@ import pwd
_LISTRE
=
re
.
compile
(
r"(\w+)\[(\d+)\]"
)
def
_varFindLimitSpace
(
space
,
part
,
depth
):
def
_varFindLimitSpace
(
vars
,
space
,
part
,
depth
):
# TODO: comments
...
...
@@ -101,7 +101,7 @@ def _varFind(text, vars, depth=0):
pass
elif
is_complex
and
text
[
end
]
==
'.'
:
if
brace_level
==
part_start
[
1
]:
space
=
_varFindLimitSpace
(
space
,
text
[
part_start
[
0
]:
end
],
depth
)
space
=
_varFindLimitSpace
(
vars
,
space
,
text
[
part_start
[
0
]:
end
],
depth
)
part_start
=
(
end
+
1
,
brace_level
)
else
:
break
...
...
@@ -113,7 +113,7 @@ def _varFind(text, vars, depth=0):
return
None
if
var_end
==
part_start
[
0
]:
return
None
space
=
_varFindLimitSpace
(
space
,
text
[
part_start
[
0
]:
var_end
],
depth
)
space
=
_varFindLimitSpace
(
vars
,
space
,
text
[
part_start
[
0
]:
var_end
],
depth
)
return
{
'replacement'
:
space
,
'start'
:
start
,
'end'
:
end
}
def
varReplace
(
raw
,
vars
,
depth
=
0
,
expand_lists
=
False
):
...
...
test/TestUtils.py
View file @
efe83daf
...
...
@@ -238,6 +238,28 @@ class TestUtils(unittest.TestCase):
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
assert
res
==
'action $foo'
def
test_varReplace_var_part
(
self
):
vars
=
{
'foo'
:
{
'bar'
:
'result'
,
},
'key'
:
'bar'
,
}
template
=
'test ${foo.$key}'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
assert
res
==
'test result'
def
test_varReplace_var_partial_part
(
self
):
vars
=
{
'foo'
:
{
'barbaz'
:
'result'
,
},
'key'
:
'bar'
,
}
template
=
'test ${foo.${key}baz}'
res
=
ansible
.
utils
.
varReplace
(
template
,
vars
)
assert
res
==
'test result'
def
test_template_varReplace_iterated
(
self
):
template
=
'hello $who'
vars
=
{
...
...
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