Changed printers to set location from LDAP instead manually defining.
This commit is contained in:
parent
3186d04bba
commit
3c73e08f04
2 changed files with 52 additions and 4 deletions
|
@ -82,8 +82,6 @@ class cups::server inherits cups::client {
|
|||
# Printer name.
|
||||
# $uri:
|
||||
# URI to use for connecting to printer device.
|
||||
# $location:
|
||||
# Printer location, defaults to empty.
|
||||
# $ppd:
|
||||
# PPD file to use for printer. If set to "auto" PPD will be copied
|
||||
# from "puppet:///files/cups/${name}.ppd".
|
||||
|
@ -96,10 +94,12 @@ class cups::server inherits cups::client {
|
|||
# cups::printer { "hp1":
|
||||
# ensure => present,
|
||||
# uri => "socket://hp1:9100,
|
||||
# location => "Unknown",
|
||||
# }
|
||||
#
|
||||
define cups::printer($uri, $ensure = present, $location = "", $ppd = "auto") {
|
||||
define cups::printer($uri, $ensure = present, $ppd = "auto") {
|
||||
|
||||
$hostname = regsubst($uri, '^[a-z]*://(.*)[:/].*', '\1')
|
||||
$location = template("cups/printer-location.erb")
|
||||
|
||||
case $ensure {
|
||||
present: {
|
||||
|
|
48
cups/templates/printer-location.erb
Normal file
48
cups/templates/printer-location.erb
Normal file
|
@ -0,0 +1,48 @@
|
|||
<%
|
||||
|
||||
require 'ldap'
|
||||
require 'uri'
|
||||
|
||||
basedn = ''
|
||||
conn = ''
|
||||
|
||||
f = File.new('/etc/openldap/ldap.conf', 'r')
|
||||
f.readlines.each do |line|
|
||||
line = line.strip
|
||||
next if line =~ /^#/
|
||||
next if line == ''
|
||||
line = line.split
|
||||
if line[0] == 'BASE'
|
||||
basedn = line[1]
|
||||
elsif line[0] == 'URI'
|
||||
line.shift
|
||||
line.each do |uri|
|
||||
uri = URI.parse(uri)
|
||||
begin
|
||||
if uri.scheme == 'ldaps'
|
||||
if ! uri.port
|
||||
uri.port = 636
|
||||
end
|
||||
conn = LDAP::SSLConn.new(uri.host, uri.port)
|
||||
else
|
||||
if ! uri.port
|
||||
uri.port = 389
|
||||
end
|
||||
conn = LDAP::Conn.new(uri.host, uri.port)
|
||||
end
|
||||
conn.bind
|
||||
break
|
||||
rescue LDAP::ResultError
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
f.close
|
||||
|
||||
filter = "(&(objectClass=ipHost)(cn=#{hostname})(l=*))"
|
||||
conn.search(basedn, LDAP::LDAP_SCOPE_SUBTREE, filter, ['l']) { |entry|
|
||||
%><%= entry.vals('l')[0] %><%
|
||||
}
|
||||
|
||||
-%>
|
Loading…
Add table
Reference in a new issue