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,
|
||||||
$to_fqdn,
|
$to_fqdn,
|
||||||
$target,
|
$target,
|
||||||
){
|
){
|
||||||
if $::fqdn != $to_fqdn {
|
if $::fqdn != $to_fqdn {
|
||||||
concat::fragment{
|
concat::fragment{
|
||||||
$name:
|
$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',
|
$port = '655',
|
||||||
$compression = '10',
|
$compression = '10',
|
||||||
$mode = 'switch',
|
$mode = 'switch',
|
||||||
|
$tinc_connect_to = undef,
|
||||||
|
$tinc_accept_from = undef,
|
||||||
|
$tinc_hostfiles_dir = 'absent',
|
||||||
$tinc_up_content = undef,
|
$tinc_up_content = undef,
|
||||||
$tinc_down_content = undef,
|
$tinc_down_content = undef,
|
||||||
){
|
){
|
||||||
|
@ -112,43 +115,53 @@ define tinc::instance(
|
||||||
group => 0,
|
group => 0,
|
||||||
mode => '0600';
|
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}":
|
# if (! $tinc_connect_to) and (!$tinc_accept_from) {
|
||||||
port => $port,
|
if $::settings::storeconfigs {
|
||||||
compression => $compression,
|
notify {"debug_storeconfigs": message => "If storeconfigs is true, then I should change something"}
|
||||||
address => $host_address,
|
# export this host and collect all the other hosts
|
||||||
public_key => $tinc_keys[1],
|
# @@tinc::host{"${fqdn_tinc}@${name}":
|
||||||
tag => "tinc::host_for_${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}":
|
concat::fragment{"tinc_conf_header_${name}":
|
||||||
target => $tinc_config,
|
target => $tinc_config,
|
||||||
content => template('tinc/tinc.conf-header.erb'),
|
content => template('tinc/tinc.conf-header.erb'),
|
||||||
order => '100',
|
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":
|
file { "/etc/tinc/${name}/tinc-up":
|
||||||
content => $tinc_up_content,
|
content => $tinc_up_content,
|
||||||
|
|
|
@ -9,6 +9,9 @@ define tinc::switch(
|
||||||
$tinc_internal_ip = 'absent',
|
$tinc_internal_ip = 'absent',
|
||||||
$tinc_internal_netmask = 'absent',
|
$tinc_internal_netmask = 'absent',
|
||||||
$tinc_bridge_interface = 'absent',
|
$tinc_bridge_interface = 'absent',
|
||||||
|
$tinc_connect_to = undef,
|
||||||
|
$tinc_accept_from = undef,
|
||||||
|
$tinc_hostfiles_dir = 'absent',
|
||||||
$compression = '10',
|
$compression = '10',
|
||||||
$shorewall_zone = 'absent'
|
$shorewall_zone = 'absent'
|
||||||
){
|
){
|
||||||
|
@ -21,6 +24,9 @@ define tinc::switch(
|
||||||
port => $port,
|
port => $port,
|
||||||
compression => $compression,
|
compression => $compression,
|
||||||
mode => 'switch',
|
mode => 'switch',
|
||||||
|
tinc_connect_to => $tinc_connect_to,
|
||||||
|
tinc_accept_from => $tinc_accept_from,
|
||||||
|
tinc_hostfiles_dir => $tinc_hostfiles_dir,
|
||||||
}
|
}
|
||||||
|
|
||||||
if $ensure == 'present' {
|
if $ensure == 'present' {
|
||||||
|
|
Loading…
Reference in a new issue