Commit aede9435a93d5aaffe51a310cdeb38a496039dfc

Authored by Antonio Terceiro
1 parent b02ece51

centralize IP configuration for development environment

Rakefile
1   -if !File.exist?('.ssh_config')
2   - sh "vagrant ssh-config > .ssh_config"
3   -end
4   -
5 1 require 'chake'
6 2  
7 3 task :test do
... ... @@ -11,3 +7,15 @@ task :test do
11 7 end
12 8  
13 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 1 # -*- mode: ruby -*-
2 2 # vi: set ft=ruby :
3 3  
  4 +require 'yaml'
  5 +
4 6 # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5 7 VAGRANTFILE_API_VERSION = "2"
6 8  
... ... @@ -11,20 +13,22 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
11 13 config.vm.provision 'shell', path: 'utils/proxy.sh', args: [proxy]
12 14 end
13 15  
  16 + ips = YAML.load_file('nodes.yaml').first[1]['peers']
  17 +
14 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 20 end
17 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 23 end
20 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 26 end
23 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 29 end
26 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 32 reverseproxy.vm.network 'forwarded_port', guest: 80, host: 8080
29 33 reverseproxy.vm.network 'forwarded_port', guest: 443, host: 8443
30 34 end
... ...
nodes.yaml
... ... @@ -3,11 +3,11 @@ vagrant@integration:
3 3 - role[server]
4 4 - role[integration_server]
5 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 11 vagrant@email:
12 12 run_list:
13 13 - role[server]
... ...
ssh_config.erb 0 → 100644
... ... @@ -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
... ...