diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2518846 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +output-virtualbox-iso/ +packer_cache/ +*.box diff --git a/ansible/playbook.yml b/ansible/playbook.yml new file mode 100644 index 0000000..0654869 --- /dev/null +++ b/ansible/playbook.yml @@ -0,0 +1,19 @@ +--- +- hosts: all + become: true + tasks: + + - name: Install provisioners + apt: name={{ item }} state=present + with_items: + - puppet + - chef + + - name: Vagrant insecure key + authorized_key: user=vagrant key=https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub + + - name: Insert "UseDNS no" into sshd_config + blockinfile: + dest: /etc/ssh/sshd_config + block: | + UseDNS no diff --git a/http/preseed.cfg b/http/preseed.cfg new file mode 100644 index 0000000..4482120 --- /dev/null +++ b/http/preseed.cfg @@ -0,0 +1,27 @@ +d-i time/zone string UTC +d-i debian-installer/locale string en_US +d-i keyboard-configuration/xkb-keymap select us + +d-i partman-auto/method string regular +d-i partman-auto/choose_recipe select atomic +d-i partman/choose_partition select finish +d-i partman/confirm boolean true +d-i partman/confirm_nooverwrite boolean true + +d-i passwd/root-password-again password vagrant +d-i passwd/root-password password vagrant +d-i passwd/user-fullname string vagrant +d-i passwd/username string vagrant +d-i passwd/user-password password vagrant +d-i passwd/user-password-again password vagrant +d-i user-setup/allow-password-weak boolean true + +d-i netcfg/hostname string xenial64 + +d-i pkgsel/include string openssh-server sudo + +d-i preseed/late_command string \ + echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /target/etc/sudoers.d/vagrant; \ + in-target chmod 440 /etc/sudoers.d/vagrant; + +d-i finish-install/reboot_in_progress note diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..4dde5b6 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +export DEBIAN_FRONTEND=noninteractive +sudo apt update +sudo apt install -y ansible linux-headers-$(uname -r) build-essential dkms + +sudo mkdir /media/VBoxGuestAdditions +sudo mount -o loop,ro /home/vagrant/VBoxGuestAdditions.iso /media/VBoxGuestAdditions +sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run +sudo umount /media/VBoxGuestAdditions +sudo rmdir /media/VBoxGuestAdditions +rm /home/vagrant/VBoxGuestAdditions.iso diff --git a/template.json b/template.json new file mode 100644 index 0000000..8dbc498 --- /dev/null +++ b/template.json @@ -0,0 +1,82 @@ +{ + "builders": [ + { + "type": "virtualbox-iso", + "guest_os_type": "Ubuntu_64", + "iso_url": "http://releases.ubuntu.com/16.04/ubuntu-16.04-beta2-server-amd64.iso", + "iso_checksum": "0f948fea5a587a62a873d2c001948a6ffbda20b67b05a468006caf9dfd41bcd7", + "iso_checksum_type": "sha256", + "vm_name": "packer-ubuntu-16.04-amd64", + "disk_size": "{{ user `disk_size` }}", + "headless": "{{ user `headless` }}", + "boot_wait": "5s", + "http_directory": "http", + "boot_command": [ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "/install/vmlinuz ", + "initrd=/install/initrd.gz ", + "auto=true ", + "priority=critical ", + "url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", + "" + ], + "ssh_wait_timeout": "30m", + "ssh_username": "vagrant", + "ssh_password": "vagrant", + "shutdown_command": "sudo systemctl poweroff", + "vboxmanage": [ + ["modifyvm", "{{ .Name }}", "--memory", "{{ user `memory` }}"], + ["modifyvm", "{{ .Name }}", "--cpus", "{{ user `cpus` }}"] + ] + } + ], + "provisioners": [ + { + "type": "shell", + "scripts": "scripts/install.sh" + }, + { + "type": "ansible-local", + "playbook_file": "ansible/playbook.yml", + "playbook_dir": "ansible" + } + ], + "post-processors": [ + [ + { + "type": "vagrant", + "compression_level": 9, + "output": "ubuntu-16.04-amd64.box", + "keep_input_artifact": false + }, + { + "type": "atlas", + "artifact": "s12v/xenial64", + "artifact_type": "vagrant.box", + "metadata": { + "version": "20160401", + "description": "**Ubuntu 16.04 beta 2**. Baked with https://github.com/s12v/xenial\n - Ansible, Puppet, Chef\n - VBoxGuestAdditions 5.0.x\n - 80G disk", + "created_at": "{{timestamp}}", + "provider": "virtualbox" + } + } + ] + ], + "variables": { + "cpus": "1", + "memory": "512", + "hostname": "xenial", + "headless": "false", + "disk_size": "81920" + } +}