Last active
July 15, 2016 19:31
-
-
Save mynameisrufus/8dd118a396f427b34ce7 to your computer and use it in GitHub Desktop.
Vagrant dynamic port mapping
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
--- | |
- mapping: '80:8082' | |
role: nil | |
- mapping: '53:5350/udp,53:5350,8081' | |
role: 'powerdns' | |
- mapping: '2003,4444/udp,9200,9300' | |
role: 'logging' | |
- mapping: '4000,4560,5000' | |
role: 'metrics' |
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 : | |
require 'yaml' | |
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | |
VAGRANTFILE_API_VERSION = "2" | |
# Load mappings.yml | |
MAPPINGS = YAML.load_file('mappings.yml') | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
MAPPINGS.each do |maps| | |
maps["mapping"].split(/,/).each do |mapping| | |
guest, host = mapping.split(/:/) | |
host, protocol = (host || guest).to_s.split(/\//) | |
config.vm.network :forwarded_port, guest: guest.gsub(/\/.*/, ''), host: (host || guest), protocol: (protocol || "tcp") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recommend checking in a
mappings.example.yml
and addingmappings.yml
to your.gitignore
.