-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathprinter.yml
113 lines (100 loc) · 4.46 KB
/
printer.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
- hosts: computers
gather_facts: no
# vars:
# old_names:
# - Canon Printer
# - Canon iR-ADV C7055/C7065 Class Driver
# - Canon
# - iR-ADV C7260
# - iR-ADV C7260 (Crombeen)
# new_name: iR-ADV C7260 (Crombeen)
tasks:
- name: Remove printer iR-ADV C7260
win_shell: |
$printers = Get-Printer | Where-Object {$_.Name -like "*C7260*"}
ForEach ($printer in $printers) {
Remove-Printer -Name $printer.Name
}
$printerdriver = Get-PrinterDriver | Where-Object {$_.Name -like "*iR-ADV*"}
ForEach ($printerdriver in $printerdrivers) {
Remove-PrinterDriver -Name $printerdriver.Name
}
$printerport = Get-PrinterPort | Where-Object {$_.Name -like "*192.168.0.40*"}
ForEach ($printerport in $printerports) {
Remove-PrinterPort -Name $printerrt.Name
}
If ($printers -or $printerdrivers -or $printerports) {
Write-Host "changed"
}
register: canon_c7260
failed_when: no
changed_when: canon_c7260.stdout.find("changed") != -1
- name: Remove printer driver
win_shell: |
$drivers = (Get-WindowsDriver -online | Where-Object {$_.OriginalFileName -like "*cnp60ha64.inf"}).Driver
ForEach ($driver in $drivers) {
PNPUtil.exe /delete-driver $driver
}
register: removal
failed_when: no
changed_when: removal.stdout.find("Driver package deleted successfully.") != -1
# - name: Install printer driver
# win_shell: |
# Set-Location -Path "\\diskstation01.crombeen.internal\ictadmin\Hardware\Printer\Canon iR ADVANCE\PCL6_Driver_V2185_32_64_NL_07\x64\Driver"
# PNPUtil.exe /add-driver CNP60HA64.INF /install
# register: driver
# changed_when: "'Added driver packages: 1' in driver.stdout"
# failed_when: "'Driver package added successfully.' not in driver.stdout"
- name: Install printer driver
win_shell: |
Set-Location -LiteralPath "\\diskstation01.crombeen.internal\ictadmin\Hardware\Printer\Canon iR ADVANCE\GPlus_PCL6_Driver_V200_32_64_00\x64\Driver"
PNPUtil.exe /add-driver CNP60MA64.INF /install
register: driver
changed_when: 'driver.stdout.find("Added driver packages: 1") != -1'
failed_when: driver.stdout.find("Driver package added successfully.") == -1
# - name: Create printer iR-ADV C7260
# win_shell: |
# Add-PrinterPort -Name "IP_192.168.0.40" -PrinterHostAddress "printer01.crombeen.internal" -PortNumber 9100 -ErrorAction SilentlyContinue
# Add-PrinterDriver -Name "Canon iR-ADV C7260/7270 PCL6" -ErrorAction SilentlyContinue
# Add-Printer -Name "iR-ADV C7260 (Crombeen)" -DriverName "Canon iR-ADV C7260/7270 PCL6" -Port "IP_192.168.0.40" -ErrorAction SilentlyContinue
# register: canon_c7260
# failed_when: no
# changed_when: canon_c7260.rc == 0
- name: Create printer iR-ADV 6555
win_shell: |
Add-PrinterPort -Name "IP_192.168.0.225" -PrinterHostAddress "canon_6555.crombeen.internal" -PortNumber 9100
Add-PrinterDriver -Name "Canon Generic Plus PCL6"
Add-Printer -Name "iR-ADV 6555 III (Zwart-Wit Crombeen)" -DriverName "Canon Generic Plus PCL6" -Port "IP_192.168.0.225"
register: canon_6555
failed_when: no
changed_when: canon_6555.rc == 0
# - name: Create printer iR-ADV C3530
# win_shell: |
# Add-PrinterPort -Name "IP_192.168.0.226" -PrinterHostAddress "canon_c3530.crombeen.internal" -PortNumber 9100
# Add-PrinterDriver -Name "Canon Generic Plus PCL6"
# Add-Printer -Name "iR-ADV C3530 (Kleur Crombeen)" -DriverName "Canon Generic Plus PCL6" -Port "IP_192.168.0.226"
# register: canon_c3530
# failed_when: no
# changed_when: canon_c3530.rc == 0
- name: Set default printer
win_shell: |
$wshNet = New-Object -ComObject WScript.Network
$wshNet.SetDefaultPrinter("iR-ADV 6555 III (Zwart-Wit Crombeen)")
tags: default
- name: Do not let Windows manage your default printer
win_regedit:
path: HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows
name: LegacyDefaultPrinterMode
data: 1
type: dword
tags: registry
# - name: Rename printer
# win_shell: |
# ( Get-Printer -Name "{{ item }}" ) -and ( Rename-Printer -Name "{{ item }}" -NewName "{{ new_name }}" )
# with_items: '{{ old_names }}'
# - name: Default to black-white printing ({{ user }}) for {{ new_name }}
# win_shell: |
# Set-PrintConfiguration -PrinterName "{{ new_name }}" -Color $false -Confirm:$false
# ignore_errors: yes
# become: yes
# become_user: '{{ user }}'