Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
55 lines (49 sloc) 1.47 KB
---
# vim: set ft=ansible et ts=2 sw=2:
#
# Create a new VM from a template
- name: VM from template
hosts: vmcreate
gather_facts: false
connection: local
vars:
vcenter_hostname: vcsa.box
esxhost: esx1.box
datastore: datastore1
network: "VMnetwork"
vmtemplate: CentOS7-Base
vmcluster: LAN
notes: Created by Ansible
dumpfacts: False
tasks:
- name: Check for required variables
fail: msg="Must pass name and group to -e"
when: name is not defined or group is not defined
- name: Check for vSphere access parameters
fail: msg="Must set vcenter_user and vcenter_pass in a Vault"
when: (vcenter_user is not defined) or (vcenter_pass is not defined)
- name: Create VM from template
vmware_guest:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
esxi_hostname: "{{ esxhost }}"
datacenter: BOX
name: "{{ name }}"
template: "{{ vmtemplate }}"
disk:
- size_gb: "{{ disk_size | default(20) }}"
type: thin
datastore: "{{ datastore }}"
nic:
- type: vmxnet3
network: "{{ network }}"
hardware:
memory_mb: "{{ vm_memory | default(1024) }}"
wait_for_ip_address: True
state: present
register: newvm
- name: IP address info
debug:
msg: "{{ newvm.instance.ipv4 }} {{ name }}"
You can’t perform that action at this time.