diff --git a/avahi/manifests/init.pp b/avahi/manifests/init.pp index 88566aa..64b7ee6 100644 --- a/avahi/manifests/init.pp +++ b/avahi/manifests/init.pp @@ -26,13 +26,12 @@ class avahi::daemon { # === Parameters # # $name: -# Service name +# Service type. e.g. "_http._tcp". # $description: # Description of service. Defaults to local hostname. # $port: -# Port which service listens on. -# $type: -# Service type for this service. e.g. "_http._tcp". +# Port which service listens on. Defaults to port found from +# /etc/services. # $txt: # Array containing TXT record data. # $ensure: @@ -41,22 +40,21 @@ class avahi::daemon { # # === Sample usage # -# avahi::service { "ssh": +# avahi::service { "_ssh._tcp": # ensure => present, -# port => 22, -# type => "_ssh._tcp", # } # -define avahi::service($type, $port = "AUTO", $description = "%h", $ensure = "present", $txt = []) { +define avahi::service($port = "AUTO", $description = "%h", $ensure = "present", $txt = []) { - $srvtype = $type + $filename = regsubst($name, '^_([^.]+)\._.*', '\1.service') + if $port == "AUTO" { - $realport = avahi_service_port($srvtype) + $realport = avahi_service_port($name) } else { $realport = $port } - file { "/etc/avahi/services/${name}.service": + file { "/etc/avahi/services/${filename}": ensure => $ensure, content => template("avahi/service.erb"), mode => 0644, diff --git a/avahi/templates/service.erb b/avahi/templates/service.erb index 924904c..9173fa2 100644 --- a/avahi/templates/service.erb +++ b/avahi/templates/service.erb @@ -6,8 +6,8 @@ <%= description %> - <%= srvtype %> - <%= port %> + <%= name %> + <%= realport %> <% txt.each do |val| -%> <%= val %> <% end -%>