packer.io - pretty darn cool

I was messing around twitter last week and noticed this new project called packer.io.  What it basically does is allow you to build a repeatable image for virtualbox(as well as amazon, digital ocean, and vmware fusion) from a pretty small json file.  Here is a template(example.json) I created which builds our typical ubuntu image for virtualbox :

{

“builders”: [{

“type”: “virtualbox”,

“guest_os_type”: “Linux”,

“iso_url”: “http://mirrors.us.kernel.org/ubuntu-releases/12.04/ubuntu-12.04.2-server-amd64.iso”,

“iso_md5”: “af5f788aee1b32c4b2634734309cc9e9”,

“ssh_username”: “root”,

“ssh_password”: “root”,

“ssh_wait_timeout”: “30m”,

“boot_command”:[

 "<esc><esc><enter><wait>“,

 ”/install/vmlinuz noapic “,

 "preseed/url=http://<a url somewhere>/ubuntu-nqa.seed ”,

 "debian-installer=en_US auto locale=en_US kbd-chooser/method=us “,

 "hostname=unassigned-hostname ”,

 "fb=false debconf/frontend=noninteractive “,

 "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ”,

 "keyboard-configuration/variant=USA console-setup/ask_detect=false “,

 "initrd=/install/initrd.gz – <enter>”

]

}],

“provisioners”: [{

    “type”: “shell”,

    “inline”: [

      “sudo apt-get update”,

      “sudo apt-get upgrade -y”,

      “sudo apt-get install -y redis-server”,

      “sudo apt-get update”,

      “sudo apt-get install -y python-software-properties python g++ make”,

“sudo add-apt-repository -y ppa:chris-lea/node.js”,

“sudo apt-get update”,

“sudo apt-get install -y nodejs”

    ]

  }]

}

So in the above json, I provide the iso_url of a ubuntu mirror that contains the ubuntu install I’m interested in, a pre-seed url contain all my preset ubuntu settings, and a provisioner which installs all the stuff I typically want on my images(redis, node).  I then run ’packer build  example.json’ and in about 20 minutes(maybe faster depending on CPU and download speeds) I have an ovf and vmdk file which I can bring into virtualbox and run. There are a couple of items that I’m still trying to get working.  Currently I ssh in as root to install software.  I want to be able to create a non root user to do this.(currently it hangs because it wants me to enter a password for each sudo command).  I also want to be able to use this with vagrant.  I unfortunately installed a version of virtualbox that doesn’t work too well with vagrant.  I’ve just touched the surface of packer.io.  Please check out the project at Packer.io .

For reference, here is my pre-seed file(make sure root passwords matchup here and in the example.json file):

# Ubuntu Server Quick Install

# by Dustin Kirkland <[email protected]>

#  * Documentation: http://bit.ly/uquick-doc

d-i     debian-installer/locale string en_US.UTF-8

d-i     debian-installer/splash boolean false

d-i     console-setup/ask_detect        boolean false

d-i     console-setup/layoutcode        string us

d-i     console-setup/variantcode       string

d-i     netcfg/get_nameservers  string

d-i     netcfg/get_ipaddress    string

d-i     netcfg/get_netmask      string 255.255.255.0

d-i     netcfg/get_gateway      string

d-i     netcfg/confirm_static   boolean true

d-i     clock-setup/utc boolean true

d-i time/zone string US/Eastern

d-i mirror/country string US

d-i mirror/http/proxy string

d-i     partman-auto/method string regular

d-i     partman-lvm/device_remove_lvm boolean true

d-i     partman-lvm/confirm boolean true

d-i     partman/confirm_write_new_label boolean true

d-i     partman/choose_partition        select Finish partitioning and write changes to disk

d-i     partman/confirm boolean true

d-i     partman/confirm_nooverwrite boolean true

d-i     partman/default_filesystem string ext3

d-i     clock-setup/utc boolean true

d-i     clock-setup/ntp boolean true

d-i     clock-setup/ntp-server  string ntp.ubuntu.com

d-i     base-installer/kernel/image     string linux-server

d-i     user-setup/allow-password-weak  boolean true

d-i     passwd/root-login       boolean true

d-i passwd/root-password password root

d-i passwd/root-password-again password root

d-i     passwd/make-user        boolean true

d-i     passwd/user-fullname    string ubuntu

d-i     passwd/username string ubuntu

d-i     passwd/user-password-crypted    password $6$.1eHH0iY$ArGzKX2YeQ3G6U.mlOO3A.NaL22Ewgz8Fi4qqz.Ns7EMKjEJRIW2Pm/TikDptZpuu7I92frytmk5YeL.9fRY4.

d-i     passwd/user-uid string

d-i     user-setup/encrypt-home boolean false

d-i     passwd/user-default-groups      string adm cdrom dialout lpadmin plugdev sambashare

d-i     apt-setup/services-select       multiselect security

d-i     apt-setup/security_host string security.ubuntu.com

d-i     apt-setup/security_path string /ubuntu

d-i     debian-installer/allow_unauthenticated  string false

tasksel tasksel/first multiselect ubuntu-server 

d-i pkgsel/include string openssh-server 

d-i     pkgsel/upgrade  select safe-upgrade

d-i     pkgsel/language-packs   multiselect

d-i     pkgsel/update-policy    select none

d-i     pkgsel/updatedb boolean true

d-i     grub-installer/skip     boolean false

d-i     lilo-installer/skip     boolean false

d-i     grub-installer/only_debian      boolean true

d-i     grub-installer/with_other_os    boolean true

d-i     finish-install/keep-consoles    boolean false

d-i     finish-install/reboot_in_progress       note

d-i     cdrom-detect/eject      boolean true

d-i     debian-installer/exit/halt      boolean false

d-i     debian-installer/exit/poweroff  boolean false

d-i     pkgsel/include string byobu vim openssh-server

byobu   byobu/launch-by-default boolean true