forked from GastroGee/packer-vmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.hcl
133 lines (117 loc) · 3.89 KB
/
example.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
variable "cluster" {
type = string
default = "dev"
}
variable "datastore" {
type = string
default = "dev"
}
variable "folder" {
type = string
default = "dev"
}
variable "iso_checksum" {
type = string
default = "sha256:f11bda2f2caed8f420802b59f382c25160b114ccc665dbac9c5046e7fceaced2"
}
variable "iso_url" {
type = string
default = "https://cdimage.ubuntu.com/ubuntu-legacy-server/releases/20.04/release/ubuntu-20.04.1-legacy-server-amd64.iso"
}
variable "network" {
type = string
default = "dev"
}
variable "resource_pool" {
type = string
default = "dev"
}
variable "vcenter_password" {
type = string
default = "gastrolee"
}
variable "vcenter_server" {
type = string
default = "https://gastrollc-esx.corp.gastro.com"
}
variable "vcenter_username" {
type = string
default = "gastro"
}
variable "vm_name" {
type = string
default = "ubuntu-2004-template"
}
source "vsphere-iso" "Dev" {
CPUs = "4"
RAM = "4096"
RAM_reserve_all = true
boot_command = ["<esc><wait>", "<esc><wait>", "<enter><wait>", "/install/vmlinuz<wait>", " initrd=/install/initrd.gz", " priority=critical", " locale=en_US", " file=/media/preseed.cfg", "<enter>"]
boot_order = "disk,cdrom"
convert_to_template = "true"
disk_controller_type = ["pvscsi", "pvscsi"]
floppy_files = ["http/preseed.cfg"]
guest_os_type = "ubuntu64Guest"
insecure_connection = "true"
iso_checksum = var.iso_checksum
iso_url = var.iso_url
cluster = var.cluster
datastore = var.datastore
folder = var.folder
configuration_parameters = {
"disk.EnableUUID" = true
}
network_adapters {
network = var.network
network_card = "vmxnet3"
}
password = var.vcenter_password
resource_pool = var.resource_pool
ssh_password = var.ssh_password
ssh_username = var.ssh_username
storage {
disk_controller_index = 0
disk_size = 85000
disk_thin_provisioned = true
}
storage {
disk_controller_index = 1
disk_size = 100000
disk_thin_provisioned = true
}
username = var.vcenter_username
vcenter_server = var.vcenter_server
vm_name = "Ubuntu-2004-Template"
}
build {
sources = ["source.vsphere-iso.Dev"]
provisioner "shell" {
inline = ["echo 'template build - start configuring ssh access'"]
}
provisioner "shell" {
inline = ["mkdir -p /home/${var.ssh_username}/.ssh"]
}
provisioner "shell" {
inline = ["sudo chown -R ${var.ssh_username}:${var.ssh_username} /home/${var.ssh_username}", "sudo chmod go-w /home/${var.ssh_username}/", "sudo chmod 700 /home/${var.ssh_username}/.ssh"]
}
provisioner "shell" {
inline = ["echo 'template build - disable ssh password access'"]
}
provisioner "shell" {
inline = ["sudo su root -c \"sed '/ChallengeResponseAuthentication/d' -i /etc/ssh/sshd_config | sudo bash\"", "sudo su root -c \"sed '/PasswordAuthentication/d' -i /etc/ssh/sshd_config | sudo bash\"", "sudo su root -c \"sed '/UsePAM/d' -i /etc/ssh/sshd_config | sudo bash\"", "sudo su root -c \"echo >> /etc/ssh/sshd_config | sudo bash\"", "sudo su root -c \"echo 'ChallengeResponseAuthentication no' >> /etc/ssh/sshd_config | sudo bash\"", "sudo su root -c \"echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config | sudo bash\""]
}
provisioner "shell" {
inline = ["echo 'template build - starting configuration by deploying base packages'"]
}
provisioner "shell" {
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'"
expect_disconnect = true
scripts = ["scripts/base.sh", "scripts/installs.sh"]
}
provisioner "shell" {
inline = [
"sudo bash -c 'echo -n /etc/machine-id'",
"sudo rm /var/lib/dbus/machine-id",
"sudo ln -s /etc/machine-id /var/lib/dbus/machine-id"
]
}