-
Notifications
You must be signed in to change notification settings - Fork 0
/
nso.pkr.hcl
164 lines (142 loc) · 4.19 KB
/
nso.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
# Creating a Cisco NSO VM image, mainly for CML2
variable "cpus" {
type = string
default = "2"
}
variable "disk_size" {
type = string
default = "4G"
}
variable "iso_checksum" {
type = string
# default = "sha256:38b82727bfc1b36d9784bf07b8368c1d777450e978837e1cd7fa32b31837e77c"
}
variable "iso_url" {
type = string
default = "http://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"
}
variable "memory" {
type = string
default = "2048M"
}
# Currently only used for local installs
variable "nso_install_directory" {
type = string
default = "/pkgs/nso-install"
}
variable "nso_install_type" {
type = string
default = "local"
validation {
condition = contains(["local", "system"], var.nso_install_type)
error_message = "NSO install type must be \"local\" or \"system\"."
}
}
variable "nso_java_opts" {
type = string
default = "-Xmx2G -Xms1G"
}
# Some NSO packages still require Java 8 (previous LTS release)
variable "nso_java_version" {
type = string
default = "11"
validation {
condition = contains(["8", "11"], var.nso_java_version)
error_message = "Java version for NSO must be \"8\" or \"11\"."
}
}
variable "nso_ned_list" {
type = list(string)
default = []
}
variable "nso_run_directory" {
type = string
default = "/home/ubuntu/ncs-run"
}
variable "nso_version" {
type = string
default = "5.4.3"
}
variable "ssh_password" {
type = string
default = "ubuntu"
}
variable "ssh_username" {
type = string
default = "ubuntu"
}
variable "update_os" {
type = string
default = "true"
}
variable "upload_directory" {
type = string
default = "/tmp"
}
variable "vm_name" {
type = string
default = "ubuntuNSO"
}
source "qemu" "build_nso" {
accelerator = "kvm"
cd_files = ["./isoData/build/*"]
cd_label = "cidata"
disk_compression = true
disk_image = true
disk_size = var.disk_size
format = "qcow2"
headless = true
# http_directory = "installResources"
iso_checksum = var.iso_checksum
iso_url = var.iso_url
output_directory = "output-${var.vm_name}-${var.nso_version}"
qemuargs = [
["-m", "${var.memory}"],
["-smp", "${var.cpus}"],
["-serial", "mon:stdio"]
]
ssh_clear_authorized_keys = true # This shouldn't be needed, but just in case...
ssh_password = var.ssh_password
ssh_port = 22
ssh_timeout = "300s"
ssh_username = var.ssh_username
use_default_display = true
vm_name = "${var.vm_name}-${var.nso_version}-${formatdate("YYYYMMDD", timestamp())}.qcow2"
}
build {
sources = ["source.qemu.build_nso"]
provisioner "file" {
destination = "${var.upload_directory}/"
source = "./installResources/requirements.txt"
}
provisioner "file" {
destination = "${var.upload_directory}/"
source = fileexists("./installResources/nso-${var.nso_version}.linux.x86_64.signed.bin") ? "./installResources/nso-${var.nso_version}.linux.x86_64.signed.bin" : "./installResources/nso-${var.nso_version}.linux.x86_64.installer.bin"
}
provisioner "file" {
destination = "${var.upload_directory}/"
sources = [for ned in var.nso_ned_list : "./installResources/${ned}"]
}
provisioner "shell" {
environment_vars = [
"INSTALL_DIR=${var.nso_install_directory}",
#"HTTP_URL=http://${build.PackerHTTPAddr}",
"NSO_INSTALL_TYPE=${var.nso_install_type}",
"NSO_JAVA_OPTS=${var.nso_java_opts}",
"NSO_JAVA_VERSION=${var.nso_java_version}",
"NSO_VER=${var.nso_version}",
"RUN_DIR=${var.nso_run_directory}",
"SSH_PASSWORD=${var.ssh_password}",
"SSH_USERNAME=${var.ssh_username}",
"UPDATE_OS=${var.update_os}",
"UPLOAD_DIR=${var.upload_directory}",
]
execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -S -E bash '{{ .Path }}'"
scripts = [
"scripts/updateOS.sh",
"scripts/packages.sh",
"scripts/installMain.sh",
"scripts/cleanup.sh"
]
}
}