ubuntu-server-jammy-docker.pkr.hcl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. # Ubuntu Server jammy
  2. # ---
  3. # Packer Template to create an Ubuntu Server (jammy) on Proxmox
  4. # Variable Definitions
  5. variable "proxmox_api_url" {
  6. type = string
  7. }
  8. variable "proxmox_api_token_id" {
  9. type = string
  10. }
  11. variable "proxmox_api_token_secret" {
  12. type = string
  13. sensitive = true
  14. }
  15. # Resource Definiation for the VM Template
  16. source "proxmox" "ubuntu-server-jammy" {
  17. # Proxmox Connection Settings
  18. proxmox_url = "${var.proxmox_api_url}"
  19. username = "${var.proxmox_api_token_id}"
  20. token = "${var.proxmox_api_token_secret}"
  21. # (Optional) Skip TLS Verification
  22. # insecure_skip_tls_verify = true
  23. # VM General Settings
  24. node = "your-proxmox-node"
  25. vm_id = "100"
  26. vm_name = "ubuntu-server-jammy"
  27. template_description = "Ubuntu Server jammy Image"
  28. # VM OS Settings
  29. # (Option 1) Local ISO File
  30. # iso_file = "local:iso/ubuntu-22.04-live-server-amd64.iso"
  31. # - or -
  32. # (Option 2) Download ISO
  33. # iso_url = "https://releases.ubuntu.com/22.04/ubuntu-22.04-live-server-amd64.iso"
  34. # iso_checksum = "84aeaf7823c8c61baa0ae862d0a06b03409394800000b3235854a6b38eb4856f"
  35. iso_storage_pool = "local"
  36. unmount_iso = true
  37. # VM System Settings
  38. qemu_agent = true
  39. # VM Hard Disk Settings
  40. scsi_controller = "virtio-scsi-pci"
  41. disks {
  42. disk_size = "20G"
  43. format = "qcow2"
  44. storage_pool = "local-lvm"
  45. storage_pool_type = "lvm"
  46. type = "virtio"
  47. }
  48. # VM CPU Settings
  49. cores = "1"
  50. # VM Memory Settings
  51. memory = "2048"
  52. # VM Network Settings
  53. network_adapters {
  54. model = "virtio"
  55. bridge = "vmbr0"
  56. firewall = "false"
  57. }
  58. # VM Cloud-Init Settings
  59. cloud_init = true
  60. cloud_init_storage_pool = "local-lvm"
  61. # PACKER Boot Commands
  62. boot_command = [
  63. "<esc><wait>",
  64. "e<wait>",
  65. "<down><down><down><end>",
  66. "<bs><bs><bs><bs><wait>",
  67. "autoinstall ds=nocloud-net\\;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ ---<wait>",
  68. "<f10><wait>"
  69. ]
  70. boot = "c"
  71. boot_wait = "5s"
  72. # PACKER Autoinstall Settings
  73. http_directory = "http"
  74. # (Optional) Bind IP Address and Port
  75. # http_bind_address = "0.0.0.0"
  76. # http_port_min = 8802
  77. # http_port_max = 8802
  78. ssh_username = "your-user-name"
  79. # (Option 1) Add your Password here
  80. # ssh_password = "your-password"
  81. # - or -
  82. # (Option 2) Add your Private SSH KEY file here
  83. # ssh_private_key_file = "~/.ssh/id_rsa"
  84. # Raise the timeout, when installation takes longer
  85. ssh_timeout = "20m"
  86. }
  87. # Build Definition to create the VM Template
  88. build {
  89. name = "ubuntu-server-jammy"
  90. sources = ["source.proxmox.ubuntu-server-jammy"]
  91. # Provisioning the VM Template for Cloud-Init Integration in Proxmox #1
  92. provisioner "shell" {
  93. inline = [
  94. "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
  95. "sudo rm /etc/ssh/ssh_host_*",
  96. "sudo truncate -s 0 /etc/machine-id",
  97. "sudo apt -y autoremove --purge",
  98. "sudo apt -y clean",
  99. "sudo apt -y autoclean",
  100. "sudo cloud-init clean",
  101. "sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg",
  102. "sudo rm -f /etc/netplan/00-installer-config.yaml",
  103. "sudo sync"
  104. ]
  105. }
  106. # Provisioning the VM Template for Cloud-Init Integration in Proxmox #2
  107. provisioner "file" {
  108. source = "files/99-pve.cfg"
  109. destination = "/tmp/99-pve.cfg"
  110. }
  111. # Provisioning the VM Template for Cloud-Init Integration in Proxmox #3
  112. provisioner "shell" {
  113. inline = [ "sudo cp /tmp/99-pve.cfg /etc/cloud/cloud.cfg.d/99-pve.cfg" ]
  114. }
  115. # Provisioning the VM Template with Docker Installation #4
  116. provisioner "shell" {
  117. inline = [
  118. "sudo apt-get install -y ca-certificates curl gnupg lsb-release",
  119. "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg",
  120. "echo \"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null",
  121. "sudo apt-get -y update",
  122. "sudo apt-get install -y docker-ce docker-ce-cli containerd.io"
  123. ]
  124. }
  125. }