Commit aede9435a93d5aaffe51a310cdeb38a496039dfc
1 parent
b02ece51
Exists in
master
and in
90 other branches
centralize IP configuration for development environment
Showing
4 changed files
with
41 additions
and
14 deletions
Show diff stats
Rakefile
| 1 | -if !File.exist?('.ssh_config') | ||
| 2 | - sh "vagrant ssh-config > .ssh_config" | ||
| 3 | -end | ||
| 4 | - | ||
| 5 | require 'chake' | 1 | require 'chake' |
| 6 | 2 | ||
| 7 | task :test do | 3 | task :test do |
| @@ -11,3 +7,15 @@ task :test do | @@ -11,3 +7,15 @@ task :test do | ||
| 11 | end | 7 | end |
| 12 | 8 | ||
| 13 | task :default => :test | 9 | task :default => :test |
| 10 | + | ||
| 11 | +file 'ssh_config.erb' | ||
| 12 | +file '.ssh_config' => ['nodes.yaml', 'ssh_config.erb'] do |t| | ||
| 13 | + require 'erb' | ||
| 14 | + template = ERB.new(File.read('ssh_config.erb')) | ||
| 15 | + File.open(t.name, 'w') do |f| | ||
| 16 | + f.write(template.result(binding)) | ||
| 17 | + end | ||
| 18 | + puts 'ERB %s' % t.name | ||
| 19 | +end | ||
| 20 | + | ||
| 21 | +task :bootstrap_common => '.ssh_config' |
Vagrantfile
| 1 | # -*- mode: ruby -*- | 1 | # -*- mode: ruby -*- |
| 2 | # vi: set ft=ruby : | 2 | # vi: set ft=ruby : |
| 3 | 3 | ||
| 4 | +require 'yaml' | ||
| 5 | + | ||
| 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! | 6 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! |
| 5 | VAGRANTFILE_API_VERSION = "2" | 7 | VAGRANTFILE_API_VERSION = "2" |
| 6 | 8 | ||
| @@ -11,20 +13,22 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | @@ -11,20 +13,22 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | ||
| 11 | config.vm.provision 'shell', path: 'utils/proxy.sh', args: [proxy] | 13 | config.vm.provision 'shell', path: 'utils/proxy.sh', args: [proxy] |
| 12 | end | 14 | end |
| 13 | 15 | ||
| 16 | + ips = YAML.load_file('nodes.yaml').first[1]['peers'] | ||
| 17 | + | ||
| 14 | config.vm.define 'integration' do |integration| | 18 | config.vm.define 'integration' do |integration| |
| 15 | - integration.vm.network 'private_network', ip: '10.1.1.1' | 19 | + integration.vm.network 'private_network', ip: ips['integration'] |
| 16 | end | 20 | end |
| 17 | config.vm.define 'email' do |email| | 21 | config.vm.define 'email' do |email| |
| 18 | - email.vm.network 'private_network', ip: '10.1.1.2' | 22 | + email.vm.network 'private_network', ip: ips['email'] |
| 19 | end | 23 | end |
| 20 | config.vm.define 'social' do |social| | 24 | config.vm.define 'social' do |social| |
| 21 | - social.vm.network 'private_network', ip: '10.1.1.3' | 25 | + social.vm.network 'private_network', ip: ips['social'] |
| 22 | end | 26 | end |
| 23 | config.vm.define 'database' do |database| | 27 | config.vm.define 'database' do |database| |
| 24 | - database.vm.network 'private_network', ip: '10.1.1.4' | 28 | + database.vm.network 'private_network', ip: ips['database'] |
| 25 | end | 29 | end |
| 26 | config.vm.define 'reverseproxy' do |reverseproxy| | 30 | config.vm.define 'reverseproxy' do |reverseproxy| |
| 27 | - reverseproxy.vm.network 'private_network', ip: '10.1.1.5' | 31 | + reverseproxy.vm.network 'private_network', ip: ips['reverseproxy'] |
| 28 | reverseproxy.vm.network 'forwarded_port', guest: 80, host: 8080 | 32 | reverseproxy.vm.network 'forwarded_port', guest: 80, host: 8080 |
| 29 | reverseproxy.vm.network 'forwarded_port', guest: 443, host: 8443 | 33 | reverseproxy.vm.network 'forwarded_port', guest: 443, host: 8443 |
| 30 | end | 34 | end |
nodes.yaml
| @@ -3,11 +3,11 @@ vagrant@integration: | @@ -3,11 +3,11 @@ vagrant@integration: | ||
| 3 | - role[server] | 3 | - role[server] |
| 4 | - role[integration_server] | 4 | - role[integration_server] |
| 5 | peers: &PEERS | 5 | peers: &PEERS |
| 6 | - integration: 10.1.1.1 | ||
| 7 | - email: 10.1.1.2 | ||
| 8 | - social: 10.1.1.3 | ||
| 9 | - database: 10.1.1.4 | ||
| 10 | - reverseproxy: 10.1.1.5 | 6 | + integration: 10.10.10.2 |
| 7 | + email: 10.10.10.3 | ||
| 8 | + social: 10.10.10.4 | ||
| 9 | + database: 10.10.10.5 | ||
| 10 | + reverseproxy: 10.10.10.6 | ||
| 11 | vagrant@email: | 11 | vagrant@email: |
| 12 | run_list: | 12 | run_list: |
| 13 | - role[server] | 13 | - role[server] |
| @@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
| 1 | +Host * | ||
| 2 | + User vagrant | ||
| 3 | + UserKnownHostsFile /dev/null | ||
| 4 | + StrictHostKeyChecking no | ||
| 5 | + PasswordAuthentication no | ||
| 6 | + IdentitiesOnly yes | ||
| 7 | + LogLevel FATAL | ||
| 8 | + | ||
| 9 | +<% $nodes.each do |node| %> | ||
| 10 | +Host <%= node.hostname %> | ||
| 11 | + Hostname <%= node.data['peers'][node.hostname] %> | ||
| 12 | + IdentityFile <%= (Dir.glob(".vagrant/machines/#{node.hostname}/*/private_key") + [File.expand_path('~/.vagrant.d/insecure_private_key')]).find { |f| File.exists?(f) }.tap { |f| File.expand_path(f) } %> | ||
| 13 | +<% end %> | ||
| 14 | + | ||
| 15 | +# vim: ft=sshconfig |