diff --git a/Rakefile b/Rakefile index c01138f..3340813 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,3 @@ -if !File.exist?('.ssh_config') - sh "vagrant ssh-config > .ssh_config" -end - require 'chake' task :test do @@ -11,3 +7,15 @@ task :test do end task :default => :test + +file 'ssh_config.erb' +file '.ssh_config' => ['nodes.yaml', 'ssh_config.erb'] do |t| + require 'erb' + template = ERB.new(File.read('ssh_config.erb')) + File.open(t.name, 'w') do |f| + f.write(template.result(binding)) + end + puts 'ERB %s' % t.name +end + +task :bootstrap_common => '.ssh_config' diff --git a/Vagrantfile b/Vagrantfile index 78b0f4d..faea52a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,6 +1,8 @@ # -*- 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" @@ -11,20 +13,22 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.provision 'shell', path: 'utils/proxy.sh', args: [proxy] end + ips = YAML.load_file('nodes.yaml').first[1]['peers'] + config.vm.define 'integration' do |integration| - integration.vm.network 'private_network', ip: '10.1.1.1' + integration.vm.network 'private_network', ip: ips['integration'] end config.vm.define 'email' do |email| - email.vm.network 'private_network', ip: '10.1.1.2' + email.vm.network 'private_network', ip: ips['email'] end config.vm.define 'social' do |social| - social.vm.network 'private_network', ip: '10.1.1.3' + social.vm.network 'private_network', ip: ips['social'] end config.vm.define 'database' do |database| - database.vm.network 'private_network', ip: '10.1.1.4' + database.vm.network 'private_network', ip: ips['database'] end config.vm.define 'reverseproxy' do |reverseproxy| - reverseproxy.vm.network 'private_network', ip: '10.1.1.5' + reverseproxy.vm.network 'private_network', ip: ips['reverseproxy'] reverseproxy.vm.network 'forwarded_port', guest: 80, host: 8080 reverseproxy.vm.network 'forwarded_port', guest: 443, host: 8443 end diff --git a/nodes.yaml b/nodes.yaml index 93f505c..b8c9fad 100644 --- a/nodes.yaml +++ b/nodes.yaml @@ -3,11 +3,11 @@ vagrant@integration: - role[server] - role[integration_server] peers: &PEERS - integration: 10.1.1.1 - email: 10.1.1.2 - social: 10.1.1.3 - database: 10.1.1.4 - reverseproxy: 10.1.1.5 + integration: 10.10.10.2 + email: 10.10.10.3 + social: 10.10.10.4 + database: 10.10.10.5 + reverseproxy: 10.10.10.6 vagrant@email: run_list: - role[server] diff --git a/ssh_config.erb b/ssh_config.erb new file mode 100644 index 0000000..edc7c69 --- /dev/null +++ b/ssh_config.erb @@ -0,0 +1,15 @@ +Host * + User vagrant + UserKnownHostsFile /dev/null + StrictHostKeyChecking no + PasswordAuthentication no + IdentitiesOnly yes + LogLevel FATAL + +<% $nodes.each do |node| %> +Host <%= node.hostname %> + Hostname <%= node.data['peers'][node.hostname] %> + 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) } %> +<% end %> + +# vim: ft=sshconfig -- libgit2 0.21.2