Here is an example of one of the scripts where I use this method of calling an item from a list where it works fine using the old $var syntax but fails when changing to the jinja2 style variables.
First I call the script from my main .yml file that is a bunch of includes
- include: vm_provision.yml server=
vcenter.mydomain.com username=
v...@mydomain.com vmhost=
esxi1.mydomain.com vmhost_destination=
esxi1.mydomain.com template='vm-ubuntu124apl-x' datastore='iSCSI-datastore-1' iteration=0
That in turn calls this script
---
#####################
#vm_provision.yml
#An ansible script to provision individual vms based on the parameters fed to the script.
#See start_provision.yml and script documentation for other required parameters.
#####################
- hosts: vmaservers
vars_files:
- server_name.yml
user: vi-admin
tasks:
- name: clone VM taking parameters from start_provision.yml and calling
vmprovision.pl on the vma server.
action: shell /home/vi-admin/bin/
vmprovision.pl --server {{ server }} --username {{ username }} --credstore ~/.credentials.xml --op clone --vmhost {{ vmhost }} --vmhost_destination {{ vmhost_destination }} --vmname {{ template }} --datastore {{ datastore }} --vmname_destination {{ servername[iteration] }}
I get back the error One or more undefined variables: 'list' object has no attribute '0'
server_name.yml is a list like this
---
# Server names to use for each VM
servername:
- "vm-testans-1"
- "vm-testans-2"
- "vm-testans-3"