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 
[email protected] 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"






-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/db641ee8-e4a6-4de4-b865-b85c12ea5c5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to