diff --git a/infra-config/04-vm-templates/fedora-42/LICENSE b/infra-config/04-vm-templates/fedora-42/LICENSE new file mode 100644 index 0000000..c3c2cb7 --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 eaksel + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/infra-config/04-vm-templates/fedora-42/README.md b/infra-config/04-vm-templates/fedora-42/README.md new file mode 100644 index 0000000..9a11e3f --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/README.md @@ -0,0 +1,63 @@ +# packer-CentOS8 + +## What is packer-CentOS8 ? + +packer-CentOS8 is a set of configuration files used to build an automated CentOS 8 virtual machine images using [Packer](https://www.packer.io/). +This Packer configuration file allows you to build images for VMware Workstation and Oracle VM VirtualBox. + +## Prerequisites + +- [Packer](https://www.packer.io/downloads.html) + - +- A Hypervisor + - [VMware Workstation](https://www.vmware.com/products/workstation-pro.html) + - [Oracle VM VirtualBox](https://www.virtualbox.org/) + +## How to use Packer + +Commands to create an automated VM image: + +To create a CentOS 8 VM image using VMware Workstation use the following commands: + +```cmd +cd c:\packer-CentOS8 +packer build -only=vmware-iso centos8.json +``` + +To create a CentOS 8 VM image using Oracle VM VirtualBox use the following commands: + +```cmd +cd c:\packer-CentOS8 +packer build -only=virtualbox-iso centos8.json +``` + +*If you omit the keyword "-only=" both the Workstation and Virtualbox VMs will be created.* + +By default the .iso of CentOS 8 is pulled from + +You can change the URL to one closer to your build server. To do so change the **"iso_url"** parameter in the **"variables"** section of the centos8.json file. + +```json +{ + "variables": { + "iso_url": "http://miroir.univ-paris13.fr/centos/8/isos/x86_64/CentOS-8.1.1911-x86_64-boot.iso" +} +``` + +## Keyboard configuration + +By default the keyboard is set to be US qwerty. +To switch it to something else edit the following file: + +- ./http/ks.cfg + +Set the `keyboard` parameter as desired, for example: `keyboard --vckeymap=fr --xlayouts='fr'` + +## Default credentials + +The default credentials for this VM image are: + +|Username|Password| +|--------|--------| +|packer|packer| +|root|packer| diff --git a/infra-config/04-vm-templates/fedora-41/fedora-42-small.pkrvars.hcl b/infra-config/04-vm-templates/fedora-42/fedora-42-small.pkrvars.hcl similarity index 100% rename from infra-config/04-vm-templates/fedora-41/fedora-42-small.pkrvars.hcl rename to infra-config/04-vm-templates/fedora-42/fedora-42-small.pkrvars.hcl diff --git a/infra-config/04-vm-templates/fedora-41/fedora-42.pkr.hcl b/infra-config/04-vm-templates/fedora-42/fedora-42.pkr.hcl similarity index 100% rename from infra-config/04-vm-templates/fedora-41/fedora-42.pkr.hcl rename to infra-config/04-vm-templates/fedora-42/fedora-42.pkr.hcl diff --git a/infra-config/04-vm-templates/fedora-42/files/ansible.pub b/infra-config/04-vm-templates/fedora-42/files/ansible.pub new file mode 100644 index 0000000..1586a14 --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/files/ansible.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINnSM/9fO8rz/amqkyoGUzUKNNzzmtSXPwOCr1O9zKNO ansible diff --git a/infra-config/04-vm-templates/fedora-42/http/ks.cfg b/infra-config/04-vm-templates/fedora-42/http/ks.cfg new file mode 100644 index 0000000..dd4fa1e --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/http/ks.cfg @@ -0,0 +1,70 @@ +# Kickstart file for Fedora 41 Server (Text-based Installation) +# +# For use with the Fedora Server netinstall ISO. +# Boot the installer with: +# linux /isolinux/vmlinuz inst.ks=http:////ks.cfg +# +# For a local file on a USB drive, you can use: +# linux /isolinux/vmlinuz inst.ks=hd:LABEL=:/ks.cfg + +# Use text mode install +text + +# Disable Initial Setup on first boot +firstboot --disable + +# Keyboard layout +keyboard --vckeymap=us --xlayouts='us' + +# System language +lang en_US.UTF-8 + +# Network information +network --bootproto=dhcp --device=link --activate +network --hostname=fedora.localdomain + +# Root password +rootpw $5$CXpezfLKTajPP7yI$VM8STd3QaHBTKMe2DLTmK5p.lEGbUYYZV8jGG3nxX2/ --iscrypted + +# SELinux configuration +selinux --enforcing + +# Do not configure the X Window System +skipx + +# System timezone +timezone US/Chicago --utc + +# Add a user named wed +user --groups=wheel --name=wed --password=$5$UOpZHG55fWCHlNSp$nFnpaVLb9enbQTebHo4SKBqolGr39SMYo2ZshHCe2d3 --iscrypted --gecos="wed" + +# System bootloader configuration +bootloader --location=mbr --append="crashkernel=auto" + +# Clear the Master Boot Record +zerombr + +# Remove partitions +clearpart --all --initlabel + +# Automatically create partitions using LVM +autopart --type=lvm + +# Reboot after successful installation +reboot + +%packages --ignoremissing +# dnf group info minimal-environment +@^minimal-environment +# Exclude unnecessary firmwares +-iwl*firmware +%end + +%post --nochroot --logfile=/mnt/sysimage/root/ks-post.log +# Disable quiet boot and splash screen +sed --follow-symlinks -i "s/ rhgb quiet//" /mnt/sysimage/etc/default/grub +sed --follow-symlinks -i "s/ rhgb quiet//" /mnt/sysimage/boot/grub2/grubenv + +# Passwordless sudo for the user 'wed' +echo "wed ALL=(ALL) NOPASSWD: ALL" >> /mnt/sysimage/etc/sudoers.d/wed +%end diff --git a/infra-config/04-vm-templates/fedora-42/http/ks1.cfg b/infra-config/04-vm-templates/fedora-42/http/ks1.cfg new file mode 100644 index 0000000..126c085 --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/http/ks1.cfg @@ -0,0 +1,64 @@ +# Kickstart file for Fedora 41 Server (Text-based Installation) +# +# For use with the Fedora Server netinstall ISO. +# Boot the installer with: +# linux /isolinux/vmlinuz inst.ks=http:////ks.cfg +# +# For a local file on a USB drive, you can use: +# linux /isolinux/vmlinuz inst.ks=hd:LABEL=:/ks.cfg + +# System language, keyboard layout, and timezone +lang en_US.UTF-8 +keyboard us +timezone America/Chicago --isUtc + +# Installation source +url --mirrorlist=https://mirrors.fedoraproject.org/mirrorlist?repo=fedora-41&arch=x86_64 + +# Use text mode installer +text + +# Network configuration +# Using DHCP for automatic network configuration. +# For a static configuration, uncomment and modify the following lines: +# network --bootproto=static --device=eth0 --ip=192.168.1.10 --netmask=255.255.255.0 --gateway=192.168.1.1 --nameserver=8.8.8.8,8.8.4.4 --hostname=fedora-server +network --bootproto=dhcp --device=eth0 --onboot=on --ipv6=auto --hostname=fedora41-server + +# Root password (encrypted) +# To generate an encrypted password, use: +# python -c 'import crypt; print(crypt.crypt("YourPassword", crypt.mksalt(crypt.METHOD_SHA512)))' +rootpw --iscrypted $6$your_encrypted_root_password_hash + +# Disk partitioning +# This will erase the specified disk. +# --ondisk=sda can be changed to a more specific device like vda for virtual machines. +# --all will erase all partitions on the disk. +# LVM partitioning scheme is used for flexibility. +zerombr +clearpart --all --initlabel --drives=sda +autopart --type=lvm + +# System services +# Disables services not typically required on a minimal server. +services --disabled="kdump,mdmonitor,mdmonitor-takeover" --enabled="sshd,chronyd" + +# Package selection +# @^server-product-environment provides a minimal server installation. +# You can add additional packages as needed. +%packages +@^server-product-environment +-@standard +# Add essential command-line tools +vim-enhanced +tmux +git +%end + +# Post-installation script +%post --log=/root/ks-post.log +echo "Fedora 41 Server installation complete." > /etc/motd +# Add any additional post-installation tasks here. +%end + +# Reboot after installation +reboot diff --git a/infra-config/04-vm-templates/fedora-42/proxmox.pkvars.hcl b/infra-config/04-vm-templates/fedora-42/proxmox.pkvars.hcl new file mode 100644 index 0000000..9947f70 --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/proxmox.pkvars.hcl @@ -0,0 +1,20 @@ +################################################################################## +# VARIABLES +################################################################################## + +# Credentials + +proxmox_username = "root@pam" +proxmox_password = "" +ssh_username = "wed" +ssh_password = "" + +# Proxmox Objects +proxmox_node = "pve03" +proxmox_domain = "int.mk-labs.cloud" +#proxmox_url = "https://${var.proxmox_node}.${proxmox_domain}:8006/api2/json" +proxmox_vm_storage_pool = "pve-templates" +#proxmox_insecure_connection = false #Default: true +proxmox_iso_storage_pool = "local" + +template_name = "" diff --git a/infra-config/04-vm-templates/fedora-42/scripts/cleanup.sh b/infra-config/04-vm-templates/fedora-42/scripts/cleanup.sh new file mode 100644 index 0000000..050e71b --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/scripts/cleanup.sh @@ -0,0 +1,12 @@ +#!/bin/bash -eux + +pip uninstall -y ansible + +dnf clean all + +# Zero out the rest of the free space using dd, then delete the written file. +#dd if=/dev/zero of=/EMPTY bs=1M +#rm -f /EMPTY + +# Add `sync` so Packer doesn't quit too early, before the large file is deleted. +sync diff --git a/infra-config/04-vm-templates/fedora-42/scripts/setup.yml b/infra-config/04-vm-templates/fedora-42/scripts/setup.yml new file mode 100644 index 0000000..1b746dd --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/scripts/setup.yml @@ -0,0 +1,81 @@ +--- +- name: "Setup.yml" + hosts: localhost + gather_facts: yes + become: yes + tasks: + - name: Colorize root shell prompt + lineinfile: + path: /root/.bashrc + line: 'export PS1="\[\033[38;5;11m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\h:\[$(tput sgr0)\]\[\033[38;5;6m\][\w]:\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"' + state: present + + - name: Alias vi to vim + lineinfile: + path: /root/.bashrc + line: "alias vi='vim'" + state: present + + - name: Create vim configuration file + file: + path: /root/.vimrc + state: touch + owner: root + group: root + mode: 0644 + + - name: Configure vim + blockinfile: + path: /root/.vimrc + block: | + set nocompatible + set number + set autoindent + syntax on + highlight Comment ctermfg=LightCyan + marker: "" + state: present + + - name: Disable GSSAPIAuthentication + lineinfile: + path: /etc/ssh/sshd_config + regexp: "^GSSAPIAuthentication" + line: "GSSAPIAuthentication no" + state: present + + - name: Update CA bundle (RedHat) + get_url: + url: https://curl.haxx.se/ca/cacert.pem + dest: /etc/pki/tls/certs/ca-bundle.crt + force: yes + when: ansible_os_family == "RedHat" + + - name: Install epel repo (RedHat) + dnf: + name: "epel-release" + state: latest + when: ansible_os_family == "RedHat" + + - name: Install packages (RedHat) + dnf: + name: "{{ packages }}" + state: latest + vars: + packages: + - bash-completion + - curl + - git + - rsync + - screen + - tcpdump + - vim + - wget + when: ansible_os_family == "RedHat" + + - name: Install open-vm-tools (RedHat) + dnf: + name: open-vm-tools + state: latest + when: + - ansible_os_family == "RedHat" + - ansible_virtualization_type == "VMware" diff --git a/infra-config/04-vm-templates/fedora-42/variables.pkr.hcl b/infra-config/04-vm-templates/fedora-42/variables.pkr.hcl new file mode 100644 index 0000000..93eb413 --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/variables.pkr.hcl @@ -0,0 +1,144 @@ +# Proxmox variable definitions + +variable "proxmox_username" { + type = string + description = "The username for authenticating to Proxmox." + default = "" + sensitive = true +} + +variable "proxmox_password" { + type = string + description = "The plaintext password for authenticating to Proxmox." + default = "" + sensitive = true +} + +variable "proxmox_node" { + type = string + description = "The Proxmox node to store the templates on." + default = "" +} + +variable "proxmox_domain" { + type = string + description = "The domain the Proxmox node resizes in." + default = "" +} + +variable "proxmox_insecure_verify" { + type = bool + description = "If true, does not validate the proxmox server's TLS certificate." + default = true +} + +variable "proxmox_vm_storage_pool" { + type = string + description = "The storage pool where the VM will live." + default = "" +} + +# Virtual Machine variables + +variable "vm_name" { + type = string + description = "The template vm name" + default = "" +} + +variable "vm_id" { + type = number + description = "The ID of virtual machine." +} + +variable "vm_cpu_sockets" { + type = number + description = "The number of virtual CPUs sockets." + default = "1" +} + +variable "vm_cpu_cores" { + type = number + description = "The number of virtual CPUs cores per socket." + default = "1" +} + +variable "vm_mem_size" { + type = number + description = "The size for the virtual memory in MB." +} + +variable "vm_disk_size" { + type = number + description = "The size of the primary virtual disk in GiB." +} + +variable "proxmox_bridge" { + type = string + description = "The Proxmox bridge the NIC connects to." +} + +variable "proxmox_vlan" { + type = number + description = "The VLAN the NIC is on." +} + +variable "vm_boot_wait" { + type = string + description = "The time to wait before boot (in seconds)." + default = "" +} + +variable "shell_scripts" { + type = list(string) + description = "A list of scripts." + default = [] +} + +# ISO Objects + +variable "proxmox_iso_storage_pool" { + type = string + description = "The storage pool where the ISO is located." + default = "" +} + +variable "iso_url" { + type = string + description = "The url to retrieve the iso image" + default = "" + } + +variable "iso_file" { + type = string + description = "The file name of the guest operating system ISO image installation media." + default = "" +} + +variable "iso_checksum" { + type = string + description = "The checksum of the ISO image." + default = "" +} + +variable "iso_checksum_type" { + type = string + description = "The checksum type of the ISO image. Ex: sha256" + default = "" +} + +# SSH info + +variable "ssh_username" { + type = string + description = "The username to use to authenticate over SSH." + default = "" + sensitive = true +} + +variable "ssh_password" { + type = string + description = "The plaintext password to use to authenticate over SSH." + default = "" + sensitive = true +} diff --git a/infra-config/04-vm-templates/fedora-42/variables.pkrvars-large.hcl b/infra-config/04-vm-templates/fedora-42/variables.pkrvars-large.hcl new file mode 100755 index 0000000..87da981 --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/variables.pkrvars-large.hcl @@ -0,0 +1,35 @@ +################################################################################## +# VARIABLES +################################################################################## + +# HTTP Settings + +http_directory = "http" + +# Virtual Machine Settings + +vm_name = "centos9-large" +vm_guest_os_type = "centos8_64Guest" +vm_version = 19 +vm_firmware = "efi" +vm_cdrom_type = "sata" +vm_cpu_sockets = 1 +vm_cpu_cores = 1 +vm_mem_size = 2048 +vm_disk_size = 51200 +thin_provision = true +disk_eagerly_scrub = false +vm_disk_controller_type = ["pvscsi"] +vm_network_card = "vmxnet3" +vm_boot_wait = "5s" +ssh_username = "wed" +ssh_password = "1mag!ne3R" + +# ISO Objects + +iso_checksum = "ca03867ab88fbe565b91ae518e6f7f83debe6415234f29ff2cc5634052840ce8" +iso_checksum_type = "sha256" +iso_url = "https://mirror.rackspace.com/centos-stream/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-dvd1.iso" +# Scripts + +shell_scripts = ["scripts/cleanup.sh"] diff --git a/infra-config/04-vm-templates/fedora-42/variables.pkrvars-medium.hcl b/infra-config/04-vm-templates/fedora-42/variables.pkrvars-medium.hcl new file mode 100755 index 0000000..7356e0b --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/variables.pkrvars-medium.hcl @@ -0,0 +1,35 @@ +################################################################################## +# VARIABLES +################################################################################## + +# HTTP Settings + +http_directory = "http" + +# Virtual Machine Settings + +vm_name = "centos9-medium" +vm_guest_os_type = "centos8_64Guest" +vm_version = 19 +vm_firmware = "efi" +vm_cdrom_type = "sata" +vm_cpu_sockets = 1 +vm_cpu_cores = 1 +vm_mem_size = 2048 +vm_disk_size = 25600 +thin_provision = true +disk_eagerly_scrub = false +vm_disk_controller_type = ["pvscsi"] +vm_network_card = "vmxnet3" +vm_boot_wait = "5s" +ssh_username = "wed" +ssh_password = "1mag!ne3R" + +# ISO Objects + +iso_checksum = "ca03867ab88fbe565b91ae518e6f7f83debe6415234f29ff2cc5634052840ce8" +iso_checksum_type = "sha256" +iso_url = "https://mirror.rackspace.com/centos-stream/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-dvd1.iso" +# Scripts + +shell_scripts = ["scripts/cleanup.sh"] diff --git a/infra-config/04-vm-templates/fedora-42/variables.pkrvars-xlarge.hcl b/infra-config/04-vm-templates/fedora-42/variables.pkrvars-xlarge.hcl new file mode 100755 index 0000000..43b34ad --- /dev/null +++ b/infra-config/04-vm-templates/fedora-42/variables.pkrvars-xlarge.hcl @@ -0,0 +1,35 @@ +################################################################################## +# VARIABLES +################################################################################## + +# HTTP Settings + +http_directory = "http" + +# Virtual Machine Settings + +vm_name = "centos9-large" +vm_guest_os_type = "centos8_64Guest" +vm_version = 19 +vm_firmware = "efi" +vm_cdrom_type = "sata" +vm_cpu_sockets = 1 +vm_cpu_cores = 1 +vm_mem_size = 2048 +vm_disk_size = 102400 +thin_provision = true +disk_eagerly_scrub = false +vm_disk_controller_type = ["pvscsi"] +vm_network_card = "vmxnet3" +vm_boot_wait = "5s" +ssh_username = "wed" +ssh_password = "1mag!ne3R" + +# ISO Objects + +iso_checksum = "ca03867ab88fbe565b91ae518e6f7f83debe6415234f29ff2cc5634052840ce8" +iso_checksum_type = "sha256" +iso_url = "https://mirror.rackspace.com/centos-stream/9-stream/BaseOS/x86_64/iso/CentOS-Stream-9-latest-x86_64-dvd1.iso" +# Scripts + +shell_scripts = ["scripts/cleanup.sh"]