cups: Add $location parameter for cups::printer. Now printer location can be empty, or defined string or fetched from LDAP.

This commit is contained in:
Ossi Herrala 2013-07-12 11:01:00 +00:00
parent cada7e0d69
commit f2cd2d0ad7

View file

@ -101,6 +101,8 @@ class cups::server inherits cups::client {
# Printer name.
# $uri:
# URI to use for connecting to printer device.
# $location:
# Printer location. Use "LDAP" to fetch location information from LDAP.
# $ensure:
# If set to present printer will be installed and if set to absent
# printer will be removed.
@ -112,10 +114,15 @@ class cups::server inherits cups::client {
# uri => "socket://hp1:9100,
# }
#
define cups::printer($uri, $ensure = present) {
define cups::printer($uri, $location = "", $ensure = present) {
$hostname = regsubst($uri, '^[a-z]*://(.*)[:/].*', '\1')
$location = template("cups/printer-location.erb")
if $location == "LDAP" {
$_location = template("cups/printer-location.erb")
} else {
$_location = $location
}
case $ensure {
present: {
@ -128,9 +135,9 @@ define cups::printer($uri, $ensure = present) {
exec { "cups-set-location-${name}":
command => "lpadmin -p ${name} -L '${location}'",
path => "/bin:/sbin:/usr/bin:/usr/sbin",
unless => $location ? {
unless => $_location ? {
"" => "lpoptions -p ${name} | egrep ' printer-location '",
default => "lpoptions -p ${name} | egrep ' printer-location=${location} '",
default => "lpoptions -p ${name} | egrep ' printer-location=${_location} '",
},
require => Exec["cups-add-printer-${name}"],
}