7/28/2016 - 5:10 PM

Vagrantfile with postgres

Vagrantfile with postgres

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!

$script = <<SCRIPT
  echo "-------------------- updating package lists"
  apt-get update

  # gotta put this before the upgrade, b/c it reboots and then all commands are lost
  echo "-------------------- installing postgres"
  apt-get install postgresql

  # fix permissions
  echo "-------------------- fixing listen_addresses on postgresql.conf"
  sudo sed -i "s/#listen_address.*/listen_addresses '*'/" /etc/postgresql/9.1/main/postgresql.conf

  echo "-------------------- fixing postgres pg_hba.conf file"
  # replace the ipv4 host line with the above line
  sudo cat >> /etc/postgresql/9.1/main/pg_hba.conf <<EOF
  # Accept all IPv4 connections - FOR DEVELOPMENT ONLY!!!
  host    all         all             md5

  echo "-------------------- creating postgres vagrant role with password vagrant"
  # Create Role and login
  sudo su postgres -c "psql -c \"CREATE ROLE vagrant SUPERUSER LOGIN PASSWORD 'vagrant'\" "

  echo "-------------------- creating wtm database"
  # Create WTM database
  sudo su postgres -c "createdb -E UTF8 -T template0 --locale=en_US.utf8 -O vagrant wtm"

  echo "-------------------- upgrading packages to latest"
  apt-get upgrade -y

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Every Vagrant virtual environment requires a box to build off of. = "precise32"

  # speed up apt-get
  config.cache.auto_detect = true

  # The url from where the '' box will be fetched if it
  # doesn't already exist on the user's system.
  config.vm.box_url = ""

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine. :forwarded_port, guest: 5432, host: 5433

  # Run the shell script inline provisioner
  config.vm.provision "shell", inline: $script

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # :private_network, ip: ""

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # :public_network

  # If true, then any SSH connections made will enable agent forwarding.
  # Default value: false
  # config.ssh.forward_agent = true