Home

Awesome

vagrant-shell-scripts

A collection of scripts (Ubuntu-only at this time) to ease Vagrant box provisioning using the shell method.

Usage

  1. Place on top of your Vagrantfile before Vagrant.configure(..):

    require File.join(File.dirname(__FILE__), 'path/to/vagrant-shell-scripts/vagrant')
    
  2. Place at the end of your Vagrantfile before the last end:

    config.vm.provision :shell do |shell|
        vagrant_shell_scripts_configure(
            shell,
            File.dirname(__FILE__),
            'path/to/provisioning_script'
        )
    end
    
  3. Place on top of your provisioning script:

    #!/usr/bin/env bash
    
    <%= import 'ubuntu.sh' %>
    

Functions

Utility

Nameservers

Aptitude

System

Default Commands

Apache

Nginx

PHP

MySQL

RubyGems

NPM (Node Package Manager)

GitHub

Environment

Extras

The ubuntu-extras.sh file provides useful but rarely used commands.

Archives

Packages (e.g., ZIP distributions)

Temporary Files

PostgreSQL

The ubuntu-postgres.sh file provides functions for manipulating a PostgreSQL server instance.

Postfix

The ubuntu-postfix.sh file provides functions for manipulating an SMTP server instance using Postfix.

Environment

The following variables can be defined before including the ubuntu.sh script:

Goal

As I explore different OSes, I hope to add support for more platforms.

The functions should remain the same, so provisioning scripts are somewhat 'portable'.

Full Example

The provisioning script below sets up Apache, SuExec, a virtual host for /vagrant (the default share) and remote root access to MySQL.

#!/usr/bin/env bash

# {{{ Ubuntu utilities

<%= import 'vagrant-shell-scripts/ubuntu.sh' %>

# }}}

# Use Google Public DNS for resolving domain names.
# The default is host-only DNS which may not be installed.
nameservers-local-purge
nameservers-append '8.8.8.8'
nameservers-append '8.8.4.4'

# Use a local Ubuntu mirror, results in faster downloads.
apt-mirror-pick 'bg'

# Update packages cache.
apt-packages-update

# Install VM packages.
apt-packages-install     \
  apache2-mpm-worker     \
  apache2-suexec-custom  \
  mysql-server-5.1       \
  libapache2-mod-fastcgi \
  php5-cgi               \
  php5-gd                \
  php5-mysql

# Allow modules for Apache.
apache-modules-enable actions rewrite fastcgi suexec

# Replace the default Apache site.
PHP=/usr/bin/php-cgi apache-sites-create 'vagrant'
apache-sites-disable default default-ssl
apache-sites-enable vagrant

# Restart Apache web service.
apache-restart

# Allow unsecured remote access to MySQL.
mysql-remote-access-allow

# Restart MySQL service for changes to take effect.
mysql-restart

Copyright

Copyright (c) 2012 Stan Angeloff. See LICENSE.md for details.