Machines

A custom Ubuntu system in less than 15 minutes

Setup Ubuntu development and server Machines locally or in the cloud for developing and hosting Ruby, Rails and related environments.

Write commands in Ruby like:

sudo install %w(build-essential zlib1g-dev libpcre3-dev)
sudo write "127.0.1.1\t#{$conf.hostname}", :to => '/etc/hosts'
sudo append "192.168.1.2\tserver", :to => '/etc/hosts'
run download $conf.nginx.url
run create_from 'nginx/nginx.conf.erb', :to => File.join($conf.nginx.path, 'conf', 'nginx.conf')

Example to upgrade passenger:

machines build phil_workstation passenger_nginx

RubyDoc.info documentation

Status

March 2013

Features

What it's Not

Motivation

Configuration management is a complex topic. I wanted to reduce some of the variables (single target platform, single development environment) to provide a simpler solution.

Overview

The top level script is the Machinesfile. This contains a list of packages to run. Packages contain one or more tasks and the tasks contain the commands to run. Default packages are provided by Machines. Default packages can be overridden and new ones created.

Commands are added to a queue with sudo or run. lib/packages contains the packages you can add in the Machinesfile in Machines. Once the build starts the commands are run and shown with the current progress.

Installation and Configuration

Install the gem

gem install machines

Generate an example project

machines new example

Configure your deployment

Take a look at the generated project. It contains several folders with templates and configuration settings for various programs, your Machinesfile and the various .yml files.

So here is the recommended approach to configuring your environment:

Prepare the target machine

Check the Machinesfile

machines dryrun <machine>
cat log/output.log

Check the machine

ssh-keygen -R <host ip> # remove host from known_hosts file (handy when testing)
$ ssh <IP ADDRESS>      # Make sure you can connect to the machine

Build the machine

$ machines build <machine>

Console output:

While running open another terminal to view detailed output:

tail -f log/output.log

or debug:

tail -f log/debug.log

Commandline Options

machines COMMAND
COMMAND can be:
  htpasswd                 Generates basic auth in webserver/conf/htpasswd
  new <DIR>                Generates an example machines project in DIR
  dryrun                   Logs commands but does not run them
  tasks                    Lists the available tasks
  build <machine> [task]   Builds your chosen machine. Optionally, build just one task
  packages                 Lists the available packages
  override <PACKAGE>       Copies the default package into project/packages so it can be edited/overidden

Global settings

Machines uses a gem I wrote called app_conf. It allows settings to be loaded from YAML and also set using Ruby. Machines uses it both internally and for package settings. Some of the settings set and used by Machines are:

Take a look at template/*.yml for more.

Commands

Commands you can use with run or sudo are in the following modules (links to rdoc):

When creating your own commands the Checks module should be useful.

Setting up a test VM

Make sure you've downloaded one of the ISOs from the list in Prepare the target machine.

  1. Download and install VirtualBox
  2. Oracle VirtualBox -> New
    • Name: machinesvm
    • Operating System: Linux
    • Version: Ubuntu (64 bit)
  3. Settings -> Network -> Adapter 2 -> Enable Network Adapter
    • Attached to: Host-only Adapter
  4. Start VM -> Next -> Media Source folder icon (next to dropdown) -> mini.iso -> Next -> Start
  5. Ubuntu Installer boot menu -> Install -> Accept defaults except for:
    • Select correct country/keyboard
    • Primary network interface: eth0
    • Full name for the new user: user
    • Username for your account: user
    • Choose a password for the new user: password
    • Re-enter password to verify: password
    • YES to partition disks (choose partition entire disk if asked)
    • Add OpenSSH from application installer menu
  6. Devices -> CD/DVD Devices -> Uncheck mini.iso
  7. Reboot and login
    • login: user
    • Password: password
  8. Run ifconfig and make a note of the eth1 inet addr. It should be 192.168.56.101 if this is the first VM you've installed
    • If you don't see eth1 then sudo nano /etc/network/interfaces and add the lines auto eth1 and iface eth1 inet dhcp as with eth0. Save and exit. Run ifconfig again and note the inet addr of eth1
  9. Take a snapshot (restore before each test run)

What's happening under the hood

Limitations

Development, Patches, Pull Requests

References

APIs

General

RVM

Ubuntu minimal install guides

Acknowledgements

Thanks to all the people that published the hundreds of articles, blog posts and APIs I've read.

Copyright

Copyright (c) 2010, 2011, 2012, 2013 Phil Thompson. See LICENSE for details.