diff --git a/manifests/connect_to.pp b/manifests/connect_to.pp index 7112a4e..4563d5b 100644 --- a/manifests/connect_to.pp +++ b/manifests/connect_to.pp @@ -5,7 +5,7 @@ define tinc::connect_to( $to, $to_fqdn, $target, -){ + ){ if $::fqdn != $to_fqdn { concat::fragment{ $name: diff --git a/manifests/hostfile.pp b/manifests/hostfile.pp new file mode 100644 index 0000000..c7dc8ec --- /dev/null +++ b/manifests/hostfile.pp @@ -0,0 +1,31 @@ +# a hostfile for a certain network +# title must be: +# hostname@network +# +define tinc::hostfile( + $source_dir = undef, + $net = undef, + $ensure = present, +) { + # if absent the net should + # clean it up by itself + if $ensure == 'present' { + include tinc + if $tinc::uses_systemd { + $service_name = "tincd@${net}" + } else { + $service_name = 'tinc' + } + if $net and $source_dir { + file{"/etc/tinc/${net}/hosts/${name}": + source => "${source_dir}/${name}", + # to be sure that we manage that net + require => File["/etc/tinc/${net}/hosts"], + notify => Service[$service_name], + owner => root, + group => 0, + mode => '0600'; + } + } + } +} diff --git a/manifests/instance.pp b/manifests/instance.pp index 6839516..878a02f 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -7,6 +7,9 @@ define tinc::instance( $port = '655', $compression = '10', $mode = 'switch', + $tinc_connect_to = undef, + $tinc_accept_from = undef, + $tinc_hostfiles_dir = 'absent', $tinc_up_content = undef, $tinc_down_content = undef, ){ @@ -112,43 +115,53 @@ define tinc::instance( group => 0, mode => '0600'; } - # export this host and collect all the other hosts - # @@tinc::host{"${fqdn_tinc}@${name}": - # port => $port, - # compression => $compression, - # address => $host_address, - # public_key => $tinc_keys[1], - # tag => "tinc::host_for_${name}", - # } - # Tinc::Host<<| tag == "tinc::host_for_${name}" |>> - tinc::host{"${fqdn_tinc}@${name}": - port => $port, - compression => $compression, - address => $host_address, - public_key => $tinc_keys[1], - tag => "tinc::host_for_${name}", + # if (! $tinc_connect_to) and (!$tinc_accept_from) { + if $::settings::storeconfigs { + notify {"debug_storeconfigs": message => "If storeconfigs is true, then I should change something"} + # export this host and collect all the other hosts + # @@tinc::host{"${fqdn_tinc}@${name}": + # port => $port, + # compression => $compression, + # address => $host_address, + # public_key => $tinc_keys[1], + # tag => "tinc::host_for_${name}", + # } + # Tinc::Host<<| tag == "tinc::host_for_${name}" |>> + + # @@tinc::connect_to{"${name}_connect_to_${fqdn_tinc}": + # to => $fqdn_tinc, + # to_fqdn => $::fqdn, + # target => $tinc_config, + # tag => "tinc_${name}_auto", + # Tinc::Connect_to<<| tag == "tinc_${name}_auto" |>> + } - + else { + tinc::host{"${fqdn_tinc}@${name}": + port => $port, + compression => $compression, + address => $host_address, + public_key => $tinc_keys[1], + } + + $tinc_hosts = union($tinc_accept_from, $tinc_connect_to) + tinc::hostfile {$tinc_hosts: + source_dir => $tinc_hostfiles_dir, + net => $name + } + + $connect_params = $tinc_connect_to.reduce({}) |$memo, $entry| + {merge($memo, {"${fqdn_tinc}_connect_to_${entry}" => {to => $entry, to_fqdn => "", target => $tinc_config}})} + + create_resources(tinc::connect_to, $connect_params) + } + concat::fragment{"tinc_conf_header_${name}": target => $tinc_config, content => template('tinc/tinc.conf-header.erb'), order => '100', } - - # @@tinc::connect_to{"${name}_connect_to_${fqdn_tinc}": - # to => $fqdn_tinc, - # to_fqdn => $::fqdn, - # target => $tinc_config, - # tag => "tinc_${name}_auto", - # Tinc::Connect_to<<| tag == "tinc_${name}_auto" |>> - - tinc::connect_to{"${name}_connect_to_${fqdn_tinc}": - to => $fqdn_tinc, - to_fqdn => $::fqdn, - target => $tinc_config, - tag => "tinc_${name}_auto", - } file { "/etc/tinc/${name}/tinc-up": content => $tinc_up_content, diff --git a/manifests/switch.pp b/manifests/switch.pp index 2f28360..88b024c 100644 --- a/manifests/switch.pp +++ b/manifests/switch.pp @@ -9,6 +9,9 @@ define tinc::switch( $tinc_internal_ip = 'absent', $tinc_internal_netmask = 'absent', $tinc_bridge_interface = 'absent', + $tinc_connect_to = undef, + $tinc_accept_from = undef, + $tinc_hostfiles_dir = 'absent', $compression = '10', $shorewall_zone = 'absent' ){ @@ -21,6 +24,9 @@ define tinc::switch( port => $port, compression => $compression, mode => 'switch', + tinc_connect_to => $tinc_connect_to, + tinc_accept_from => $tinc_accept_from, + tinc_hostfiles_dir => $tinc_hostfiles_dir, } if $ensure == 'present' {