16/12/2024

Packer-2

Öncelikle calisan boot command kismi ubuntu 22.04 icin

 # PACKER Boot Commands
  boot_command = ["<wait>e<wait>","<down><down><down><end>","<bs><bs><bs><bs><wait>","autoinstall quiet",  " --- ","<down><down>","<enter>","boot","<F10>"]
  boot      = "c"
  boot_wait = "2s"

Packer kurulumu yaptiktan sonra template i normal VM olarak calistiriyor ve bu kisim da pkr-sources.pkr.hcl dosyasinda build kisminda geciyor.

build {
  name = "Cans-ubuntu1"
  sources = [
    "source.proxmox-iso.Cans-ubuntu1"
  ]

  provisioner "shell" {
    inline = ["echo 'Hello World'"]
  }
  provisioner "shell" {
    scripts = [
      "./scripts/prepare.sh"
        ]
    }
  provisioner "ansible" {
    playbook_file = "./ansible/playbook.yml"
  }
}

the sources kismi dosyanin ilk kismini isaret ediyor ve sonra provisioner lar basliyor.
and görüldügü gibi ansible kullanabiliyoruz.

prepare.sh is very much the same everywhere

#!/usr/bin/env bash

while [ ! -f /var/lib/cloud/instance/boot-finished ]; do
    echo 'Waiting for cloud-init...'
    sleep 5
done

sudo rm /etc/ssh/ssh_host_*
sudo truncate -s 0 /etc/machine-id
sudo apt -y autoremove --purge
sudo apt -y clean
sudo apt -y autoclean
sudo cloud-init clean
sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg
sudo sync