Defined Type: avahi::service

Defined in:
manifests/service.pp

Overview

Statically define a service in Avahi.

Examples:

Add static service definitions for SSH and SFTP

include dbus
include avahi

avahi::service { 'ssh':
  description       => '%h',
  replace_wildcards => true,
  services          => [
    {
      'type' => '_ssh._tcp',
      'port' => 22,
    },
  ],
}

avahi::service { 'sftp-ssh':
  description       => '%h',
  replace_wildcards => true,
  services          => [
    {
      'type' => '_sftp-ssh._tcp',
      'port' => 22,
    },
  ],
}

Add a static service definition for NFS on IPv6 only

include dbus
include avahi

avahi::service { 'nfs':
  description       => 'NFS on %h',
  replace_wildcards => true,
  services          => [
    {
      'type'       => '_nfs._tcp',
      'port'       => 2049,
      'protocol'   => 'ipv6',
      'txt-record' => [
        'path=/export/some/path',
      ],
    },
  ],
}

Advertise an AirPrint printer

include dbus
include avahi

avahi::service { 'printer':
  description => 'An AirPrint printer',
  services    => [
    {
      'type'       => '_ipp._tcp',
      'subtype'    => [
        '_universal._sub._ipp._tcp',
      ],
      'port'       => 631,
      'txt-record' => [
        'txtver=1',
        'qtotal=1',
        'rp=printers/aPrinter',
        'ty=aPrinter',
        'adminurl=http://198.0.2.1:631/printers/aPrinter',
        'note=Office Laserjet 4100n',
        'priority=0',
        'product=(GPL Ghostscript)',
        'printer-state=3',
        'printer-type=0x801046',
        'Transparent=T',
        'Binary=T',
        'Fax=F',
        'Color=T',
        'Duplex=T',
        'Staple=F',
        'Copies=T',
        'Collate=F',
        'Punch=F',
        'Bind=F',
        'Sort=F',
        'Scan=F',
        'pdl=application/octet-stream,application/pdf,application/postscript,image/jpeg,image/png,image/urf',
        'URF=W8,SRGB24,CP1,RS600',
      ],
    },
  ],
}

Parameters:

  • description (String)

    The description of the service, any occurence of %h will be replaced with the hostname if $replace_wildcards is set to true.

  • services (Array[Avahi::Record, 1])

    An array of hashes which must contain type and port keys and optionally protocol, subtype, domain-name, host-name and txt-record keys.

  • replace_wildcards (Optional[Boolean]) (defaults to: undef)

    Whether any occurence of %h is replaced with the hosname.

  • service (String) (defaults to: $title)

    The name of the service. It is used to construct the filename, i.e. ${conf_dir}/services/${service}.service.

See Also:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'manifests/service.pp', line 103

define avahi::service (
  String                  $description,
  Array[Avahi::Record, 1] $services,
  Optional[Boolean]       $replace_wildcards = undef,
  String                  $service           = $title,
) {

  include avahi

  $validate_cmd = $avahi::validate ? {
    true    => "${avahi::xmllint} --path ${avahi::dtd_dir} --valid --noout %",
    default => undef,
  }

  file { "${avahi::conf_dir}/services/${service}.service":
    ensure       => file,
    owner        => 0,
    group        => 0,
    mode         => '0644',
    content      => template("${module_name}/service.erb"),
    validate_cmd => $validate_cmd,
  }
}