Skip to content

Instantly share code, notes, and snippets.

@phips
Created July 10, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save phips/596955ae5967acf317ca to your computer and use it in GitHub Desktop.
Save phips/596955ae5967acf317ca to your computer and use it in GitHub Desktop.
vsphere_guest
---
# vim: set ft=ansible et ts=2 sw=2:
#
# Create a new VM to kickstart install
- hosts: vmcreate
gather_facts: false
connection: local
vars:
vcenter_hostname: esx1.box
esxhost: esx1.box
vcenter_folder: "New Build"
datastore: datastore1
datacenter: ha-datacenter
network: "VMnetwork"
state: powered_on
disksize: 20
mem: 1024
cpus: 1
notes: Created by Ansible
tasks:
- name: Check for required variables
fail: msg="Must pass name to -e"
when: name is not defined
- name: Check for permission to run
assert:
that: allowed_to_deploy is true
- 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 a new VM
vsphere_guest:
vcenter_hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
guest: "{{ name }}"
state: "{{ state }}"
vm_extra_config:
notes: "{{ notes }}"
vm_disk:
disk1:
size_gb: "{{ disksize }}"
type: thin
datastore: "{{ datastore }}"
vm_nic:
nic1:
type: vmxnet3
network: "{{ network }}"
network_type: standard
# nic2:
# type: vmxnet3
# network: "Kickstart"
# network_type: standard
vm_hardware:
memory_mb: "{{ mem }}"
num_cpus: "{{ cpus }}"
osid: centos64Guest
scsi: paravirtual
vm_cdrom:
type: iso
iso_path: "/ISOs/{{ iso | default('CentOS-6.6-x86_64-bin-DVD1.iso') }}"
vm_hw_version: vmx-08
esxi:
datacenter: "{{ datacenter }}"
hostname: "{{ esxhost }}"
- name: Gather VM facts
vsphere_guest:
vcenter_hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_pass }}"
guest: "{{ name }}"
vmware_guest_facts: yes
register: newvm
tags: mac
- name: Report VM MAC address
debug: msg="{{ newvm.ansible_facts.hw_eth0.macaddress_dash }}"
tags: mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment