On 22. juli 2016 13:05, Chethan S wrote:
> I am in the process of developing a playbook to create VMs in VMware
> vCenter Server wherein I need to be able to name the VMs with incremental
> number suffixes - VM(x) becomes VM1, VM2. Since the number of VMs would be
> fixed, I intend to specify the number in the playbook itself.
>
> I'm assuming I need to specify the highlighted variable vmname (below)
> prior to the vsphere_guest module.
What you are looking for i loop, read all about it here
https://docs.ansible.com/ansible/playbooks_loops.html
> ---
> - name: Create VMs on VMware vCenter Server
> hosts: localhost
>
>
> tasks:
>
> - vsphere_guest:
> vcenter_hostname: "nameofhost"
> guest: "{{ vmname }}"
> from_template: yes
> template_src: "templatename"
> validate_certs: no
> esxi:
> datacenter: dcname
> hostname: hname
I whould do something like this.
*Inventory file:*
[myvms]
VM[1:20]
*Playbbook:*
---
- hosts: myvms
tasks:
- vsphere_guest:
vcenter_hostname: "nameofhost"
guest: "{{ item }}"
from_template: yes
template_src: "templatename"
validate_certs: no
esxi:
datacenter: dcname
hostname: hname
with_items: play_hosts
delegate_to: localhost
> I would also like to know which kind of editor you people use to write
> Ansible Playbooks.
vim with this plugin
https://github.com/pearofducks/ansible-vim
--
Kai Stian Olstad