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
89a31b0a
Commit
89a31b0a
authored
Aug 27, 2012
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow variable expansion for vars that evaluate to false
parent
83718712
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
lib/ansible/utils.py
+14
-5
No files found.
lib/ansible/utils.py
View file @
89a31b0a
...
...
@@ -156,6 +156,9 @@ def parse_json(raw_data):
_LISTRE
=
re
.
compile
(
r"(\w+)\[(\d+)\]"
)
class
VarNotFoundException
(
Exception
):
pass
def
_varLookup
(
name
,
vars
):
''' find the contents of a possibly complex variable in vars. '''
...
...
@@ -167,13 +170,13 @@ def _varLookup(name, vars):
elif
"["
in
part
:
m
=
_LISTRE
.
search
(
part
)
if
not
m
:
r
eturn
r
aise
VarNotFoundException
()
try
:
space
=
space
[
m
.
group
(
1
)][
int
(
m
.
group
(
2
))]
except
(
KeyError
,
IndexError
):
r
eturn
r
aise
VarNotFoundException
()
else
:
r
eturn
r
aise
VarNotFoundException
()
return
space
_KEYCRE
=
re
.
compile
(
r"\$(?P<complex>\{){0,1}((?(complex)[\w\.\[\]]+|\w+))(?(complex)\})"
)
...
...
@@ -184,7 +187,10 @@ def varLookup(varname, vars):
m
=
_KEYCRE
.
search
(
varname
)
if
not
m
:
return
None
return
_varLookup
(
m
.
group
(
2
),
vars
)
try
:
return
_varLookup
(
m
.
group
(
2
),
vars
)
except
VarNotFoundException
:
return
None
def
varReplace
(
raw
,
vars
):
''' Perform variable replacement of $variables in string raw using vars dictionary '''
...
...
@@ -202,7 +208,10 @@ def varReplace(raw, vars):
# original)
varname
=
m
.
group
(
2
)
replacement
=
unicode
(
_varLookup
(
varname
,
vars
)
or
m
.
group
())
try
:
replacement
=
unicode
(
_varLookup
(
varname
,
vars
))
except
VarNotFoundException
:
replacement
=
m
.
group
()
start
,
end
=
m
.
span
()
done
.
append
(
raw
[:
start
])
# Keep stuff leading up to token
...
...
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