-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatevm.yml
95 lines (88 loc) · 2.85 KB
/
createvm.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
# playbook to create a VM based on a VMware template
- name: clone a new vm from a vmware template
hosts: localhost
gather_facts: no
vars_files:
- createvm_vars.yml
tasks:
- name: clone vm
local_action:
module: vsphere
host: "{{ vcenter }}"
login: "{{ login }}"
password: "{{ password }}"
checkssl: no
guest:
name: "{{ newvmhostname }}"
state: present
folder: "{{ folder }}"
clone_from: "centos{{ elver }}"
spec:
type: VirtualMachineCloneSpec
value:
config:
VirtualMachineConfigSpec:
name: "{{ newvmhostname }}"
memoryMB: "{{ mbram }}"
numCPUs: "{{ numcpus }}"
customization:
CustomizationSpec:
globalIPSettings:
CustomizationGlobalIPSettings:
dnsServerList: "{{ nameserver }}"
dnsSuffixList: "{{ domain }}"
identity:
CustomizationLinuxPrep:
domain: "{{ domain }}"
hostName:
CustomizationFixedName:
name: "{{ newvmhostname }}"
nicSettingMap:
- CustomizationAdapterMapping:
adapter:
CustomizationIPSettings:
ip:
CustomizationDhcpIpGenerator: {}
location:
VirtualMachineRelocateSpec:
pool:
ManagedObjectReference:
type: ResourcePool
name: Resources
template: False
- name: power on vm
local_action:
module: vsphere
host: "{{ vcenter }}"
login: "{{ login }}"
password: "{{ password }}"
guest:
name: "{{ newvmhostname }}"
state: running
- name: wait for vm to come up and be accessible
local_action:
module: wait_for
host: "{{ newvmhostname }}.{{ domain }}"
state: started
port: 22
timeout: 300
- name: bootstrap basic config to prepare for puppet
hosts: "{{ newvmhostname }}.{{ domain }}"
remote_user: root
vars_files:
- createvm_vars.yml
tasks:
# this shouldn't be necessary, but just in case the is behind our current patching baseline
- name: update all packages
yum:
name: "*"
state: latest
# our image is an unmodified minimal install. this should be moved to puppet,but we need
# to install the puppet rpm using this method anyway
- name: install base set of packages
yum:
state: present
name: "{{ item }}"
with_items:
- "{{ packages }}"