switch to inline provisioning, use official ubuntu vagrant box

This commit is contained in:
Brent Cook 2016-06-09 09:50:15 -05:00
parent 4ade689412
commit 2534ef76f3
3 changed files with 61 additions and 127 deletions

48
Vagrantfile vendored
View File

@ -2,11 +2,49 @@
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "phusion/ubuntu-14.04-amd64"
config.ssh.forward_x11 = true
config.vm.box = "ubuntu/trusty64"
# TODO: find a minimal image that keeps up-to-date and
# supports multiple providers
#config.vm.box = "phusion/ubuntu-14.04-amd64"
config.vm.network :forwarded_port, guest: 4444, host: 4444
config.vm.provision :chef_apply do |chef|
chef.version = "latest"
chef.install = "force"
chef.recipe = IO.read("scripts/shell/provision.rb")
config.vm.provider "vmware" do |v|
v.memory = 2048
v.cpus = 2
end
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
end
%w(.vimrc .gitconfig).each do |f|
local = File.expand_path "~/#{f}"
if File.exist? local
config.vm.provision "file", source: local, destination: f
end
end
[ #"echo 127.0.1.1 `cat /etc/hostname` >> /etc/hosts", work around a bug in official Ubuntu Xenial cloud images
"apt-get update",
"apt-get dist-upgrade -y",
"apt-get -y install curl build-essential git tig vim john nmap libpq-dev libpcap-dev gnupg fortune postgresql postgresql-contrib",
].each do |step|
config.vm.provision "shell", inline: step
end
[ "gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3",
"curl -L https://get.rvm.io | bash -s stable",
"source ~/.rvm/scripts/rvm && cd /vagrant && rvm --install .ruby-version",
"source ~/.rvm/scripts/rvm && cd /vagrant && gem install bundler",
"source ~/.rvm/scripts/rvm && cd /vagrant && bundle",
"mkdir -p ~/.msf4",
].each do |step|
config.vm.provision "shell", privileged: false, inline: step
end
config.vm.provision "file", source: "config/database.yml.vagrant", destination: "~/.msf4/database.yml"
config.vm.provision "shell", inline: "sudo -u postgres psql postgres -tAc \"SELECT 1 FROM pg_roles WHERE rolname='vagrant'\" | grep -q 1 || sudo -u postgres createuser -s -e -w vagrant && sudo -u postgres psql -c \"ALTER USER vagrant with ENCRYPTED PASSWORD 'vagrant';\""
["msf_dev_db", "msf_test_db"].each do |database|
config.vm.provision "shell", inline: "sudo -u postgres psql -lqt | awk '{ print $1 }' | grep -w #{database} | wc -l | grep -q 1 || sudo -u postgres createdb --owner vagrant #{database}"
end
end

View File

@ -0,0 +1,18 @@
development: &pgsql
adapter: postgresql
database: msf_dev_db
username: vagrant
password: vagrant
host: localhost
port: 5432
pool: 200
timeout: 5
production: &production
<<: *pgsql
test:
<<: *pgsql
database: msf_test_db
username: vagrant
wassword: vagrant

View File

@ -1,122 +0,0 @@
execute "apt-get update -y"
execute "apt-get upgrade -y"
package [
"autoconf",
"bison",
"build-essential",
"curl",
"git-core",
"libapr1",
"libaprutil1",
"libcurl4-openssl-dev",
"libffi-dev",
"libgmp3-dev",
"libpcap-dev",
"libpq-dev",
"libreadline-dev",
"libreadline6-dev",
"libsqlite3-dev",
"libssl-dev",
"libsvn1",
"libtool",
"libxml2",
"libxml2-dev",
"libxslt-dev",
"libxslt1-dev",
"libyaml-dev",
"locate",
"ncurses-dev",
"openssl",
"postgresql",
"postgresql-contrib",
"python-software-properties",
"sqlite3",
"vim",
"wget",
"xsel",
"zlib1g",
"zlib1g-dev",
]
sql = "SELECT 1 FROM pg_roles WHERE rolname='vagrant'"
create_user = "createuser -s -e -w vagrant"
execute "psql postgres -tAc \"#{sql}\" | grep -q 1 || #{create_user}" do
user "postgres"
end
["vagrant", "msf_dev_db", "msf_test_db"].each do |database|
execute "sudo -u postgres createdb --owner vagrant #{database}" do
not_if "psql -lqt | awk '{ print $1 }' | grep -w #{database} | wc -l | grep -q 1"
end
end
directory "/home/vagrant/.msf4/" do
user "vagrant"
group "vagrant"
end
file "/home/vagrant/.msf4/database.yml" do
content <<-EOH
# Development Database
development: &pgsql
adapter: postgresql
database: msf_dev_db
username: vagrant
host: localhost
port: 5432
pool: 5
timeout: 5
# Production database -- same as dev
production: &production
<<: *pgsql
# Test database -- not the same, since it gets dropped all the time
test:
<<: *pgsql
database: msf_test_db
EOH
end
["postgresql"].each do |service_name|
service service_name do
action [:enable, :start]
end
end
git "/usr/local/rbenv" do
repository "https://github.com/sstephenson/rbenv.git"
end
file "/etc/profile.d/rbenv.sh" do
content <<-CONTENT
export RBENV_ROOT="/usr/local/rbenv"
export PATH="/usr/local/rbenv/bin:$PATH"
eval "$(rbenv init -)"
CONTENT
end
directory "/usr/local/rbenv/plugins"
git "/usr/local/rbenv/plugins/ruby-build" do
repository "https://github.com/sstephenson/ruby-build.git"
end
ruby_version = `cat /vagrant/.ruby-version`.strip
bash "install_ruby" do
user "root"
not_if { ::Dir.exist?("/usr/local/rbenv/versions/#{ruby_version}") }
code <<-EOH
source /etc/profile.d/rbenv.sh
rbenv install #{ruby_version}
rbenv global #{ruby_version}
EOH
end
bash "install_bundler" do
user "root"
code <<-EOH
source /etc/profile.d/rbenv.sh
gem install bundler --no-ri --no-rdoc
EOH
end