From 4e22ae97812c8d7c792bb24ef14fbdbb79360a40 Mon Sep 17 00:00:00 2001 From: mh Date: Sun, 11 Jan 2015 14:22:18 +0100 Subject: [PATCH] abstract the tinc host part into its own define --- manifests/host.pp | 36 ++++++++++++++++++++++++++++++++++++ manifests/instance.pp | 16 ++++++++-------- templates/host.erb | 5 ++--- 3 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 manifests/host.pp diff --git a/manifests/host.pp b/manifests/host.pp new file mode 100644 index 0000000..264d19c --- /dev/null +++ b/manifests/host.pp @@ -0,0 +1,36 @@ +# a host for a certain network +# title must be: +# hostname@network +# +define tinc::host( + $public_key, + $ensure = present, + $port = 655, + $compression = 10, +) { + # if absent the net should + # clean it up by itself + if $ensure == 'present' { + validate_re($name,'.+@.+') + $sp_name = split($name,'@') + $fqdn_tinc = $sp_name[0] + $net = $sp_name[1] + + include tinc + if $tinc::uses_systemd { + $service_name = "tincd@${net}" + } else { + $service_name = 'tinc' + } + + file{"/etc/tinc/${net}/hosts/${fqdn_tinc}": + content => template('tinc/host.erb'), + # 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 bd6b38e..d4fce3a 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -112,15 +112,15 @@ define tinc::instance( group => 0, mode => '0600'; } - # export and collect all the keys of this net - @@file { "/etc/tinc/${name}/hosts/${fqdn_tinc}": - content => template('tinc/host.erb'), - tag => "tinc_host_for_${name}", - owner => root, - 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}", } - File<<| tag == "tinc_host_for_${name}" |>> + Tinc::Host<<| tag == "tinc::host_for_${name}" |>> concat::fragment{"tinc_conf_header_${name}": target => $tinc_config, diff --git a/templates/host.erb b/templates/host.erb index 9196355..5530e46 100644 --- a/templates/host.erb +++ b/templates/host.erb @@ -1,6 +1,5 @@ -Address = <%= @host_address %> +Address = <%= @address %> Port = <%= @port %> Compression = <%= @compression %> # 0=no,11=best lzo -# -<%= @tinc_keys[1] %> +<%= @public_key %>