Last active
June 30, 2016 20:19
-
-
Save gkhays/8732d4fbb367d6b42f33ba6042f0787b to your computer and use it in GitHub Desktop.
vsphere_guest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# 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