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
2673eb0a
Commit
2673eb0a
authored
Aug 03, 2015
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to fail on undefined variables to listify
And use it in the call to get the loop items for a task.
parent
a586c749
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
7 deletions
+14
-7
lib/ansible/executor/task_executor.py
+1
-1
lib/ansible/plugins/lookup/nested.py
+11
-4
lib/ansible/utils/listify.py
+2
-2
No files found.
lib/ansible/executor/task_executor.py
View file @
2673eb0a
...
...
@@ -143,7 +143,7 @@ class TaskExecutor:
items
=
None
if
self
.
_task
.
loop
and
self
.
_task
.
loop
in
lookup_loader
:
loop_terms
=
listify_lookup_plugin_terms
(
terms
=
self
.
_task
.
loop_args
,
variables
=
self
.
_job_vars
,
loader
=
self
.
_loader
)
loop_terms
=
listify_lookup_plugin_terms
(
terms
=
self
.
_task
.
loop_args
,
variables
=
self
.
_job_vars
,
loader
=
self
.
_loader
,
fail_on_undefined
=
True
)
items
=
lookup_loader
.
get
(
self
.
_task
.
loop
,
loader
=
self
.
_loader
)
.
run
(
terms
=
loop_terms
,
variables
=
self
.
_job_vars
)
return
items
...
...
lib/ansible/plugins/lookup/nested.py
View file @
2673eb0a
...
...
@@ -17,22 +17,29 @@
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
from
ansible.errors
import
AnsibleError
from
jinja2.exceptions
import
UndefinedError
from
ansible.errors
import
AnsibleError
,
AnsibleUndefinedVariable
from
ansible.plugins.lookup
import
LookupBase
from
ansible.utils.listify
import
listify_lookup_plugin_terms
class
LookupModule
(
LookupBase
):
def
__lookup_variabless
(
self
,
terms
,
variables
):
def
__lookup_variables
(
self
,
terms
,
variables
):
foo
=
variables
.
copy
()
foo
.
pop
(
'vars'
)
results
=
[]
for
x
in
terms
:
intermediate
=
listify_lookup_plugin_terms
(
x
,
variables
,
loader
=
self
.
_loader
)
try
:
intermediate
=
listify_lookup_plugin_terms
(
x
,
variables
,
loader
=
self
.
_loader
,
fail_on_undefined
=
True
)
except
UndefinedError
,
e
:
raise
AnsibleUndefinedVariable
(
"One of the nested variables was undefined. The error was:
%
s"
%
e
)
results
.
append
(
intermediate
)
return
results
def
run
(
self
,
terms
,
variables
=
None
,
**
kwargs
):
terms
=
self
.
__lookup_variables
s
(
terms
,
variables
)
terms
=
self
.
__lookup_variables
(
terms
,
variables
)
my_list
=
terms
[:]
my_list
.
reverse
()
...
...
lib/ansible/utils/listify.py
View file @
2673eb0a
...
...
@@ -26,14 +26,14 @@ from ansible.template.safe_eval import safe_eval
__all__
=
[
'listify_lookup_plugin_terms'
]
#FIXME: probably just move this into lookup plugin base class
def
listify_lookup_plugin_terms
(
terms
,
variables
,
loader
):
def
listify_lookup_plugin_terms
(
terms
,
variables
,
loader
,
fail_on_undefined
=
False
):
if
isinstance
(
terms
,
basestring
):
stripped
=
terms
.
strip
()
templar
=
Templar
(
loader
=
loader
,
variables
=
variables
)
#FIXME: warn/deprecation on bare vars in with_ so we can eventually remove fail on undefined override
terms
=
templar
.
template
(
terms
,
convert_bare
=
True
,
fail_on_undefined
=
False
)
terms
=
templar
.
template
(
terms
,
convert_bare
=
True
,
fail_on_undefined
=
fail_on_undefined
)
#TODO: check if this is needed as template should also return correct type already
terms
=
safe_eval
(
terms
)
...
...
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