1+ # Generated by packer-kvm/build-packer-templates.yaml
2+
3+ packer {
4+ required_plugins {
5+ qemu = {
6+ version = " ~> 1"
7+ source = " github.com/hashicorp/qemu"
8+ }
9+ ansible = {
10+ version = " >= 1.1.2"
11+ source = " github.com/hashicorp/ansible"
12+ }
13+ }
14+ }
15+
16+ variable "cpu" {
17+ type = string
18+ default = " 2"
19+ }
20+
21+ variable "destination_server" {
22+ type = string
23+ default = " download.goffinet.org"
24+ }
25+
26+ variable "disk_size" {
27+ type = string
28+ default = " 40000"
29+ }
30+
31+ variable "headless" {
32+ type = string
33+ default = " true"
34+ }
35+
36+ variable "iso_checksum" {
37+ type = string
38+ default = " file:http://releases.ubuntu.com/20.04/SHA256SUMS"
39+ }
40+
41+ variable "iso_url" {
42+ type = string
43+ default = " http://releases.ubuntu.com/20.04/ubuntu-20.04.6-live-server-amd64.iso"
44+ }
45+
46+ variable "name" {
47+ type = string
48+ default = " ubuntu"
49+ }
50+
51+ variable "ram" {
52+ type = string
53+ default = " 2048"
54+ }
55+
56+ variable "ssh_password" {
57+ type = string
58+ default = " ubuntu"
59+ }
60+
61+ variable "ssh_username" {
62+ type = string
63+ default = " ubuntu"
64+ }
65+
66+ variable "version" {
67+ type = string
68+ default = " 2004"
69+ }
70+
71+ source "qemu" "ubuntu2004" {
72+ accelerator = " kvm"
73+ boot_command = [" <enter><enter><f6><esc><wait>" , " <bs><bs><bs><bs>" , " autoinstall net.ifnames=0 biosdevname=0 ip=dhcp ipv6.disable=1 ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/http/${ var . name } ${ var . version } / " , " --- <enter>" ]
74+ disk_cache = " none"
75+ disk_compression = true
76+ disk_discard = " unmap"
77+ disk_interface = " virtio"
78+ disk_size = var. disk_size
79+ format = " qcow2"
80+ headless = var. headless
81+ http_directory = " ."
82+ iso_checksum = var. iso_checksum
83+ iso_url = var. iso_url
84+ net_device = " virtio-net"
85+ output_directory = " artifacts/qemu/${ var . name } ${ var . version } "
86+ qemu_binary = " /usr/bin/qemu-system-x86_64"
87+ qemuargs = [[" -m" , " ${ var . ram } M" ], [" -smp" , " ${ var . cpu } " ], [" -cpu" , " host" ]]
88+ shutdown_command = " sudo /usr/sbin/shutdown -h now"
89+ ssh_password = var. ssh_password
90+ ssh_username = var. ssh_username
91+ boot_wait = " 10s"
92+ ssh_handshake_attempts = 500
93+ ssh_timeout = " 45m"
94+ ssh_wait_timeout = " 45m"
95+ host_port_max = 2229
96+ host_port_min = 2222
97+ http_port_max = 10089
98+ http_port_min = 10082
99+ }
100+
101+ build {
102+ sources = [" source.qemu.ubuntu2004" ]
103+
104+ provisioner "shell" {
105+ execute_command = " {{ .Vars }} sudo -E bash '{{ .Path }}'"
106+ inline = [" sudo apt-get update" , " sudo apt-get -y install software-properties-common" , " sudo apt-add-repository --yes --update ppa:ansible/ansible" , " sudo apt update" , " sudo apt -y install ansible" ]
107+ }
108+
109+ provisioner "ansible-local" {
110+ playbook_dir = " ansible"
111+ playbook_file = " ansible/playbook.yml"
112+ }
113+
114+ post-processor "shell-local" {
115+ environment_vars = [" IMAGE_NAME=${ var . name } " , " IMAGE_VERSION=${ var . version } " , " DESTINATION_SERVER=${ var . destination_server } " ]
116+ script = " scripts/push-image.sh"
117+ }
118+ }
0 commit comments