This commit is contained in:
Maxim Slipenko 2023-11-18 17:28:18 +03:00
commit 6063360ded
9 changed files with 163 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
iso/*.iso

1
README.md Normal file
View File

@ -0,0 +1 @@
packer build -var-file=alt-server-v-10/vars.pkrvars.hcl libvirt.pkr.hcl

View File

@ -0,0 +1,18 @@
("/sysconfig-base/language" action "write" lang ("en_US"))
("/sysconfig-base/kbd" action "write" layout "ctrl_shift_toggle")
("/datetime-installer" action "write" commit #t name "RU" zone "Europe/Moscow" utc #t)
("/evms/control" action "write" control open installer #t)
("/evms/control" action "write" control update)
("/evms/profiles/server" action apply commit #f clearall #t exclude ())
("/evms/control" action "write" control commit)
("/evms/control" action "write" control close)
("/pkg-init" action "write")
("/pkg-install" action "write" lists "" auto #t)
("/preinstall" action "write")
("/grub" action "write" device "/dev/vda" passwd #f passwd_1 "*" passwd_2 "*")
("/net-eth" action "write" reset #t)
("/net-eth" action "write" name "eth0" configuration "dhcp")
("/net-eth" action "write" commit #t)
("/root/change_password" language ("en_US") passwd_2 "vagrant" passwd_1 "vagrant")
("/users/create_account" new_name "vagrant" gecos "vagrant" allow_su #t auto #f passwd_1 "vagrant" passwd_2 "vagrant" autologin #f)
("/postinstall/laststate" script "http://server/script.sh")

View File

@ -0,0 +1,5 @@
((server
(title . "Setup")
(action . trivial)
(actiondata ("/" (size 1024000 . #t ) (fsim . "Ext2/3") (methods plain)))
))

11
alt-server-v-10/setup.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/bash -e
# add vagrant's public key - user can ssh without password
mkdir -pm 700 /home/vagrant/.ssh
curl -q -o /home/vagrant/.ssh/authorized_keys https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant:vagrant /home/vagrant/.ssh
# give sudo access (grants all permissions to user vagrant)
echo "vagrant ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/vagrant
chmod 0440 /etc/sudoers.d/vagrant

17
alt-server-v-10/setup.yml Normal file
View File

@ -0,0 +1,17 @@
---
- name: Provision
hosts: default
become: true
become_method: su
gather_facts: false
vars:
become_password: vagrant
tasks:
- name: Shell
ansible.builtin.shell: |
mkdir -pm 700 /home/vagrant/.ssh
curl -q -o /home/vagrant/.ssh/authorized_keys https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant:vagrant /home/vagrant/.ssh
echo "vagrant ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/vagrant
chmod 0440 /etc/sudoers.d/vagrant

View File

@ -0,0 +1,22 @@
iso_url = "./iso/alt-server-v-10.1-x86_64.iso"
iso_checksum = "sha256:9955e7bb5ee9affbe3de7473a3bcd53f7d8463b9e2f43ef6831ebfe71bc7da6c"
ssh_username = "vagrant"
ssh_password = "vagrant"
vm_name = "alt-server-v-10"
http_dir = "./alt-server-v-10/http"
output_directory = "./builds/alt-server-v-10"
output_filename = "alt-server-v-10-amd64"
boot_command = [
"<wait><wait><wait><wait><wait><wait><wait><wait>",
"e<wait><down><down><down><end><spacebar>",
"ai curl=http://{{ .HTTPIP }}:{{ .HTTPPort }}/",
"<f10>"
]
setup_playbook = "./alt-server-v-10/setup.yml"
setup_script = "./alt-server-v-10/setup.sh"

0
iso/.gitkeep Normal file
View File

88
libvirt.pkr.hcl Normal file
View File

@ -0,0 +1,88 @@
packer {
required_plugins {
qemu = {
source = "github.com/hashicorp/qemu"
version = "~> 1"
}
vagrant = {
source = "github.com/hashicorp/vagrant"
version = "~> 1"
}
ansible = {
source = "github.com/hashicorp/ansible"
version = "~> 1"
}
}
}
variable "headless" {
type = bool
default = true
}
variable "iso_url" {
type = string
}
variable "iso_checksum" {
type = string
}
variable "http_dir" {
type = string
}
variable "vm_name" {
type = string
}
variable "boot_command" {
type = list(string)
}
variable "setup_script" {
type = string
}
source "qemu" "alt-linux" {
headless = "${var.headless}"
# Путь и контрольная сумма исходного ISO-образа
iso_url = "${var.iso_url}"
iso_checksum = "${var.iso_checksum}"
http_directory = "${var.http_dir}"
vm_name = "${var.vm_name}"
boot_wait = "15s"
boot_command = "${var.boot_command}"
accelerator = "kvm"
disk_size = 4096
format = "qcow2"
net_device = "virtio-net"
output_directory = "output-vagrant"
qemuargs = [
[ "-m", "1024" ],
[ "-smp", "1" ]
]
ssh_username = "vagrant"
ssh_password = "vagrant"
ssh_port = 22
ssh_wait_timeout = "10000s"
ssh_pty = true
}
build {
sources = [
"source.qemu.alt-linux"
]
# provisioner "ansible" {
# playbook_file = "${var.setup_playbook}"
# }
#provisioner "shell" {
#script = "${var.setup_script}"
#execute_command = "python -c 'import pty; pty.spawn(\"/bin/bash\")'; echo 'vagrant' | su -c sh -c '{{ .Vars }} {{ .Path }}'"
#}
post-processor "vagrant" {
keep_input_artifact = false
output = "package.box"
}
}