From 6063360dedfcb5bd2100b1a56fa4f73adad0e52c Mon Sep 17 00:00:00 2001 From: Maxim Slipenko Date: Sat, 18 Nov 2023 17:28:18 +0300 Subject: [PATCH] init --- .gitignore | 1 + README.md | 1 + alt-server-v-10/http/autoinstall.scm | 18 ++++++ alt-server-v-10/http/vm-profile.scm | 5 ++ alt-server-v-10/setup.sh | 11 ++++ alt-server-v-10/setup.yml | 17 ++++++ alt-server-v-10/vars.pkrvars.hcl | 22 +++++++ iso/.gitkeep | 0 libvirt.pkr.hcl | 88 ++++++++++++++++++++++++++++ 9 files changed, 163 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 alt-server-v-10/http/autoinstall.scm create mode 100644 alt-server-v-10/http/vm-profile.scm create mode 100644 alt-server-v-10/setup.sh create mode 100644 alt-server-v-10/setup.yml create mode 100644 alt-server-v-10/vars.pkrvars.hcl create mode 100644 iso/.gitkeep create mode 100644 libvirt.pkr.hcl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d42bcf2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +iso/*.iso \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e7f8365 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +packer build -var-file=alt-server-v-10/vars.pkrvars.hcl libvirt.pkr.hcl \ No newline at end of file diff --git a/alt-server-v-10/http/autoinstall.scm b/alt-server-v-10/http/autoinstall.scm new file mode 100644 index 0000000..bea8a8f --- /dev/null +++ b/alt-server-v-10/http/autoinstall.scm @@ -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") \ No newline at end of file diff --git a/alt-server-v-10/http/vm-profile.scm b/alt-server-v-10/http/vm-profile.scm new file mode 100644 index 0000000..c2abcfb --- /dev/null +++ b/alt-server-v-10/http/vm-profile.scm @@ -0,0 +1,5 @@ +((server + (title . "Setup") + (action . trivial) + (actiondata ("/" (size 1024000 . #t ) (fsim . "Ext2/3") (methods plain))) +)) diff --git a/alt-server-v-10/setup.sh b/alt-server-v-10/setup.sh new file mode 100644 index 0000000..ad77381 --- /dev/null +++ b/alt-server-v-10/setup.sh @@ -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 \ No newline at end of file diff --git a/alt-server-v-10/setup.yml b/alt-server-v-10/setup.yml new file mode 100644 index 0000000..251c0be --- /dev/null +++ b/alt-server-v-10/setup.yml @@ -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 diff --git a/alt-server-v-10/vars.pkrvars.hcl b/alt-server-v-10/vars.pkrvars.hcl new file mode 100644 index 0000000..5ba27ce --- /dev/null +++ b/alt-server-v-10/vars.pkrvars.hcl @@ -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 = [ + "", + "e", + "ai curl=http://{{ .HTTPIP }}:{{ .HTTPPort }}/", + "" +] + +setup_playbook = "./alt-server-v-10/setup.yml" +setup_script = "./alt-server-v-10/setup.sh" \ No newline at end of file diff --git a/iso/.gitkeep b/iso/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/libvirt.pkr.hcl b/libvirt.pkr.hcl new file mode 100644 index 0000000..56771f3 --- /dev/null +++ b/libvirt.pkr.hcl @@ -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" + } +}