I was looking at that and have ried a few things without success.
Are you able to see if im on the right track here?
I have create a file called ‘hostnames’ which is located in a sub directory (files) where the playbook is, and have included the vm names in that file:
---
serverlist:
- server1
- server2
I have then added the ‘with_items’ and variable ‘serverlist’. But i think I may be getting a bit confused through?
Im I completely off track here?
I can see a couple of issues in your playbook which might unstick you…
First the with_items needs to go right at the end of all of the parameters for the vsphere guest module - at the moment you have the exsi parameter after the with_items.
Also there’s a missing double quote at the end of the with items line:
The other thing is actually getting your file containing the serverlist variable loaded into Ansible. There’s at least a couple of ways of doing this - either do an include_vars: file_containing_vars.yml at the top of your playbook, or you can pass in the contents of a yaml file on the command line using -e @/path/to/yaml/file.yml. Not sure what is going to suit your usage best
I’m not very familiar with that module, but the iterator on a loop (which is effectively what you have with the with_items stanza) is “item" and not “list”
What is happening now is when I run the playbook it is creating one VM in vSphere called “files/hostnames”??
So its as if the playbook is looking at, with_items: “{{ serverlist }}”, and then seeing the variable, serverlist: files/hostnames, and then creating a VM with that name. Its not looking into the ‘hostnames’ file and creating the multiple VM’s in that file??
rather than naming the file you want to load in the vars: section of your playbook - vars is just for variables you want to declare within the playbook itself.
Ansible is pretty flexible, if that suits your need then that’s good enough.
If you use a role you can do away with the include_vars but putting your serverlist var in a vars/main.yml under your role. Roles are nice as they can magically load lots of stuff like variables - see http://docs.ansible.com/ansible/playbooks_roles.html#roles