Skip to content

Instantly share code, notes, and snippets.

@Daemoen
Last active October 18, 2018 18:13
Show Gist options
  • Save Daemoen/b23ea859c7e8098e2395187de9f75f2d to your computer and use it in GitHub Desktop.
Save Daemoen/b23ea859c7e8098e2395187de9f75f2d to your computer and use it in GitHub Desktop.
Vagrantfile template that is extremely flexible and includes dynamic definitions, ansible playbook usage, and dynamic ansible logging
required_plugins = %w(vagrant-s3auth vagrant-vbguest)
plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
puts "Installing plugins: #{plugins_to_install.join(' ')}"
if system "vagrant plugin install #{plugins_to_install.join(' ')}"
exec "vagrant #{ARGV.join(' ')}"
else
abort "Installation of one or more plugins has failed. Aborting."
end
end
ENV['AWS_PROFILE'] = 'profile_name'
Vagrant.configure(2) do |config|
################################
# Shared Settings
###############################
config.vm.boot_timeout = 450
################################
# Development Boxes
###############################
[
{ 'name' => 'boxname_str', 'version' => 'version_str', 'revision' => 'revision_str', 'ip' => 'ip_addr', 'port' => port_int, 'book' => 'playbook_str', 'log' => bool }
].each do |db|
config.vm.define db['name'], autostart: false do |host|
host.vm.box = 'basename_str' + db['version'] + "-" + db['revision']
host.vm.box_url = 's3://bucket_str/' + host.vm.box
host.vm.network 'forwarded_port', guest: 22, host: db['port'], id: 'ssh'
host.vm.network 'private_network', ip: db['ip'],
nictype: 'virtio'
host.vm.synced_folder '.', '/vagrant', disabled: true
if db['book'] != ''
host.vm.provision 'ansible' do |ansible|
# ansible.inventory_path = 'inventory/vagrant'
ansible.extra_vars = {
varname: 'value'
}
ansible.playbook = 'playbooks/' + db['book'] + '.yml'
ansible.verbose = db['log'] ### Change the 'log' element above to True or vvv to enable verbose logging
end
end
end
end
# default global settings
config.vm.provider 'virtualbox' do |vb|
vb.gui = false
vb.memory = '1024'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment