diff --git a/packer/linux/build-debian-12-amd64.sh b/packer/linux/build-debian-12-x64.sh similarity index 100% rename from packer/linux/build-debian-12-amd64.sh rename to packer/linux/build-debian-12-x64.sh diff --git a/packer/linux/build-ubuntu-24.04-x64.sh b/packer/linux/build-ubuntu-24.04-x64.sh new file mode 100755 index 0000000..e8a7d4b --- /dev/null +++ b/packer/linux/build-ubuntu-24.04-x64.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +packer="/usr/bin/packer" + +# => For logs: +#export PACKER_LOG_PATH=./build-debian-12-amd64.log +export PACKER_LOG=0 + +creds_vars_file="$HOME/.secret/.packer/vcsrv-creds.pkrvars.hcl" + + +$packer init $HOME/packer/linux/ubuntu-24.04-x64/ +$packer build -force \ +-var-file="$creds_vars_file" \ +-var-file="$HOME/packer/linux/ubuntu-24.04-x64/conf.pkrvars.hcl" \ +$HOME/packer/linux/ubuntu-24.04-x64/ + diff --git a/packer/linux/debian-12-x64/conf.pkrvars.hcl b/packer/linux/debian-12-x64/conf.pkrvars.hcl index 7cf4053..d58d5b6 100644 --- a/packer/linux/debian-12-x64/conf.pkrvars.hcl +++ b/packer/linux/debian-12-x64/conf.pkrvars.hcl @@ -4,7 +4,7 @@ vcenter_host = "esxi8-01.lab.loc" vcenter_folder = "VLAN-0221" vcenter_datastore = "Cluster01-LUN02" -vm_name = "z-test-packer-vm" +vm_name = "z-debian-packer-vm" vm_num_cpu = 1 vm_ram = 1024 vm_hardware_version = "20" diff --git a/packer/linux/debian-12-x64/data/prep-script.sh b/packer/linux/debian-12-x64/data/prep-script.sh index d8d6b46..fcead25 100644 --- a/packer/linux/debian-12-x64/data/prep-script.sh +++ b/packer/linux/debian-12-x64/data/prep-script.sh @@ -1,12 +1,12 @@ #!/bin/bash -echo Resize root partition... +echo "Resize root partition..." sudo parted /dev/sda resizepart 2 100% > /dev/null 2>&1 sudo pvresize /dev/sda2 > /dev/null 2>&1 sudo lvextend -y -f -l +100%FREE /dev/vg01/root > /dev/null 2>&1 sudo resize2fs /dev/vg01/root > /dev/null 2>&1 -echo Create rc.local file... +echo "Create rc.local file..." sudo echo "#!/bin/sh -e # # rc.local diff --git a/packer/linux/debian-12-x64/debian-12-x64.pkr.hcl b/packer/linux/debian-12-x64/debian-12-x64.pkr.hcl index 5e975d1..ef8fc60 100644 --- a/packer/linux/debian-12-x64/debian-12-x64.pkr.hcl +++ b/packer/linux/debian-12-x64/debian-12-x64.pkr.hcl @@ -22,7 +22,7 @@ packer { // var1 = "var1" //} -source "vsphere-iso" "debian-12" { +source "vsphere-iso" "debian-12-x64" { vcenter_server = var.vcenter_server username = var.vcenter_username password = var.vcenter_password @@ -70,7 +70,7 @@ source "vsphere-iso" "debian-12" { build { name = "template" - sources = ["source.vsphere-iso.debian-12"] + sources = ["source.vsphere-iso.debian-12-x64"] provisioner "file" { destination = "/tmp/prep-script.sh" diff --git a/packer/linux/debian-12-x64/data/preseed.cfg b/packer/linux/debian-12-x64/http/preseed.cfg similarity index 94% rename from packer/linux/debian-12-x64/data/preseed.cfg rename to packer/linux/debian-12-x64/http/preseed.cfg index dc5e04b..e52f341 100644 --- a/packer/linux/debian-12-x64/data/preseed.cfg +++ b/packer/linux/debian-12-x64/http/preseed.cfg @@ -19,11 +19,11 @@ d-i clock-setup/utc boolean true # Package Configuration d-i pkgsel/upgrade select full-upgrade d-i apt-setup/services-select multiselect security, updates -#d-i mirror/country string TR -d-i mirror/country string manual -d-i mirror/http/hostname string 192.168.111.251 -d-i mirror/http/directory string /debian -d-i apt-setup/security_host string 192.168.111.251 +d-i mirror/country string TR +#d-i mirror/country string manual +#d-i mirror/http/hostname string 192.168.111.251 +#d-i mirror/http/directory string /debian +#d-i apt-setup/security_host string 192.168.111.251 d-i apt-setup/non-free-firmware boolean true d-i apt-setup/non-free boolean true @@ -102,7 +102,7 @@ d-i debian-installer/splash boolean false d-i finish-install/reboot_in_progress note d-i preseed/late_command string in-target /bin/sh -c '/bin/echo "send dhcp-client-identifier = hardware;" >> /etc/dhcp/dhclient.conf'; \ in-target mkdir -p /home/ansb-srv-it/.ssh; \ -in-target /bin/sh -c "echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC21HOAhC6o25M1oKxKsZxIoxUUeIpb4oqtAdPRNGU4PhJL1g1Cnro+YeF36YnvTKHRzDxS211y/zZBkt7BxOM7qj6dTQSH23jRwGLyfcYv7VyrK1YoxUAXumOJYnhfjVhXoznKnY9++GO9a/1gxQCzjGFMoxAQxFiBMbR/3Ic92ix2SM5aftXl1Mvu3mv45iZimyVIOH5cXdC0XtDSC7EEsdp1Ex6H/GfYabS+cJ55Uyct3orVBSf1LYFLaBNpIx7evXe+bXl81pvW8k/JhYTizoYNEA9rCi+1zaLQMb5LviHM3QqiYjkJbdt2Bd6TVmAfXrJKkj5XXnaMcDqXg8VUKqBenWOSugwagjYYjPRN/pyOeucL+pW1+iv8rAsVxn/0/eliNMn4rExN+Bj6kOmmdrsfqfierffW4DGDJtZlZhfXeZTX8XhdwMt7QUsUdK/Mr14uaEGjhWywX7uqSTnySV1mG4f6vJOyJksZKNSDzK8zH4k3u3onBFbut6NRG+cW4DaScmDbxAkUyurpesPlQkZzcKit6LLscJWZqCrd09zUvHuktnLuhlcicPQPD0B3VhbqVjTvjTDqZX8ZdxrHaRFwfKtv+gqo5Xb2ziS9MxsslxrSe9Ss4w4XkfbZ3BMnyfJWgxHuuyp4Y9gVRE4pFmsoR3v1zpTTHzMGKJKXWw== root@ansible' >> /home/ansb-srv-it/.ssh/authorized_keys"; \ +in-target /bin/sh -c "echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC21HOAhC6o25M1oKxKsZxIoxUUeIpb4oqtAdPRNGU4PhJL1g1Cnro+YeF36YnvTKHRzDxS211y/zZBkt7BxOM7qj6dTQSH23jRwGLyfcYv7VyrK1YoxUAXumOJYnhfjVhXoznKnY9++GO9a/1gxQCzjGFMoxAQxFiBMbR/3Ic92ix2SM5aftXl1Mvu3mv45iZimyVIOH5cXdC0XtDSC7EEsdp1Ex6H/GfYabS+cJ55Uyct3orVBSf1LYFLaBNpIx7evXe+bXl81pvW8k/JhYTizoYNEA9rCi+1zaLQMb5LviHM3QqiYjkJbdt2Bd6TVmAfXrJKkj5XXnaMcDqXg8VUKqBenWOSugwagjYYjPRN/pyOeucL+pW1+iv8rAsVxn/0/eliNMn4rExN+Bj6kOmmdrsfqfierffW4DGDJtZlZhfXeZTX8XhdwMt7QUsUdK/Mr14uaEGjhWywX7uqSTnySV1mG4f6vJOyJksZKNSDzK8zH4k3u3onBFbut6NRG+cW4DaScmDbxAkUyurpesPlQkZzcKit6LLscJWZqCrd09zUvHuktnLuhlcicPQPD0B3VhbqVjTvjTDqZX8ZdxrHaRFwfKtv+gqo5Xb2ziS9MxsslxrSe9Ss4w4XkfbZ3BMnyfJWgxHuuyp4Y9gVRE4pFmsoR3v1zpTTHzMGKJKXWw== ansible@user' >> /home/ansb-srv-it/.ssh/authorized_keys"; \ in-target chown -R ansb-srv-it:ansb-srv-it /home/ansb-srv-it; \ in-target chmod 700 /home/ansb-srv-it; \ in-target chmod 600 /home/ansb-srv-it/.ssh/authorized_keys; \ @@ -110,6 +110,6 @@ in-target chmod 700 /home/ansb-srv-it/.ssh; \ in-target usermod -aG sudo ansb-srv-it; \ in-target usermod -p '*' ansb-srv-it; \ in-target usermod -p '*' root; \ -in-target /bin/sh -c "echo 'ansb-srv-it ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/ansb-srv-it"; \ +in-target /bin/sh -c "echo 'ansb-srv-it ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/ansb-srv-it"; \ in-target chmod 440 /etc/sudoers.d/ansb-srv-it; \ in-target echo diff --git a/packer/linux/ubuntu-24.04-x64/conf.pkrvars.hcl b/packer/linux/ubuntu-24.04-x64/conf.pkrvars.hcl new file mode 100644 index 0000000..cdd3301 --- /dev/null +++ b/packer/linux/ubuntu-24.04-x64/conf.pkrvars.hcl @@ -0,0 +1,20 @@ +vcenter_datacenter = "DC01" +vcenter_cluster = "Cluster01" +vcenter_host = "esxi8-01.lab.loc" +vcenter_folder = "VLAN-0221" +vcenter_datastore = "Cluster01-LUN02" + +vm_name = "z-ubuntu-packer-vm" +vm_num_cpu = 2 +vm_ram = 4096 +vm_hardware_version = "20" +vm_guest_os_type = "ubuntu64Guest" +vm_disk_size = "6144" +vm_network = "VLAN-0221" +vm_network_nic_type = "vmxnet3" + +iso_checksum = "none" +os_iso_paths = "[Cluster01-LUN01] ISO/ubuntu-24.04.1-live-server-amd64.iso" +os_iso_url = "https://releases.ubuntu.com/24.04.1/ubuntu-24.04.1-live-server-amd64.iso" + +boot_command = "eautoinstall ipv6.disable=1 ds=\"nocloud-net;s=http://aassdd.ru/.packer/ubuntu/\" ---" diff --git a/packer/linux/ubuntu-24.04-x64/data/prep-script.sh b/packer/linux/ubuntu-24.04-x64/data/prep-script.sh new file mode 100644 index 0000000..b8bc3ea --- /dev/null +++ b/packer/linux/ubuntu-24.04-x64/data/prep-script.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +echo "Resize root partition..." +sudo parted /dev/sda resizepart 2 100% > /dev/null 2>&1 +sudo pvresize /dev/sda2 > /dev/null 2>&1 +sudo lvextend -y -f -l +100%FREE /dev/vg01/root > /dev/null 2>&1 +sudo resize2fs /dev/vg01/root > /dev/null 2>&1 + +echo "Delete password for root and ansb-srv-it" +sudo usermod -p '*' root +sudo usermod -p '*' ansb-srv-it + +echo "Change perm for /home/ansb-srv-it" +sudo chmod 700 /home/ansb-srv-it + +echo "Create rc.local file..." +sudo echo "#!/bin/sh -e +# +# rc.local +# +# This script is executed at the end of each multiuser runlevel. +# Make sure that the script will exit 0 on success or any other +# value on error. +# +# In order to enable or disable this script just change the execution +# bits. +# +# By default this script does nothing. + + +exit 0 +" > /etc/rc.local +sudo chown root:root /etc/rc.local +sudo chmod 755 /etc/rc.local + +exit 0 diff --git a/packer/linux/ubuntu-24.04-x64/http/meta-data b/packer/linux/ubuntu-24.04-x64/http/meta-data new file mode 100644 index 0000000..e69de29 diff --git a/packer/linux/ubuntu-24.04-x64/http/user-data b/packer/linux/ubuntu-24.04-x64/http/user-data new file mode 100644 index 0000000..6c31690 --- /dev/null +++ b/packer/linux/ubuntu-24.04-x64/http/user-data @@ -0,0 +1,42 @@ +#cloud-config +autoinstall: + version: 1 + locale: en_US.UTF-8 + user-data: + timezone: Europe/Moscow + identity: + hostname: ubuntu-24-04-auto-tmpl + username: ansb-srv-it + password: '$6$R789K/T7lS27KICW$2i5f/sP6nXniEMbjnTyswKMdStGVQdbz8jqIyrXxrhYxJLD0JrWTZjnlFpWkEOlJ2Oa9WvEcANu9iLY3mg5mw.' + storage: + config: + - {ptable: gpt, path: /dev/sda, wipe: superblock, preserve: false, name: '', grub_device: true, type: disk, id: disk-sda} + - {device: disk-sda, size: 1048576, flag: bios_grub, number: 1, preserve: false, grub_device: false, type: partition, id: part-sda1} + - {device: disk-sda, size: -1, wipe: superblock, flag: '', number: 2, preserve: false, grub_device: false, type: partition, id: part-sda2} + - name: vg01 + devices: [part-sda2] + preserve: false + type: lvm_volgroup + id: lvm_vg01 + - {name: swap, volgroup: lvm_vg01, size: 536870912B, preserve: false, type: lvm_partition, id: lvm_vg01_swap} + - {fstype: swap, volume: lvm_vg01_swap, preserve: false, type: format, id: format_lvm_vg01_swap} + - {device: format_lvm_vg01_swap, path: '', type: mount, id: mount-swap} + - {name: root, volgroup: lvm_vg01, size: 4294967296B, preserve: false, type: lvm_partition, id: lvm_vg01_root} + - {fstype: ext4, volume: lvm_vg01_root, preserve: false, type: format, id: format_lvm_vg01_root} + - {device: format_lvm_vg01_root, path: /, type: mount, id: mount-root} + early-commands: + # otherwise packer tries to connect and exceed max attempts: + - systemctl stop open-vm-tools.service + - systemctl stop ssh + ssh: + install-server: true + allow-pw: true + authorized-keys: + - 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC21HOAhC6o25M1oKxKsZxIoxUUeIpb4oqtAdPRNGU4PhJL1g1Cnro+YeF36YnvTKHRzDxS211y/zZBkt7BxOM7qj6dTQSH23jRwGLyfcYv7VyrK1YoxUAXumOJYnhfjVhXoznKnY9++GO9a/1gxQCzjGFMoxAQxFiBMbR/3Ic92ix2SM5aftXl1Mvu3mv45iZimyVIOH5cXdC0XtDSC7EEsdp1Ex6H/GfYabS+cJ55Uyct3orVBSf1LYFLaBNpIx7evXe+bXl81pvW8k/JhYTizoYNEA9rCi+1zaLQMb5LviHM3QqiYjkJbdt2Bd6TVmAfXrJKkj5XXnaMcDqXg8VUKqBenWOSugwagjYYjPRN/pyOeucL+pW1+iv8rAsVxn/0/eliNMn4rExN+Bj6kOmmdrsfqfierffW4DGDJtZlZhfXeZTX8XhdwMt7QUsUdK/Mr14uaEGjhWywX7uqSTnySV1mG4f6vJOyJksZKNSDzK8zH4k3u3onBFbut6NRG+cW4DaScmDbxAkUyurpesPlQkZzcKit6LLscJWZqCrd09zUvHuktnLuhlcicPQPD0B3VhbqVjTvjTDqZX8ZdxrHaRFwfKtv+gqo5Xb2ziS9MxsslxrSe9Ss4w4XkfbZ3BMnyfJWgxHuuyp4Y9gVRE4pFmsoR3v1zpTTHzMGKJKXWw== ansible@user' + updates: all + packages: + - open-vm-tools + - sudo + late-commands: + - echo 'ansb-srv-it ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/ansb-srv-it + - curtin in-target --target=/target -- chmod 440 /etc/sudoers.d/ansb-srv-it diff --git a/packer/linux/ubuntu-24.04-x64/http/vendor-data b/packer/linux/ubuntu-24.04-x64/http/vendor-data new file mode 100644 index 0000000..e69de29 diff --git a/packer/linux/ubuntu-24.04-x64/ubuntu-24.04-x64.pkr.hcl b/packer/linux/ubuntu-24.04-x64/ubuntu-24.04-x64.pkr.hcl new file mode 100644 index 0000000..4abd933 --- /dev/null +++ b/packer/linux/ubuntu-24.04-x64/ubuntu-24.04-x64.pkr.hcl @@ -0,0 +1,87 @@ +packer { + required_version = ">= 1.11.0" + required_plugins { + vsphere = { + source = "github.com/hashicorp/vsphere" + version = ">= 1.4.0" + } + ansible = { + source = "github.com/hashicorp/ansible" + version = ">= 1.1.1" + } + git = { + source = "github.com/ethanmdavidson/git" + version = ">= 0.6.2" + } + } +} + + +// Defines the local variables. +//locals { +// var1 = "var1" +//} + +source "vsphere-iso" "ubuntu-24-04-x64" { + vcenter_server = var.vcenter_server + username = var.vcenter_username + password = var.vcenter_password + insecure_connection = true + datacenter = var.vcenter_datacenter + cluster = var.vcenter_cluster + host = var.vcenter_host + datastore = var.vcenter_datastore + folder = var.vcenter_folder +# convert_to_template = true +// **************** + vm_name = var.vm_name + CPUs = var.vm_num_cpu + RAM = var.vm_ram + vm_version = var.vm_hardware_version + guest_os_type = var.vm_guest_os_type + disk_controller_type = ["pvscsi"] + storage { + disk_size = var.vm_disk_size + disk_thin_provisioned = true + } + network_adapters { + network = var.vm_network + network_card = var.vm_network_nic_type + } +// **************** + ssh_username = var.connection_username +//ssh_password = var.connection_password + ssh_private_key_file = var.connection_ssh_private_key_file + ssh_port = "22" + ip_wait_timeout = "25m" + ssh_timeout = "10m" + ssh_handshake_attempts = "20" + shutdown_timeout = "10m" +// **************** + iso_checksum = var.iso_checksum +// iso_url = var.os_iso_url + iso_paths = [var.os_iso_paths] +// **************** + + boot_wait = "8s" + boot_command = [var.boot_command] + +} + +build { + name = "template" + sources = ["source.vsphere-iso.ubuntu-24-04-x64"] + + provisioner "file" { + destination = "/tmp/prep-script.sh" + source = "${path.root}data/prep-script.sh" + } + + provisioner "shell" { + inline = [ + "sudo chmod 755 /tmp/prep-script.sh", + "sudo /tmp/prep-script.sh", + ] + } + +} diff --git a/packer/linux/ubuntu-24.04-x64/variables.pkr.hcl b/packer/linux/ubuntu-24.04-x64/variables.pkr.hcl new file mode 100644 index 0000000..12b8fae --- /dev/null +++ b/packer/linux/ubuntu-24.04-x64/variables.pkr.hcl @@ -0,0 +1,65 @@ + +variable "vcenter_server" { + default = "" + sensitive = true +} + +variable "vcenter_username" { + default = "" + sensitive = true +} + +variable "vcenter_password" { + default = "" + sensitive = true +} + + +variable "vcenter_datacenter" { + default = "" + sensitive = true +} + + +variable "vcenter_cluster" { + default = "" + sensitive = true +} + +variable "vcenter_host" { + default = "" + sensitive = true +} + + +variable "vcenter_datastore" { + default = "" + sensitive = true +} + +variable "vcenter_folder" { + default = "" + sensitive = true +} + +// ************************************ +variable "vm_name" { default = "" } +variable "vm_num_cpu" { default = "" } +variable "vm_ram" { default = "" } +variable "vm_hardware_version" { default = "" } +variable "vm_guest_os_type" { default = "" } +variable "vm_disk_size" { default = "" } +variable "vm_network" { default = "" } +variable "vm_network_nic_type" { default = "" } +variable "os_version" { default = "" } +variable "os_family" { default = "" } +variable "os_iso_url" { default = "" } +// ************************************ +variable "connection_username" { default = "" } +variable "connection_password" { default = "" } +variable "connection_ssh_private_key_file" { default = "" } +// ************************************ +variable "iso_checksum" { default = "" } +variable "os_iso_paths" { default = "" } +variable "iso_url" { default = "" } +variable "boot_command" { default = "" }