Example playbook.
---
- hosts: localhost
tasks:
- name: test loop
vars:
users:
- user01
- user02
debug:
var: item
loop: " {{ users }}"
When running it, below errors will be printed out.
ASK [test loop] ***************************************************************
fatal: [localhost]: FAILED! => {"msg": "Invalid data passed to 'loop', it requires a list, got this instead: ['user01', 'user02']. Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup."}
The root cause is the space (marked as red background) before the jinja2 var.
With this space, " {{ users }}" is not a list any more.
So, be careful of extra spaces in your playbook!
No comments:
Post a Comment