forked from rgl/ubuntu-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubuntu-vsphere.pkr.hcl
171 lines (150 loc) · 3.71 KB
/
ubuntu-vsphere.pkr.hcl
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
packer {
required_plugins {
# see https://github.com/hashicorp/packer-plugin-vsphere
vsphere = {
version = ">= 1.3.0"
source = "github.com/hashicorp/vsphere"
}
}
}
variable "disk_size" {
type = string
default = 8 * 1024
}
variable "version" {
type = string
}
variable "vsphere_host" {
type = string
default = env("GOVC_HOST")
}
variable "vsphere_username" {
type = string
default = env("GOVC_USERNAME")
}
variable "vsphere_password" {
type = string
default = env("GOVC_PASSWORD")
sensitive = true
}
variable "vsphere_esxi_host" {
type = string
default = env("VSPHERE_ESXI_HOST")
}
variable "vsphere_datacenter" {
type = string
default = env("GOVC_DATACENTER")
}
variable "vsphere_cluster" {
type = string
default = env("GOVC_CLUSTER")
}
variable "vsphere_datastore" {
type = string
default = env("GOVC_DATASTORE")
}
variable "vsphere_folder" {
type = string
default = env("VSPHERE_TEMPLATE_FOLDER")
}
variable "vsphere_network" {
type = string
default = env("VSPHERE_VLAN")
}
variable "vsphere_ip_wait_address" {
type = string
default = env("VSPHERE_IP_WAIT_ADDRESS")
description = "IP CIDR which guests will use to reach the host. see https://github.com/hashicorp/packer/blob/ff5b55b560095ca88421d3f1ad8b8a66646b7ab6/builder/vsphere/common/step_http_ip_discover.go#L32"
}
variable "vsphere_os_iso" {
type = string
default = env("VSPHERE_OS_ISO")
}
locals {
boot_command = [
"c<wait>",
"linux /casper/vmlinuz",
" net.ifnames=0",
" autoinstall",
"<enter><wait5s>",
"initrd /casper/initrd",
"<enter><wait5s>",
"boot",
"<enter><wait5s>",
]
}
source "vsphere-iso" "ubuntu-amd64" {
CPUs = 4
RAM = 2048
cd_label = "cidata"
cd_files = [
"tmp/vsphere-autoinstall-cloud-init-data/user-data",
"autoinstall-cloud-init-data/meta-data"
]
boot_command = local.boot_command
boot_wait = "5s"
convert_to_template = true
insecure_connection = true
vcenter_server = var.vsphere_host
username = var.vsphere_username
password = var.vsphere_password
vm_name = "ubuntu-${var.version}-amd64-vsphere"
datacenter = var.vsphere_datacenter
cluster = var.vsphere_cluster
host = var.vsphere_esxi_host
folder = var.vsphere_folder
datastore = var.vsphere_datastore
guest_os_type = "ubuntu64Guest"
ip_wait_address = var.vsphere_ip_wait_address
iso_paths = [
var.vsphere_os_iso
]
network_adapters {
network = var.vsphere_network
network_card = "vmxnet3"
}
storage {
disk_size = var.disk_size
disk_thin_provisioned = true
}
disk_controller_type = ["pvscsi"]
ssh_password = "vagrant"
ssh_username = "vagrant"
ssh_timeout = "60m"
shutdown_command = "sudo -S poweroff"
}
build {
sources = ["source.vsphere-iso.ubuntu-amd64"]
provisioner "shell" {
execute_command = "echo vagrant | sudo -S {{ .Vars }} bash {{ .Path }}"
scripts = [
"upgrade.sh",
]
}
provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
expect_disconnect = true
scripts = [
"reboot.sh",
]
}
provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
scripts = [
"provision-guest-additions.sh",
]
}
provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
expect_disconnect = true
scripts = [
"reboot.sh",
]
}
provisioner "shell" {
execute_command = "sudo -S {{ .Vars }} bash {{ .Path }}"
scripts = [
"provision.sh",
]
}
}