Last active
October 14, 2015 01:07
-
-
Save ernestom/4284042 to your computer and use it in GitHub Desktop.
Vagrantfile base entutele
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# | |
# This file should be one directory above. | |
# | |
# Example: | |
# | |
# $ pwd | |
# /Users/ernesto/Code/Menta/enlatele <-- This is the vagrant project | |
# shared with the guest VM via NFS | |
# $ ls -1a | |
# . | |
# .. | |
# .DS_Store | |
# .vagrant | |
# Vagrantfile | |
# current <-- This is the git repo checkout | |
# | |
# $ tree -L 2 | |
# . | |
# |-- Vagrantfile <-- This file is the one Vagrant will actually | |
# `-- current use to override the one included in the VM | |
# |-- README.md | |
# |-- Vagrantfile.dist <-- This file is here for reference | |
# |-- config and version control | |
# |-- data | |
# |-- enlatele | |
# |-- fabfile.py | |
# |-- scripts | |
# |-- site | |
# `-- tests | |
# | |
# | |
require 'chef' | |
require 'chef/config' | |
require 'chef/knife' | |
unless ENV.include? 'CHEF_REPO' | |
puts 'The CHEF_REPO environment variable must be set.' | |
exit 1 | |
end | |
$host_name = `hostname -s`.strip | |
$chef_dir = File.join(ENV['CHEF_REPO'], '/.chef') | |
$knife_config = File.join($chef_dir, 'knife.rb') | |
Chef::Config.from_file(File.join($chef_dir, 'knife.rb')) | |
# | |
# monkeypatching the Vagrant provisioner | |
# to remove the node and client related to this VM | |
# after executing `vagrant destroy` | |
# | |
module Vagrant | |
module Provisioners | |
class Base | |
def cleanup | |
env[:ui].info "Attempting to remove client #{env[:vm].config.vm.host_name}" | |
`knife client show #{env[:vm].config.vm.host_name} -c #{$knife_config}` | |
if $?.to_i == 0 | |
env[:ui].info "Removing client #{env[:vm].config.vm.host_name}" | |
`knife client delete #{env[:vm].config.vm.host_name} -y -c #{$knife_config}` | |
end | |
env[:ui].info "Attempting to remove node #{env[:vm].config.vm.host_name}" | |
`knife node show #{env[:vm].config.vm.host_name} -c #{$knife_config}` | |
if $?.to_i == 0 | |
env[:ui].info "Removing node #{env[:vm].config.vm.host_name}" | |
`knife node delete #{env[:vm].config.vm.host_name} -y -c #{$knife_config}` | |
end | |
end | |
end | |
end | |
end | |
Vagrant::Config.run do |config| | |
config.vm.box = 'enlatele' | |
config.vm.network :hostonly, '192.168.56.101' | |
config.vm.share_folder( | |
'app_git_checkout', | |
'/data/sites/enlatele/', | |
'enlatele', | |
{:nfs => true, :create => true} | |
) | |
config.vm.share_folder( | |
'menta_lib_git_checkout', | |
'/usr/local/lib/menta/', | |
'menta', | |
{:nfs => true, :create => true} | |
) | |
config.vm.host_name = $host_name + '.entutele.dev' | |
config.vm.provision :chef_client do |chef| | |
chef.chef_server_url = Chef::Config[:chef_server_url] | |
chef.validation_key_path = "#{$chef_dir}/#{Chef::Config[:validation_client_name]}.pem" | |
chef.validation_client_name = Chef::Config[:validation_client_name] | |
chef.environment = 'dev' | |
chef.add_role 'enlatele' | |
chef.log_level = :debug | |
end | |
#config.ssh.username = 'menta' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment