From 8095174d592675d5cf6e756e8dd5a7761e67d2df Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 30 Dec 2010 14:25:28 +0100 Subject: [PATCH] automagically register tinc nodes Now, tinc nodes automagically organize themself within their network, so you shouldn't have to do anything anymore. --- manifests/vpn_net.pp | 19 +++++++++++++++++-- templates/tinc.conf.erb | 4 +++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/manifests/vpn_net.pp b/manifests/vpn_net.pp index 4bda608..7bca35e 100644 --- a/manifests/vpn_net.pp +++ b/manifests/vpn_net.pp @@ -1,6 +1,6 @@ define tinc::vpn_net( $ensure = present, - $connect_to_hosts = [], + $hosts_path = 'absent', $connect_on_boot = true, $key_source_path = 'absent', $tinc_interface = 'eth0', @@ -15,7 +15,6 @@ define tinc::vpn_net( # needed in template tinc.conf.erb $fqdn_tinc = regsubst("${fqdn}",'[._-]+','','G') - $connect_to_hosts_tinc = regsubst($connect_to_hosts,'[._-]+','','G') file{"/etc/tinc/${name}": require => Package['tinc'], @@ -37,6 +36,11 @@ define tinc::vpn_net( notify => Service['tinc'], } + $real_hosts_path = $hosts_path ? { + 'absent' => "/etc/tinc/${vpn_net}/hosts.list", + default => $hosts_path + } + @@file { "/etc/tinc/${vpn_net}/hosts/${name_tinc}": ensure => $ensure, notify => Service[tinc], @@ -44,6 +48,13 @@ define tinc::vpn_net( owner => root, group => 0, mode => 0600; } + @@line{"${fqdn_tinc}_for_${name}": + ensure => $ensure, + file => $real_hosts_path, + line => $fqdn_tinc, + tag => 'tinc_hosts_file' + } + if $ensure == 'present' { File["/etc/tinc/${name}"]{ @@ -60,6 +71,10 @@ define tinc::vpn_net( owner => root, group => 0, mode => 0600; } + $tinc_hosts_list = tfile($real_hosts_path) + $tinc_all_hosts = split($tinc_hosts_list,"\n") + $tinc_hosts = array_del($tinc_all_hosts,$fqdn_tinc) + file { "/etc/tinc/${name}/tinc.conf": content => template('tinc/tinc.conf.erb'), notify => Service[tinc], diff --git a/templates/tinc.conf.erb b/templates/tinc.conf.erb index 61e4999..d6c2d6c 100644 --- a/templates/tinc.conf.erb +++ b/templates/tinc.conf.erb @@ -7,6 +7,8 @@ Mode = switch BindToInterface = <%= tinc_interface.to_s %> -<% connect_to_hosts_tinc.to_a.each do |connect_to_host| -%> +<% tinc_hosts.to_a.each do |connect_to_host| -%> +<%- unless connect_to_host.to_s == scope.lookupvar('fqdn') %> ConnectTo = <%= connect_to_host %> +<%- end %> <% end -%>