automagically register tinc nodes
Now, tinc nodes automagically organize themself within their network, so you shouldn't have to do anything anymore.
This commit is contained in:
parent
02b3222295
commit
8095174d59
2 changed files with 20 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
define tinc::vpn_net(
|
define tinc::vpn_net(
|
||||||
$ensure = present,
|
$ensure = present,
|
||||||
$connect_to_hosts = [],
|
$hosts_path = 'absent',
|
||||||
$connect_on_boot = true,
|
$connect_on_boot = true,
|
||||||
$key_source_path = 'absent',
|
$key_source_path = 'absent',
|
||||||
$tinc_interface = 'eth0',
|
$tinc_interface = 'eth0',
|
||||||
|
@ -15,7 +15,6 @@ define tinc::vpn_net(
|
||||||
|
|
||||||
# needed in template tinc.conf.erb
|
# needed in template tinc.conf.erb
|
||||||
$fqdn_tinc = regsubst("${fqdn}",'[._-]+','','G')
|
$fqdn_tinc = regsubst("${fqdn}",'[._-]+','','G')
|
||||||
$connect_to_hosts_tinc = regsubst($connect_to_hosts,'[._-]+','','G')
|
|
||||||
|
|
||||||
file{"/etc/tinc/${name}":
|
file{"/etc/tinc/${name}":
|
||||||
require => Package['tinc'],
|
require => Package['tinc'],
|
||||||
|
@ -37,6 +36,11 @@ define tinc::vpn_net(
|
||||||
notify => Service['tinc'],
|
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}":
|
@@file { "/etc/tinc/${vpn_net}/hosts/${name_tinc}":
|
||||||
ensure => $ensure,
|
ensure => $ensure,
|
||||||
notify => Service[tinc],
|
notify => Service[tinc],
|
||||||
|
@ -44,6 +48,13 @@ define tinc::vpn_net(
|
||||||
owner => root, group => 0, mode => 0600;
|
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' {
|
if $ensure == 'present' {
|
||||||
File["/etc/tinc/${name}"]{
|
File["/etc/tinc/${name}"]{
|
||||||
|
@ -60,6 +71,10 @@ define tinc::vpn_net(
|
||||||
owner => root, group => 0, mode => 0600;
|
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":
|
file { "/etc/tinc/${name}/tinc.conf":
|
||||||
content => template('tinc/tinc.conf.erb'),
|
content => template('tinc/tinc.conf.erb'),
|
||||||
notify => Service[tinc],
|
notify => Service[tinc],
|
||||||
|
|
|
@ -7,6 +7,8 @@ Mode = switch
|
||||||
|
|
||||||
BindToInterface = <%= tinc_interface.to_s %>
|
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 %>
|
ConnectTo = <%= connect_to_host %>
|
||||||
|
<%- end %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
Loading…
Reference in a new issue