Skip to content

Instantly share code, notes, and snippets.

@pmeinhardt
Created August 3, 2016 08:23
Show Gist options
  • Save pmeinhardt/3b438337938151d0ed7fb53a4e34ceff to your computer and use it in GitHub Desktop.
Save pmeinhardt/3b438337938151d0ed7fb53a4e34ceff to your computer and use it in GitHub Desktop.
Create vSphere virtual machines using Ansible
---
- hosts: esxi
connection: local
remote_user: root
become: no
vars_prompt:
- name: hostname
prompt: "Enter the VMware ESXi hostname"
default: "esxi.fritz.box"
private: no
- name: username
prompt: "Enter the VMware ESXi username"
default: "root"
private: no
- name: password
prompt: "Enter the VMware ESXi password"
private: yes
vars:
vms:
- name: "Windows 7 Internet Explorer 10"
notes: "Created using Ansible"
osid: windows7_64Guest
scsi: paravirtual
memory: 4096
cpus: 2
tasks:
- name: create vms
vsphere_guest:
vcenter_hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
guest: "{{ item.name }}"
state: powered_on
vm_extra_config:
notes: "{{ item.notes }}"
vm_hardware:
memory_mb: "{{ item.memory }}"
num_cpus: "{{ item.cpus }}"
osid: "{{ item.osid }}"
scsi: "{{ item.scsi }}"
vm_disk:
disk1:
size_gb: 64
type: thin
datastore: "datastore1"
vm_nic:
nic1:
type: vmxnet3
network: "VM Network"
network_type: standard
esxi:
datacenter: "ha-datacenter"
hostname: "{{ hostname }}"
validate_certs: no
with_items:
- "{{ vms }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment