Skip to content

Instantly share code, notes, and snippets.

@rob-gordon
Last active April 4, 2017 21:51
Show Gist options
  • Select an option

  • Save rob-gordon/48070afe880cbac3074228d9d45814b1 to your computer and use it in GitHub Desktop.

Select an option

Save rob-gordon/48070afe880cbac3074228d9d45814b1 to your computer and use it in GitHub Desktop.
local_wp_env.Vagrantfile
VAGRANTFILE_API_VERSION = "2"
## Configuration ##
site_title = myvar = ENV['SITENAME'] || "wordpress"
php_version = ENV['VERSION'] || "7.0"
generate_wp_config_local = ENV['GENERATE'] || true
## End Configuration ##
def gui_enabled?
!ENV.fetch('GUI', '').empty?
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.provider "virtualbox" do |v|
v.gui = gui_enabled?
host = RbConfig::CONFIG['host_os']
# Give VM 1/4 system memory
if host =~ /darwin/
# sysctl returns Bytes and we need to convert to MB
mem = `sysctl -n hw.memsize`.to_i / 1024
elsif host =~ /linux/
# meminfo shows KB and we need to convert to MB
mem = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i
elsif host =~ /mswin|mingw|cygwin/
# Windows code via https://github.com/rdsubhas/vagrant-faster
mem = `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i / 1024
end
mem = mem / 1024 / 4
v.customize ["modifyvm", :id, "--memory", mem]
end
config.vm.network "private_network", type: "dhcp"
config.vm.synced_folder ".", "/var/www",
type: "nfs",
options: [
"rw",
"no_subtree_check",
"all_squash",
"async"
]
# download provision file
config.vm.provision "shell" do |s|
s.inline = 'wget -O "/var/www/provision.yml" "https://gist.githubusercontent.com/rob-gordon/3e2e8a9e81b9e9e5061dcd3f032542f0/raw/6de12200ba4774d9220f3f848aece7f306cc8575/lamp-prov.yml"'
end
# download apache conf file
config.vm.provision "shell" do |s|
s.inline = 'wget -O "/var/www/000-default.conf" "https://gist.githubusercontent.com/rob-gordon/31a72b7c5022037d63e5c01beb7e1c09/raw/4b8511668b457158c08ed217a18d20ea143f8770/000-default.conf"'
end
# bootstrap the vm...
# config.vm.provision "shell" do |s|
# s.inline = "cp -fv /var/www/tctmd/resources/vagrant/.bashrc /home/vagrant/.bashrc"
# end
# config.vm.provision "shell" do |s|
# s.inline = "chown -v vagrant: /home/vagrant/.bashrc"
# end
config.vm.provision "shell" do |s|
s.inline = "apt install -y ansible"
end
# build the stack
config.vm.provision "ansible_local" do |ansible|
ansible.provisioning_path = "/var/www"
ansible.playbook = "provision.yml"
ansible.extra_vars = {
"sitetitle" => site_title,
"php_version" => php_version
}
end
end
# Make wp-config-local.php
if generate_wp_config_local then
File.open("wp-config-local.php", 'w') {|f| f.write("<?php\n\tdefine('DB_NAME', 'wordpress');\n\tdefine('DB_USER', 'wordpress');\n\tdefine('DB_PASSWORD', 'wordpress');\n\tdefine('DB_HOST', 'localhost');") }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment