Now define connect fragment and hostfiles based on arrays
This commit is contained in:
parent
c280a4e706
commit
48df1e447d
4 changed files with 81 additions and 31 deletions
|
@ -5,7 +5,7 @@ define tinc::connect_to(
|
|||
$to,
|
||||
$to_fqdn,
|
||||
$target,
|
||||
){
|
||||
){
|
||||
if $::fqdn != $to_fqdn {
|
||||
concat::fragment{
|
||||
$name:
|
||||
|
|
31
manifests/hostfile.pp
Normal file
31
manifests/hostfile.pp
Normal file
|
@ -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';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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' {
|
||||
|
|
Loading…
Reference in a new issue