cups_server: Configure printers from LDAP
No modify supported just add and delete.
This commit is contained in:
parent
34624667dc
commit
a729049060
1 changed files with 80 additions and 0 deletions
|
@ -162,3 +162,83 @@
|
|||
mode: "0644"
|
||||
owner: root
|
||||
group: "{{ ansible_wheel }}"
|
||||
|
||||
- name: Get printers from LDAP
|
||||
community.general.ldap_search:
|
||||
attrs:
|
||||
- cn
|
||||
- description
|
||||
- l
|
||||
client_cert: >-
|
||||
{{ hostvars[ansible_server]['tls_certs'] + '/' + ansible_server }}.crt
|
||||
client_key: >-
|
||||
{{ hostvars[ansible_server]['tls_private'] + '/' + ansible_server }}.key
|
||||
dn: "{{ ldap_basedn }}"
|
||||
filter: "(&(objectClass=device)(cn=*.print.foo.sh))"
|
||||
scope: subordinate
|
||||
server_uri: "ldaps://{{ ldap_server[0] }}"
|
||||
delegate_to: localhost
|
||||
register: printers
|
||||
|
||||
- name: Get printers list
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- lpstat
|
||||
- -e
|
||||
changed_when: false
|
||||
register: result
|
||||
|
||||
- name: Add printers
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- lpadmin
|
||||
- -D
|
||||
- "{{ item.description }}"
|
||||
- -i
|
||||
- >-
|
||||
{{
|
||||
'/usr/local/share/cups-ppd/' +
|
||||
item.description | regex_replace(' ', '_') +
|
||||
'.ppd'
|
||||
}}
|
||||
- -L
|
||||
- "{{ item.l }}"
|
||||
- -o
|
||||
- media=a4
|
||||
- -o
|
||||
- cupsSNMPSupplies=true
|
||||
- -o
|
||||
- printer-error-policy=abort-job
|
||||
- -o
|
||||
- printer-is-shared=true
|
||||
- -v
|
||||
- "http://{{ item.cn }}:631"
|
||||
- -p
|
||||
- "{{ item.cn | split('.') | first }}"
|
||||
- -E
|
||||
with_items: >-
|
||||
{{
|
||||
printers.results | rejectattr(
|
||||
'cn',
|
||||
'in',
|
||||
result.stdout_lines | map('regex_replace', '$', '.print.foo.sh'
|
||||
) | list) | list
|
||||
}}
|
||||
|
||||
- name: Remove printers
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- lpadmin
|
||||
- -x
|
||||
- "{{ item }}"
|
||||
with_items: >-
|
||||
{{
|
||||
result.stdout_lines | reject(
|
||||
'in',
|
||||
printers.results | map(attribute='cn') | map(
|
||||
'regex_replace',
|
||||
'.print.foo.sh$',
|
||||
''
|
||||
) | list
|
||||
) | list
|
||||
}}
|
||||
|
|
Loading…
Add table
Reference in a new issue