Clarify lookup plugin TypeError recovery

Change the code and comments around recovering from a TypeError in
handling the return value from lookup plugins to make it clearer what
we're recovering from.
pull/35513/head
Toshio Kuratomi 7 years ago
parent 3729cc57d0
commit 3d614bfe84

@ -27,6 +27,7 @@ import pwd
import re
import time
from collections import Sequence
from functools import wraps
from io import StringIO
from numbers import Number
@ -635,7 +636,15 @@ class Templar:
try:
ran = UnsafeProxy(",".join(ran))
except TypeError:
if isinstance(ran, list) and len(ran) == 1:
# Lookup Plugins should always return lists. Throw an error if that's not
# the case:
if not isinstance(ran, Sequence):
raise AnsibleError("The lookup plugin '%s' did not return a list."
% name)
# The TypeError we can recover from is when the value *inside* of the list
# is not a string
if len(ran) == 1:
ran = wrap_var(ran[0])
else:
ran = wrap_var(ran)

Loading…
Cancel
Save