Make more lookup plugins happy with newstyle variables. Not quite done, but this fixes up with_items/with_nested/file/fileglob.

This commit is contained in:
Michael DeHaan 2013-04-16 18:50:00 -04:00
commit c0f8af5202
6 changed files with 58 additions and 49 deletions

View file

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import ansible.utils.template as template
import ansible.utils as utils
from ansible.utils import safe_eval
import ansible.errors as errors
@ -46,28 +46,13 @@ class LookupModule(object):
# this code is common with 'items.py' consider moving to utils if we need it again
if isinstance(terms, basestring):
# someone did:
# with_items: alist
# OR
# with_items: {{ alist }}
if not '{' in terms and not '[' in terms:
terms = '{{ %s }}' % terms
terms = template.template(self.basedir, terms, inject)
if '{' or '[' in terms:
# Jinja2 already evaluated a variable to a list.
# Jinja2-ified list needs to be converted back to a real type
# TODO: something a bit less heavy than eval
terms = safe_eval(terms)
if not isinstance(terms, list):
raise errors.AnsibleError("a list is required for with_nested")
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
my_list = terms[:]
my_list.reverse()
result = []
if len(my_list) == 0:
raise errors.AnsibleError("with_nested requires at least one list")
raise errors.AnsibleError("with_nested requires at least one element in the nested list")
result = my_list.pop()
while len(my_list) > 0:
result2 = combine(result, my_list.pop())