forked from phips/ansible-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm_clone.yml
54 lines (49 loc) · 1.47 KB
/
vm_clone.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
---
# 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 }}"