Skip to content

Instantly share code, notes, and snippets.

@davidmnoriega
Last active April 5, 2018 17:15
Show Gist options
  • Save davidmnoriega/cf610a06fd50d174688ae7ee4133bcec to your computer and use it in GitHub Desktop.
Save davidmnoriega/cf610a06fd50d174688ae7ee4133bcec to your computer and use it in GitHub Desktop.
My common Vagrantfile
Vagrant.configure("2") do |config|
if Vagrant.has_plugin?("vagrant-timezone")
# Sets guest timezone to be the same as the host
config.timezone.value = :host
end
# I run a local squid proxy for yum/apt
# See https://github.com/davidmnoriega/docker-squid
# The IPs specified here might not be universal
if Vagrant.has_plugin?("vagrant-proxyconf")
config.vm.provider "vmware_desktop" do |vm, override|
override.vm.provision :hosts do |provisioner|
provisioner.add_host '192.168.247.1', ['proxy.vagrant']
end
end
config.vm.provider :virtualbox do |vb, override|
override.vm.provision :hosts do |provisioner|
provisioner.add_host '10.0.2.2', ['proxy.vagrant']
end
end
config.apt_proxy.http = "http://proxy.vagrant:3128"
config.apt_proxy.https = "DIRECT"
config.yum_proxy.http = "http://proxy.vagrant:3128"
end
config.vm.provision "shell", inline: $provision_yum_proxy
config.vm.provider "vmware_desktop" do |vm, override|
override.vm.provision "shell", inline: $fix_vmware_tools_script
end
end
# Yum needs more help to fully use my local proxy
# http://serverascode.com/2014/03/29/squid-cache-yum.html
$provision_yum_proxy = <<'SCRIPT'
if [ -f /etc/yum.conf ]; then
echo "Updating yum repo config for proxy"
sed -e '/^mirrorlist/ s/^#*/#/' -i /etc/yum.repos.d/CentOS-Base.repo
sed -e '/^#baseurl/ s/#//' -i /etc/yum.repos.d/CentOS-Base.repo
sed -i -e 's/enabled=1/enabled=0/g' /etc/yum/pluginconf.d/fastestmirror.conf
else
echo "Skipping yum proxy config"
fi
SCRIPT
# Incase I upgrade the guest kernel
$fix_vmware_tools_script = <<'SCRIPT'
if [ -f /etc/vmware-tools/locations ]; then
echo "fix vmware tools"
if [ -f /etc/yum.conf ]; then
yum -y -q -e 0 install net-tools kernel-headers kernel-devel gcc
fi
sed -i.bak 's/answer AUTO_KMODS_ENABLED_ANSWER no/answer AUTO_KMODS_ENABLED_ANSWER yes/g' /etc/vmware-tools/locations
sed -i 's/answer AUTO_KMODS_ENABLED no/answer AUTO_KMODS_ENABLED yes/g' /etc/vmware-tools/locations
else
echo "Skipping fix vmware tools"
fi
SCRIPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment