Last active
April 10, 2024 15:13
-
-
Save radicaldingos/504d9db89b1ea89774b1 to your computer and use it in GitHub Desktop.
Example of Vagrantfile with config stored in an external YAML file. It looks for a "vagrant.yml.dist" file, which can be overloaded by a "vagrant.yml".
This file contains hidden or 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
# encoding: utf-8 | |
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
require 'yaml' | |
# Load settings from vagrant.yml or vagrant.yml.dist | |
current_dir = File.dirname(File.expand_path(__FILE__)) | |
if File.file?("#{current_dir}/vagrant.yml") | |
config_file = YAML.load_file("#{current_dir}/vagrant.yml") | |
else | |
config_file = YAML.load_file("#{current_dir}/vagrant.yml.dist") | |
end | |
settings = config_file['configs'][config_file['configs']['use']] | |
# Deploy vagrant box | |
Vagrant.configure(2) do |config| | |
config.vm.box = settings['box_name'] | |
config.vm.box_url = settings['box_url'] | |
#config.ssh.private_key_path = "~/.ssh/authorized_keys" | |
# config.vm.network "forwarded_port", guest: 80, host: 8080 | |
config.vm.network "private_network", ip: settings['vm_ip'] | |
config.vm.synced_folder ".", settings['vm_project_path'], create: true, owner: "vagrant", group: "vagrant", mount_options: ["dmode=775", "fmode=774"] | |
config.vm.provider "virtualbox" do |vb| | |
vb.name = settings['vm_name'] | |
vb.memory = settings['vm_memory'] | |
vb.cpus = settings['vm_cpus'] | |
end | |
# Shell provisioning | |
config.vm.provision "shell" do |s| | |
s.path = "bin/provisioning.sh" | |
s.args = [ settings['vm_project_path'], settings['vm_db_name'], settings['vm_db_user'] ] | |
s.privileged = true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's the line which determine the selected configuration in a YAML with the following format:
You can adapt it with your specific configuration format.