diff options
author | Jonathan Bauer | 2017-03-10 18:37:04 +0100 |
---|---|---|
committer | Jonathan Bauer | 2017-03-10 18:37:04 +0100 |
commit | e866286a4411138c49e329b7e71f67d9b187edba (patch) | |
tree | db7fefef0b82ca5577641a18935d6f3937fe02f6 | |
parent | initial commit (diff) | |
download | packer-templates-e866286a4411138c49e329b7e71f67d9b187edba.tar.gz packer-templates-e866286a4411138c49e329b7e71f67d9b187edba.tar.xz packer-templates-e866286a4411138c49e329b7e71f67d9b187edba.zip |
Templates for Centos 7.3 and Ubuntu 16.04
These were tested with qemu (2.8.0), virtualbox (5.1.16) and vmplayer
(12.5.2-4638234). Using the qemu builder is preferable as it creates
a qcow2 file directly.
The unattended install is configured to install the necessary packages
for ansible which will be needed to provision the VM. The rest is still
pretty minimal.
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | README.md | 34 | ||||
-rw-r--r-- | base.json | 9 | ||||
-rw-r--r-- | centos-7.3-x86_64.json | 91 | ||||
-rw-r--r-- | http/centos-7.3/anaconda-ks.cfg | 37 | ||||
-rw-r--r-- | http/ubuntu-16.04/preseed.cfg | 51 | ||||
-rw-r--r-- | ubuntu-16.04-amd64.json | 129 |
7 files changed, 352 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b6acd97 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +output-*/ + @@ -1,3 +1,35 @@ # Packer templates for OpenSLX -TODO +Packer-based generation of reference systems using distro's ISOs. + +## Dependencies + +Packer => 0.12.2 +Download: https://www.packer.io/downloads.html + +## Usage + +The file 'base.json' contains default variables (VM, SSH) common to all templates. +Thus it should always be included using packer's '-var-file' option. + +Basic usage: + packer build -var-file=base.json <template> + +Example: build Ubuntu 16.04.2 LTS template using qemu builder + packer build -var-file=base.json -only=qemu ubuntu-16.04-amd64.json + +Debug: + PACKER_LOG=1 PACKER_LOG_FILE=/var/log/packer.log \ + packer build -debug -only=qemu -var-file=base.json ubuntu-16.04-amd64.json + +## Notes + +Variables set in base.json can be overriden using packer's '-var' options, e.g.: + packer build -var-file=base.json -var='headless=true' <template> + +(Make sure you first include base.json before overriding a variable!) + +Packer connects to the VM per SSH to provision them after the initial iso installation. +A default password is defined in base.json and the corresponding SHA-512 hashes are set +in the kickstart/preseed files. If you change the 'ssh_password' make sure to change the +hashes in the ks/ps files (generate with 'mkpasswd -m sha-512')! diff --git a/base.json b/base.json new file mode 100644 index 0000000..8f4ff26 --- /dev/null +++ b/base.json @@ -0,0 +1,9 @@ +{ + "cpus": "2", + "disk_size": "40000", + "headless": "true", + "memory": "1024", + "ssh_timeout": "60m", + "ssh_username": "root", + "ssh_password": "s0m3p4ss" +} diff --git a/centos-7.3-x86_64.json b/centos-7.3-x86_64.json new file mode 100644 index 0000000..e3ec622 --- /dev/null +++ b/centos-7.3-x86_64.json @@ -0,0 +1,91 @@ +{ + "variables": { + "iso_url": "http://mirrors.kernel.org/centos/7/isos/x86_64/CentOS-7-x86_64-NetInstall-1611.iso", + "iso_checksum": "f2f7367deb90a25822947660c71638333ca0eceeabecc2d631be6cd508c24494", + "iso_checksum_type": "sha256", + "vm_name": "packer-centos-x86_64", + "http_dir": "http", + "kickstart_path": "centos-7.3/anaconda-ks.cfg", + "shutdown_command": "systemctl poweroff" + }, + "builders": [{ + "type": "qemu", + "iso_url": "{{ user `iso_url` }}", + "iso_checksum": "{{ user `iso_checksum` }}", + "iso_checksum_type": "{{ user `iso_checksum_type` }}", + "output_directory": "output-centos-x86_64-{{ build_type }}-{{ timestamp }}", + "vm_name": "{{ user `vm_name` }}", + "format": "qcow2", + "disk_size": "{{ user `disk_size` }}", + "disk_interface": "virtio-scsi", + "headless": "{{ user `headless` }}", + "http_directory": "{{ user `http_dir` }}", + "boot_command": [ + "<esc><wait>", + "linux inst.gpt biosdevname=0 net.ifnames=0 ", + "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{ user `kickstart_path` }}", + "<enter>" + ], + "boot_wait": "{{ user `boot_wait` }}", + "ssh_timeout": "{{ user `ssh_timeout` }}", + "ssh_username": "{{ user `ssh_username` }}", + "ssh_password": "{{ user `ssh_password` }}", + "shutdown_command": "{{ user `shutdown_command` }}", + "qemuargs": [ + ["-m", "{{ user `memory` }}"], + ["-smp", "{{ user `cpus` }}"] + ] + }, { + "type": "virtualbox-iso", + "guest_os_type": "RedHat_64", + "iso_url": "{{ user `iso_url` }}", + "iso_checksum": "{{ user `iso_checksum` }}", + "iso_checksum_type": "{{ user `iso_checksum_type` }}", + "output_directory": "output-centos-x86_64-{{ build_type }}-{{ timestamp }}", + "vm_name": "{{ user `vm_name` }}", + "disk_size": "{{ user `disk_size` }}", + "headless": "{{ user `headless` }}", + "http_directory": "{{ user `http_dir` }}", + "boot_command": [ + "<esc><wait>", + "linux inst.gpt biosdevname=0 net.ifnames=0 ", + "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{ user `kickstart_path` }}", + "<enter>" + ], + "boot_wait": "{{ user `boot_wait` }}", + "ssh_timeout": "{{ user `ssh_timeout` }}", + "ssh_username": "{{ user `ssh_username` }}", + "ssh_password": "{{ user `ssh_password` }}", + "shutdown_command": "{{ user `shutdown_command` }}", + "vboxmanage": [ + ["modifyvm", "{{ .Name }}", "--memory", "{{ user `memory` }}"], + ["modifyvm", "{{ .Name }}", "--cpus", "{{ user `cpus` }}"] + ] + }, { + "type": "vmware-iso", + "guest_os_type": "centos-64", + "iso_url": "{{ user `iso_url` }}", + "iso_checksum": "{{ user `iso_checksum` }}", + "iso_checksum_type": "{{ user `iso_checksum_type` }}", + "output_directory": "output-centos-x86_64-{{ build_type }}-{{ timestamp }}", + "vm_name": "{{ user `vm_name` }}", + "disk_size": "{{ user `disk_size` }}", + "headless": "{{ user `headless` }}", + "http_directory": "{{ user `http_dir` }}", + "boot_command": [ + "<esc><wait>", + "linux inst.gpt biosdevname=0 net.ifnames=0 ", + "inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{ user `kickstart_path` }}", + "<enter>" + ], + "boot_wait": "{{ user `boot_wait` }}", + "ssh_timeout": "{{ user `ssh_timeout` }}", + "ssh_username": "{{ user `ssh_username` }}", + "ssh_password": "{{ user `ssh_password` }}", + "shutdown_command": "{{ user `shutdown_command` }}", + "vmx_data": { + "memsize": "{{ user `memory` }}", + "numvcpus": "{{ user `cpus` }}" + } + }] +} diff --git a/http/centos-7.3/anaconda-ks.cfg b/http/centos-7.3/anaconda-ks.cfg new file mode 100644 index 0000000..8cb0be2 --- /dev/null +++ b/http/centos-7.3/anaconda-ks.cfg @@ -0,0 +1,37 @@ +install +text +reboot +url --mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os +lang en_US.UTF-8 +keyboard --vckeymap=de-nodeadkeys --xlayouts='de (nodeadkeys)' +timezone Europe/Berlin --isUtc --nontp +auth --enableshadow --passalgo=sha512 +rootpw --iscrypted $6$6yzbOJJy5auuBh9$XUAtAt/ErLkz6.1t8J4UpyZPPUbKjGO1uATaZaxmG02IhJbOwnJMqI6MTJw.SzbBvy8THCmmoia1tVMfXhGVJ1 +clearpart --none --initlabel +bootloader --location=mbr --boot-drive=sda +part biosboot --fstype="biosboot" --ondisk=sda --size=1 +part / --fstype="ext4" --ondisk=sda --grow --label=SLX_SYS + +%packages +@^minimal +@core +kexec-tools +%end + +%post --erroronfail +yum -y update +yum -y install wget +wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm +rpm -ivh epel-release-latest-7.noarch.rpm +yum -y install ansible +# allow root login for ansible +sed 's,^[[:blank:]]*#*PermitRootLogin.*,PermitRootLogin yes,g' /etc/ssh/sshd_config + +ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules +cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF +DEVICE="eth0" +BOOTPROTO="dhcp" +ONBOOT="yes" +TYPE="Ethernet" +EOF +%end diff --git a/http/ubuntu-16.04/preseed.cfg b/http/ubuntu-16.04/preseed.cfg new file mode 100644 index 0000000..598790b --- /dev/null +++ b/http/ubuntu-16.04/preseed.cfg @@ -0,0 +1,51 @@ +d-i debian-installer/locale string en_US +d-i time/zone string UTC + +d-i keyboard-configuration/xkb-keymap select de + +d-i partman-basicfilesystems/choose_label string gpt +d-i partman-basicfilesystems/default_label string gpt +d-i partman-basicfilesystems/no_swap boolean false +d-i partman-partitioning/choose_label string gpt +d-i partman-partitioning/default_label string gpt +d-i partman/choose_label string gpt +d-i partman/default_label string gpt +d-i partman-auto/method string regular +d-i partman-auto/expert_recipe string \ + scheme :: \ + 32 32 32 free \ + $gptonly{ } \ + $primary{ } \ + $bios_boot{ } \ + method{ biosgrub } . \ + 1 0 -1 ext4 \ + $gptonly{ } \ + $primary{ } \ + method{ format } \ + format{ } \ + use_filesystem{ } \ + filesystem{ ext4 } \ + label{ SLX_SYS } \ + mountpoint{ / } . +d-i partman-partitioning/confirm_write_new_label boolean true +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true + +d-i base-installer/excludes string laptop-detect +d-i passwd/make-user boolean false +d-i passwd/root-login boolean true +d-i passwd/root-password-crypted password $6$6yzbOJJy5auuBh9$XUAtAt/ErLkz6.1t8J4UpyZPPUbKjGO1uATaZaxmG02IhJbOwnJMqI6MTJw.SzbBvy8THCmmoia1tVMfXhGVJ1 +d-i user-setup/allow-password-weak boolean true + +d-i pkgsel/include string curl openssh-server sudo ansible +d-i pkgsel/language-packs multiselect + +d-i finish-install/reboot_in_progress note + +d-i preseed/early_command string \ + mkdir -p /usr/lib/post-base-installer.d && \ + echo "sed -i -e 's/^in-target.*tasksel.*/#\\0/' /var/lib/dpkg/info/pkgsel.postinst" > /usr/lib/post-base-installer.d/90skip-tasksel && \ + chmod +x /usr/lib/post-base-installer.d/90skip-tasksel + +d-i preseed/late_command string sed -i 's,^PermitRootLogin.*,PermitRootLogin yes,' /target/etc/ssh/sshd_config diff --git a/ubuntu-16.04-amd64.json b/ubuntu-16.04-amd64.json new file mode 100644 index 0000000..6ae993c --- /dev/null +++ b/ubuntu-16.04-amd64.json @@ -0,0 +1,129 @@ +{ + "variables": { + "iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04.2-server-amd64.iso", + "iso_checksum": "737ae7041212c628de5751d15c3016058b0e833fdc32e7420209b76ca3d0a535", + "iso_checksum_type": "sha256", + "vm_name": "packer-ubuntu-am64", + "http_dir": "http", + "preseed_path": "ubuntu-16.04.2-lts/preseed.cfg", + "shutdown_command": "systemctl poweroff" + }, + "builders": [{ + "type": "qemu", + "iso_url": "{{ user `iso_url` }}", + "iso_checksum": "{{ user `iso_checksum` }}", + "iso_checksum_type": "{{ user `iso_checksum_type` }}", + "output_directory": "output-ubuntu-amd64-{{ build_type }}-{{ timestamp }}", + "vm_name": "{{ user `vm_name` }}", + "disk_size": "{{ user `disk_size` }}", + "format": "qcow2", + "headless": "{{ user `headless` }}", + "http_directory": "{{ user `http_dir` }}", + "boot_command": [ + "<enter><wait>", + "<f6><esc>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs>", + "/install/vmlinuz ", + "initrd=/install/initrd.gz ", + "auto-install/enable=true ", + "debconf/priority=critical ", + "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{ user `preseed_path` }} ", + "<enter>" + ], + "boot_wait": "5s", + "ssh_timeout": "{{user `ssh_timeout`}}", + "ssh_username": "{{ user `ssh_username` }}", + "ssh_password": "{{ user `ssh_password` }}", + "shutdown_command": "{{ user `shutdown_command` }}", + "qemuargs": [ + ["-m", "{{user `memory`}}"], + ["-smp", "{{user `cpus`}}"] + ] + }, { + "type": "virtualbox-iso", + "guest_os_type": "Ubuntu_64", + "iso_url": "{{ user `iso_url` }}", + "iso_checksum": "{{ user `iso_checksum` }}", + "iso_checksum_type": "{{ user `iso_checksum_type` }}", + "output_directory": "output-ubuntu-amd64-{{ build_type }}-{{ timestamp }}", + "vm_name": "packer-ubuntu-amd64", + "disk_size": "{{ user `disk_size` }}", + "headless": "{{ user `headless` }}", + "http_directory": "{{ user `http_dir` }}", + "boot_command": [ + "<enter><wait>", + "<f6><esc>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs>", + "/install/vmlinuz ", + "initrd=/install/initrd.gz ", + "auto-install/enable=true ", + "debconf/priority=critical ", + "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{ user `preseed_path` }} ", + "<enter>" + ], + "boot_wait": "5s", + "ssh_timeout": "{{ user `ssh_timeout` }}", + "ssh_username": "{{ user `ssh_username` }}", + "ssh_password": "{{ user `ssh_password` }}", + "shutdown_command": "{{ user `shutdown_command` }}", + "vboxmanage": [ + ["modifyvm", "{{ .Name }}", "--memory", "{{ user `memory` }}"], + ["modifyvm", "{{ .Name }}", "--cpus", "{{ user `cpus` }}"] + ] + }, { + "type": "vmware-iso", + "guest_os_type": "ubuntu-64", + "iso_url": "{{ user `iso_url` }}", + "iso_checksum": "{{ user `iso_checksum` }}", + "iso_checksum_type": "{{ user `iso_checksum_type` }}", + "output_directory": "output-ubuntu-amd64-{{ build_type }}-{{ timestamp }}", + "vm_name": "packer-ubuntu-amd64", + "disk_size": "{{ user `disk_size` }}", + "headless": "{{ user `headless` }}", + "http_directory": "{{ user `http_dir` }}", + "boot_command": [ + "<enter><wait>", + "<f6><esc>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>", + "<bs><bs><bs>", + "/install/vmlinuz ", + "initrd=/install/initrd.gz ", + "auto-install/enable=true ", + "debconf/priority=critical ", + "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/{{ user `preseed_path` }} ", + "<enter>" + ], + "boot_wait": "5s", + "ssh_timeout": "{{ user `ssh_timeout` }}", + "ssh_username": "{{ user `ssh_username` }}", + "ssh_password": "{{ user `ssh_password` }}", + "shutdown_command": "{{ user `shutdown_command` }}", + "vmx_data": { + "memsize": "{{ user `memory` }}", + "numvcpus": "{{ user `cpus` }}" + } + }] +} |