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
84f98534
Commit
84f98534
authored
Sep 25, 2012
by
Daniel Hokka Zakrisson
Committed by
Michael DeHaan
Sep 25, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make varReplace recursive instead of iterative
parent
d181a643
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
lib/ansible/utils.py
+10
-11
No files found.
lib/ansible/utils.py
View file @
84f98534
...
@@ -176,12 +176,13 @@ _LISTRE = re.compile(r"(\w+)\[(\d+)\]")
...
@@ -176,12 +176,13 @@ _LISTRE = re.compile(r"(\w+)\[(\d+)\]")
class
VarNotFoundException
(
Exception
):
class
VarNotFoundException
(
Exception
):
pass
pass
def
_varLookup
(
name
,
vars
):
def
_varLookup
(
name
,
vars
,
depth
=
0
):
''' find the contents of a possibly complex variable in vars. '''
''' find the contents of a possibly complex variable in vars. '''
path
=
name
.
split
(
'.'
)
path
=
name
.
split
(
'.'
)
space
=
vars
space
=
vars
for
part
in
path
:
for
part
in
path
:
part
=
varReplace
(
part
,
vars
,
depth
=
depth
+
1
)
if
part
in
space
:
if
part
in
space
:
space
=
space
[
part
]
space
=
space
[
part
]
elif
"["
in
part
:
elif
"["
in
part
:
...
@@ -196,7 +197,7 @@ def _varLookup(name, vars):
...
@@ -196,7 +197,7 @@ def _varLookup(name, vars):
raise
VarNotFoundException
()
raise
VarNotFoundException
()
return
space
return
space
_KEYCRE
=
re
.
compile
(
r"\$(?P<complex>\{){0,1}((?(complex)[\w\.\[\]]+|\w+))(?(complex)\})"
)
_KEYCRE
=
re
.
compile
(
r"\$(?P<complex>\{){0,1}((?(complex)[\w\.\[\]
\$\{\}
]+|\w+))(?(complex)\})"
)
def
varLookup
(
varname
,
vars
):
def
varLookup
(
varname
,
vars
):
''' helper function used by with_items '''
''' helper function used by with_items '''
...
@@ -209,10 +210,13 @@ def varLookup(varname, vars):
...
@@ -209,10 +210,13 @@ def varLookup(varname, vars):
except
VarNotFoundException
:
except
VarNotFoundException
:
return
None
return
None
def
varReplace
(
raw
,
vars
,
do_repr
=
False
):
def
varReplace
(
raw
,
vars
,
do_repr
=
False
,
depth
=
0
):
''' Perform variable replacement of $variables in string raw using vars dictionary '''
''' Perform variable replacement of $variables in string raw using vars dictionary '''
# this code originally from yum
# this code originally from yum
if
(
depth
>
20
):
raise
errors
.
AnsibleError
(
"template recursion depth exceeded"
)
done
=
[]
# Completed chunks to return
done
=
[]
# Completed chunks to return
while
raw
:
while
raw
:
...
@@ -225,7 +229,8 @@ def varReplace(raw, vars, do_repr=False):
...
@@ -225,7 +229,8 @@ def varReplace(raw, vars, do_repr=False):
# original)
# original)
try
:
try
:
replacement
=
unicode
(
_varLookup
(
m
.
group
(
2
),
vars
))
replacement
=
unicode
(
_varLookup
(
m
.
group
(
2
),
vars
,
depth
))
replacement
=
varReplace
(
replacement
,
vars
,
depth
=
depth
+
1
)
except
VarNotFoundException
:
except
VarNotFoundException
:
replacement
=
m
.
group
()
replacement
=
m
.
group
()
...
@@ -286,13 +291,7 @@ def template(basedir, text, vars, do_repr=False):
...
@@ -286,13 +291,7 @@ def template(basedir, text, vars, do_repr=False):
text
=
text
.
decode
(
'utf-8'
)
text
=
text
.
decode
(
'utf-8'
)
except
UnicodeEncodeError
:
except
UnicodeEncodeError
:
pass
# already unicode
pass
# already unicode
depth
=
0
text
=
varReplace
(
unicode
(
text
),
vars
,
do_repr
)
while
prev_text
!=
text
:
depth
=
depth
+
1
if
(
depth
>
20
):
raise
errors
.
AnsibleError
(
"template recursion depth exceeded"
)
prev_text
=
text
text
=
varReplace
(
unicode
(
text
),
vars
,
do_repr
)
text
=
varReplaceFilesAndPipes
(
basedir
,
text
)
text
=
varReplaceFilesAndPipes
(
basedir
,
text
)
return
text
return
text
...
...
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