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
3a36c024
Commit
3a36c024
authored
Dec 19, 2012
by
Daniel Hokka Zakrisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make lookups being fatal up to the caller
Fixes #1769.
parent
eb57c9c4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
18 deletions
+22
-18
lib/ansible/playbook/__init__.py
+1
-1
lib/ansible/utils/template.py
+21
-17
No files found.
lib/ansible/playbook/__init__.py
View file @
3a36c024
...
...
@@ -294,7 +294,7 @@ class PlayBook(object):
def
_run_task
(
self
,
play
,
task
,
is_handler
):
''' run a single task in the playbook and recursively run any subtasks. '''
self
.
callbacks
.
on_task_start
(
utils
.
template
(
play
.
basedir
,
task
.
name
,
task
.
module_vars
),
is_handler
)
self
.
callbacks
.
on_task_start
(
utils
.
template
(
play
.
basedir
,
task
.
name
,
task
.
module_vars
,
lookup_fatal
=
False
),
is_handler
)
# load up an appropriate ansible runner to run the task in parallel
results
=
self
.
_run_task_internal
(
task
)
...
...
lib/ansible/utils/template.py
View file @
3a36c024
...
...
@@ -33,7 +33,7 @@ import pwd
_LISTRE
=
re
.
compile
(
r"(\w+)\[(\d+)\]"
)
JINJA2_OVERRIDE
=
'#jinja2:'
def
_varFindLimitSpace
(
basedir
,
vars
,
space
,
part
,
depth
):
def
_varFindLimitSpace
(
basedir
,
vars
,
space
,
part
,
lookup_fatal
,
depth
):
''' limits the search space of space to part
basically does space.get(part, None), but with
...
...
@@ -47,7 +47,7 @@ def _varFindLimitSpace(basedir, vars, space, part, depth):
if
part
[
0
]
==
'{'
and
part
[
-
1
]
==
'}'
:
part
=
part
[
1
:
-
1
]
# Template part to resolve variables within (${var$var2})
part
=
varReplace
(
basedir
,
part
,
vars
,
depth
=
depth
+
1
)
part
=
varReplace
(
basedir
,
part
,
vars
,
lookup_fatal
,
depth
=
depth
+
1
)
# Now find it
if
part
in
space
:
...
...
@@ -66,7 +66,7 @@ def _varFindLimitSpace(basedir, vars, space, part, depth):
return
space
def
_varFind
(
basedir
,
text
,
vars
,
depth
=
0
):
def
_varFind
(
basedir
,
text
,
vars
,
lookup_fatal
,
depth
=
0
):
''' Searches for a variable in text and finds its replacement in vars
The variables can have two formats;
...
...
@@ -135,7 +135,7 @@ def _varFind(basedir, text, vars, depth=0):
pass
elif
is_complex
and
text
[
end
]
==
'.'
:
if
brace_level
==
1
:
space
=
_varFindLimitSpace
(
basedir
,
vars
,
space
,
text
[
part_start
:
end
],
depth
)
space
=
_varFindLimitSpace
(
basedir
,
vars
,
space
,
text
[
part_start
:
end
],
lookup_fatal
,
depth
)
part_start
=
end
+
1
else
:
# This breaks out of the loop on non-variable name characters
...
...
@@ -161,7 +161,11 @@ def _varFind(basedir, text, vars, depth=0):
args
=
varReplace
(
basedir
,
args
,
vars
,
depth
=
depth
+
1
,
expand_lists
=
True
)
instance
=
utils
.
plugins
.
lookup_loader
.
get
(
lookup_plugin_name
.
lower
(),
basedir
=
basedir
)
if
instance
is
not
None
:
replacement
=
instance
.
run
(
args
,
inject
=
vars
)
try
:
replacement
=
instance
.
run
(
args
,
inject
=
vars
)
except
errors
.
AnsibleError
:
if
not
lookup_fatal
:
replacement
=
None
else
:
replacement
=
None
return
{
'replacement'
:
replacement
,
'start'
:
start
,
'end'
:
end
}
...
...
@@ -170,10 +174,10 @@ def _varFind(basedir, text, vars, depth=0):
var_end
-=
1
if
text
[
var_end
]
!=
'}'
or
brace_level
!=
0
:
return
None
space
=
_varFindLimitSpace
(
basedir
,
vars
,
space
,
text
[
part_start
:
var_end
],
depth
)
space
=
_varFindLimitSpace
(
basedir
,
vars
,
space
,
text
[
part_start
:
var_end
],
lookup_fatal
,
depth
)
return
{
'replacement'
:
space
,
'start'
:
start
,
'end'
:
end
}
def
varReplace
(
basedir
,
raw
,
vars
,
depth
=
0
,
expand_lists
=
False
):
def
varReplace
(
basedir
,
raw
,
vars
,
lookup_fatal
=
True
,
depth
=
0
,
expand_lists
=
False
):
''' Perform variable replacement of $variables in string raw using vars dictionary '''
# this code originally from yum
...
...
@@ -183,7 +187,7 @@ def varReplace(basedir, raw, vars, depth=0, expand_lists=False):
done
=
[]
# Completed chunks to return
while
raw
:
m
=
_varFind
(
basedir
,
raw
,
vars
,
depth
)
m
=
_varFind
(
basedir
,
raw
,
vars
,
lookup_fatal
,
depth
)
if
not
m
:
done
.
append
(
raw
)
break
...
...
@@ -195,7 +199,7 @@ def varReplace(basedir, raw, vars, depth=0, expand_lists=False):
if
expand_lists
and
isinstance
(
replacement
,
(
list
,
tuple
)):
replacement
=
","
.
join
(
replacement
)
if
isinstance
(
replacement
,
(
str
,
unicode
)):
replacement
=
varReplace
(
basedir
,
replacement
,
vars
,
depth
=
depth
+
1
,
expand_lists
=
expand_lists
)
replacement
=
varReplace
(
basedir
,
replacement
,
vars
,
lookup_fatal
,
depth
=
depth
+
1
,
expand_lists
=
expand_lists
)
if
replacement
is
None
:
replacement
=
raw
[
m
[
'start'
]:
m
[
'end'
]]
...
...
@@ -206,38 +210,38 @@ def varReplace(basedir, raw, vars, depth=0, expand_lists=False):
return
''
.
join
(
done
)
def
template_ds
(
basedir
,
varname
,
vars
):
def
template_ds
(
basedir
,
varname
,
vars
,
lookup_fatal
=
True
):
''' templates a data structure by traversing it and substituting for other data structures '''
if
isinstance
(
varname
,
basestring
):
m
=
_varFind
(
basedir
,
varname
,
vars
)
m
=
_varFind
(
basedir
,
varname
,
vars
,
lookup_fatal
)
if
not
m
:
return
varname
if
m
[
'start'
]
==
0
and
m
[
'end'
]
==
len
(
varname
):
if
m
[
'replacement'
]
is
not
None
:
return
template_ds
(
basedir
,
m
[
'replacement'
],
vars
)
return
template_ds
(
basedir
,
m
[
'replacement'
],
vars
,
lookup_fatal
)
else
:
return
varname
else
:
return
template
(
basedir
,
varname
,
vars
)
return
template
(
basedir
,
varname
,
vars
,
lookup_fatal
)
elif
isinstance
(
varname
,
(
list
,
tuple
)):
return
[
template_ds
(
basedir
,
v
,
vars
)
for
v
in
varname
]
return
[
template_ds
(
basedir
,
v
,
vars
,
lookup_fatal
)
for
v
in
varname
]
elif
isinstance
(
varname
,
dict
):
d
=
{}
for
(
k
,
v
)
in
varname
.
iteritems
():
d
[
k
]
=
template_ds
(
basedir
,
v
,
vars
)
d
[
k
]
=
template_ds
(
basedir
,
v
,
vars
,
lookup_fatal
)
return
d
else
:
return
varname
def
template
(
basedir
,
text
,
vars
,
expand_lists
=
False
):
def
template
(
basedir
,
text
,
vars
,
lookup_fatal
=
True
,
expand_lists
=
False
):
''' run a text buffer through the templating engine until it no longer changes '''
try
:
text
=
text
.
decode
(
'utf-8'
)
except
UnicodeEncodeError
:
pass
# already unicode
text
=
varReplace
(
basedir
,
unicode
(
text
),
vars
,
expand_lists
=
expand_lists
)
text
=
varReplace
(
basedir
,
unicode
(
text
),
vars
,
lookup_fatal
=
lookup_fatal
,
expand_lists
=
expand_lists
)
return
text
class
_jinja2_vars
(
object
):
...
...
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