From 19ec8f9caa499a70100f5120d1a85d12e758b360 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 12 Jun 2024 11:09:34 -0400 Subject: [PATCH] Generically install multiple defined printers --- printers.sls | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/printers.sls b/printers.sls index 4c940f9..3f8f968 100644 --- a/printers.sls +++ b/printers.sls @@ -1,17 +1,31 @@ -# install the driver inf -"PNPUtil.exe /add-driver \\\\ucs\\software\\drivers\\dell\\c2660dn_PS\\DLPRFAL.inf /install": - cmd.run: - - shell: powershell - - unless: Get-PrinterDriver -Name 'Dell C2660dn Color Laser PS' +# "ClassroomColor": "Dell C2660dn Color Laser PS", +{% set printers = { + "ClassroomColor_HP": "HP LJ300-400 color M351-M451 PCL6 Class Driver", + "Classroom_MFP": "Brother MFC-9970CDW Printer" + } +%} -# add the driver as a printer driver -"Add-PrinterDriver -Name 'Dell C2660dn Color Laser PS'": + +# install all printer driver inf files +"PNPUtil.exe /add-driver \\\\ucs\\software\\drivers\\printers\\*.inf /subdirs /install": cmd.run: - shell: powershell - - unless: Get-PrinterDriver -Name 'Dell C2660dn Color Laser PS' + # TODO: ideally would actually check for success better + - success_retcodes: [1] + +{% for printer, driver in printers.items() %} +# add the driver as a printer driver +"Add-PrinterDriver -Name '{{ driver }}'": + cmd.run: + - shell: powershell + - unless: Get-PrinterDriver -Name '{{ driver }}' # add the printer -"Add-Printer -Name ClassroomColor -PortName 'http://ucs.sawtooth.claremontmakerspace.org:631/printers/ClassroomColor' -DriverName 'Dell C2660dn Color Laser PS'": +"Add-Printer -Name '{{ printer | replace('_', ' ')}}' -PortName 'http://ucs.sawtooth.claremontmakerspace.org:631/printers/{{ printer }}' -DriverName '{{ driver }}'": + cmd.run: + - shell: powershell + - unless: Get-Printer -Name '{{ printer | replace('_', ' ') }}' +{% endfor %} cmd.run: - shell: powershell - unless: Get-Printer -Name ClassroomColor