-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathubuntu.pkr.hcl
185 lines (174 loc) · 7.34 KB
/
ubuntu.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
packer {
required_version = ">= 1.7.0"
required_plugins {
ansible = {
version = ">= 1.1.0"
source: "github.com/hashicorp/ansible"
}
vmware = {
version = ">= 1.0.9"
source = "github.com/hashicorp/vmware"
}
vsphere = {
version = ">= 1.2.1"
source: "github.com/hashicorp/vsphere"
}
vagrant = {
source = "github.com/hashicorp/vagrant"
version = ">= 1.0.3"
}
}
}
locals {
http_directory = "${path.root}/http"
}
source "hyperv-iso" "ubuntu" {
boot_command = ["<esc><wait>", "c<wait>", "set gfxpayload=keep<wait><enter>", "linux /casper/vmlinuz autoinstall ds=\"nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/\"<wait><enter>", "initrd /casper/initrd<wait><enter>", "boot<enter>"]
boot_wait = "10s"
communicator = "ssh"
cpus = "${var.cpus}"
disk_size = "${var.disk_size}"
enable_secure_boot = false
generation = "${var.hyperv_generation}"
http_directory = "./http"
iso_checksum = "${var.iso_checksum}"
iso_url = "${var.iso_url}"
ram_gb = "${var.ram_mb} / 1024"
output_directory = "${var.build_directory}/packer-${var.template}-hyperv"
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
ssh_password = "vagrant"
ssh_port = 22
ssh_timeout = "1h"
ssh_username = "vagrant"
switch_name = "${var.hyperv_switch}"
vm_name = "${var.template}"
}
source "virtualbox-iso" "ubuntu" {
boot_command = ["<esc><wait>", "c<wait>", "set gfxpayload=keep<wait><enter>", "linux /casper/vmlinuz autoinstall ds=\"nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/\"<wait><enter>", "initrd /casper/initrd<wait><enter>", "boot<enter>"]
boot_wait = "4s"
cpus = "${var.cpus}"
disk_size = "${var.disk_size}"
guest_os_type = "Ubuntu_64"
hard_drive_interface = "sata"
headless = "${var.headless}"
http_directory = "./http"
iso_checksum = "${var.iso_checksum}"
iso_url = "${var.iso_url}"
memory = "${var.ram_mb}"
output_directory = "${var.output_directory}/virtualbox"
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
ssh_handshake_attempts = 20
ssh_password = "vagrant"
ssh_port = 22
ssh_timeout = "1h"
ssh_username = "vagrant"
vboxmanage = [["modifyvm", "{{ .Name }}", "--clipboard-mode", "bidirectional"], ["modifyvm", "{{ .Name }}", "--graphicscontroller", "vmsvga"], ["modifyvm", "{{ .Name }}", "--accelerate3d", "on"], ["storageattach", "{{ .Name }}", "--storagectl", "SATA Controller", "--port", "1", "--device", "0", "--type", "dvddrive", "--medium", "emptydrive"]]
virtualbox_version_file = ".vbox_version"
vm_name = "${var.vagrant_box}"
}
source "vsphere-iso" "ubuntu" {
boot_command = var.bootcommand
vcenter_server = var.vmware_center_host
host = var.vmware_center_esxi_host
username = "${var.vmware_center_username}"
password = "${var.vmware_center_password}"
insecure_connection = false
datacenter = var.vmware_center_datacenter
datastore = var.vmware_center_datastore
cluster = var.vmware_center_cluster_name
http_port_max = 65535
http_port_min = 49152
convert_to_template = true
CPUs = var.cpus
disk_controller_type = ["pvscsi"]
storage {
disk_size = "${var.disk_size}"
disk_thin_provisioned = true
}
guest_os_type = "ubuntu64Guest"
http_directory = "${local.http_directory}"
iso_checksum = var.iso_checksum
iso_url = var.iso_url
RAM = var.ram_mb
shutdown_command = "echo 'vagrant' | sudo -S /sbin/halt -h -p"
ssh_password = "vagrant"
ssh_port = 22
ssh_timeout = "10000s"
ssh_username = "vagrant"
vm_name = var.vmware_center_vm_name
network_adapters {
network = "${var.vmware_center_vm_network}"
network_card = "vmxnet3"
}
}
source "vmware-iso" "ubuntu" {
boot_command = ["<esc><wait>", "c<wait>", "set gfxpayload=keep<wait><enter>", "linux /casper/vmlinuz autoinstall ds=\"nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/\"<wait><enter>", "initrd /casper/initrd<wait><enter>", "boot<enter>"]
boot_wait = "4s"
cpus = "${var.cpus}"
disk_size = "${var.disk_size}"
guest_os_type = "ubuntu-64"
headless = "${var.headless}"
http_directory = "./http"
iso_checksum = "${var.iso_checksum}"
iso_url = "${var.iso_url}"
memory = "${var.ram_mb}"
network_adapter_type = "VMXNET3"
output_directory = "${var.output_directory}/vmware"
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
ssh_password = "vagrant"
ssh_port = 22
ssh_timeout = "1h"
ssh_username = "vagrant"
tools_upload_flavor = ""
vm_name = "${var.vagrant_box}"
vmx_data = {
"cpuid.coresPerSocket" = "1"
"disk.EnableUUID" = "TRUE"
"ethernet0.pciSlotNumber" = "32"
"virtualHW.version" = "13"
}
// vmx_remove_ethernet_interfaces = "${var.vmx_remove_ethernet_interfaces}"
}
# a build block invokes sources and runs provisioning steps on them. The
# documentation for build blocks can be found here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
build {
sources = [
// "source.hyperv-iso.ubuntu",
// "source.virtualbox-iso.ubuntu",
//"source.vmware-iso.ubuntu",
"source.vsphere-iso.ubuntu"
]
provisioner "ansible" {
playbook_file = "./ansible_provisioning/playbook.yaml"
galaxy_file = "./ansible_provisioning/requirements.yaml"
roles_path = "./ansible_provisioning/roles"
galaxy_force_install = true
user = "vagrant"
use_proxy = false
extra_arguments = [
"-v",
"-e", "ansible_ssh_password=vagrant"
]
}
post-processors {
post-processor "vagrant" {
except = ["vsphere-iso.ubuntu"]
output = "${var.output_directory}/${ var.vagrant_box }.${ replace(replace(replace(source.type, "-iso", ""), "hyper-v", "hyperv"), "vmware", "vmware_desktop") }.box"
}
# Once box has been created, upload it to Artifactory
post-processor "shell-local" {
except = ["vsphere-iso.ubuntu"]
command = join(" ", [
"jf rt upload",
"--target-props \"box_name=${ var.vagrant_box };box_provider=${replace(replace(replace(source.type, "-iso", ""), "hyper-v", "hyperv"), "vmware", "vmware_desktop")};box_version=${ formatdate("YYYYMMDD", timestamp()) }.0\"",
"--retries 10",
"--access-token ${ var.artifactory_api_key }",
"--user ${ var.artifactory_username }",
"--url \"https://artifactory.ccdc.cam.ac.uk/artifactory\"",
"${var.output_directory}/${var.vagrant_box}.${replace(replace(replace(source.type, "-iso", ""), "hyper-v", "hyperv"), "vmware", "vmware_desktop")}.box",
"ccdc-vagrant-repo/${var.vagrant_box}.${formatdate("YYYYMMDD", timestamp())}.0.${replace(replace(replace(source.type, "-iso", ""), "hyper-v", "hyperv"), "vmware", "vmware_desktop")}.box"
])
}
}
}