diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57e0931 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vagrant/* +**/*~ +**/*.swp +/meta/.galaxy_install_info diff --git a/README.md b/README.md index d41bc60..bf83046 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ - xenial - trusty - precise +* Guest machine: CentOS + - 7.4 ## Possible additional tasks that are not part of this role's responsibilities. * Opening the necessary CUPS ports - 515(LPR), 631(IPP/IPPS), 9100(direct IP) through the firewall. @@ -51,7 +53,7 @@ * `cups_sysadmins_email`: The email that'll be used to build the cupsd.conf template - Default=`sysadmins@ansible_fqdn` * `cups__debops_ferm_dependent_rules`: Default simple rules to open up ports (515, 631, 9100) through firewall that can be referenced when using [debops.ferm](https://github.com/debops/ansible-ferm) role. * /etc/xinetd.d/cups-lpd - * `cups_lpd_usn`: The username with which it'll run the cups-lpd process (through xinetd) - Default=`cupslpd` + * `cups_lpd_user`: The username with which it'll run the cups-lpd process (through xinetd) - Default=`cupslpd` * Optional templates: * They could've been setup as a simple file copy but accessing and adding ansible variables into it will not be possible. With this ansible\_managed, ansible\_fqdn, etc are accessible. The templates could also be simple text files with no variable declaration and it'll get copied over. * `cups_cupsd_conf_template`: For /etc/cups/cupsd.conf @@ -65,7 +67,8 @@ * `cups_openprinting_apt_required`: This is defined as a ternary. It controls if the OpenPrinting APT key and repo is added based on Ricoh drivers are being installed or not. It can be easily overriden to your value. * `cups_openprinting_apt_key_id`: The APT key id to obtain from keyserver below. Default=24CBF5474CFD1E2F * `cups_openprinting_key_server`: The keyserver to acquire the key from for the below repo - Default=keyserver.ubuntu.com -* `cups_openprinting_repo`: The OpenPrinting Repo to add - Default="deb http://www.openprinting.org/download/printdriver/debian/ lsb3.2 main" +* `cups_openprinting_apt_repo`: The OpenPrinting Repo to add for Debian / Ubuntu - Default="deb http://www.openprinting.org/download/printdriver/debian/ lsb3.2 main" +* `cups_openprinting_yum_repo`: The OpenPrinting Repo to add for RedHat / CentOS - Default="http://www.openprinting.org/download/printdriver/components/lsb3.2/main/RPMS" ### Installation of Printers and classes: @@ -83,12 +86,12 @@ * `cups_packages_to_install`: The CUPS packages to install. This can be overridden for a specific package version if needed - Default=`cups, cups-pdf` * `cups_xinetd_location`: The location of xinet.d files - Default=`/etc/xinetd.d` * `cups_tmp_location`: Temp location that this role uses for copying files and running scripts. Location is created if it doesn't exist - Default=`/tmp/cups-ansible` -* `cups_admin_grp`: The group that has admin access to CUPS. This is referenced when adding users (if defined) to CUPS admin roles - Default=`lpadmin` +* `cups_admin_group`: The group that has admin access to CUPS. This is referenced when adding users (if defined) to CUPS admin roles - Default=`lpadmin` * `cups_services`: The CUPS service(s) that is referenced when starting and stopping CUPS service(s) for configuration purposes - Default=`cups` * `cups_etc_location`: etc location of CUPS config - Default=`/etc/cups` * `cups_etc_files_perms_owner`: Owner of files placed by this role under `cups_etc_location` - Default=`root` -* `cups_etc_files_perms_grp`: Group membership of files placed by this role under `cups_etc_location` - Default=`lp` +* `cups_etc_files_perms_group`: Group membership of files placed by this role under `cups_etc_location` - Default=`lp` * `cups_etc_files_mode`: File mode of files placed by this role under `cups_etc_location` - Default=`0644` -* `cups_expect_pkgs`: The expect related packages that are installed for unattended installations of different expect scripts within this role - Default=`expect, python-pexpect` +* `cups_expect_packages`: The expect related packages that are installed for unattended installations of different expect scripts within this role - Debian-Default=`expect, python-pexpect , RedHat-Default=`expect, pexpect` * `cups_ppd_shared_location`: The standard shared location where PPDs can be placed and CUPS will pick them up - Default=`/opt/share/ppd` -* `cups_ricoh_ppd_location`: The location where Ricoh PPDs from OpenPrinting are installed - Default=`/opt/OpenPrinting-Ricoh/ppds/Ricoh` \ No newline at end of file +* `cups_ricoh_ppd_location`: The location where Ricoh PPDs from OpenPrinting are installed - Default=`/opt/OpenPrinting-Ricoh/ppds/Ricoh` diff --git a/defaults/main.yml b/defaults/main.yml index d1c39a8..c791a48 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,22 +1,28 @@ --- cups_lpadmin_users: - root -cups_lpd: True -cups_lpd_usn: cupslpd +cups_lpd: true +cups_lpd_user: cupslpd -cups_sysadmins_email: "sysadmins@{{ansible_fqdn}}" +cups_sysadmins_email: "sysadmins@{{ ansible_fqdn }}" cups_cupsd_conf_template: "" cups_cups_browsed_conf_template: "" cups_snmp_conf_template: "" -cups_hplip: True -cups_ricoh_openprinting_ppds: True -cups_openprinting_apt_required: "{{cups_ricoh_openprinting_ppds}}" +cups_hplip: false +cups_ricoh_openprinting_ppds: false +cups_openprinting_apt_required: "{{ cups_ricoh_openprinting_ppds }}" +# Debian Keys cups_openprinting_apt_key_id: 24CBF5474CFD1E2F cups_openprinting_key_server: keyserver.ubuntu.com -cups_openprinting_repo: "deb http://www.openprinting.org/download/printdriver/debian/ lsb3.2 main" +# Debian: +cups_openprinting_apt_repo: "deb http://www.openprinting.org/download/printdriver/debian/ lsb3.2 main" +# CentOS et al. +cups_openprinting_yum_repo: "http://www.openprinting.org/download/printdriver/components/lsb3.2/main/RPMS" +# Suse et al. +cups_openprinting_rpm_repo: "http://www.openprinting.org/download/printdriver/components/lsb3.2/main/RPMS" cups_ppd_files_to_be_copied: "" @@ -26,21 +32,21 @@ cups__debops_ferm_dependent_rules: type: 'accept' protocol: 'tcp' dport: ['631', '515', '9100'] - accept_any: True + accept_any: true -cups_purge_all_printers_and_classes: False +cups_purge_all_printers_and_classes: false cups_printer_uri_prefix: "" cups_printer_default_state: "present" -cups_printer_default_report_ipp_supplies: True -cups_printer_default_report_snmp_supplies: True -cups_printer_default_is_shared: True -cups_printer_default_enabled: True +cups_printer_default_report_ipp_supplies: true +cups_printer_default_report_snmp_supplies: true +cups_printer_default_is_shared: true +cups_printer_default_enabled: true cups_printer_default_assign_cups_policy: "default" cups_class_default_state: "present" -cups_class_default_is_shared: True +cups_class_default_is_shared: true cups_printers_and_classes_to_be_removed: [] # - TEST @@ -66,18 +72,19 @@ cups_class_list: [] cups_packages_to_install: - cups - cups-pdf + +cups_xinetd_enabled: false cups_xinetd_location: "/etc/xinetd.d" cups_tmp_location: "/tmp/cups-ansible" -cups_admin_grp: lpadmin +cups_admin_group: lpadmin + cups_services: - cups + cups_etc_location: "/etc/cups" cups_etc_files_perms_owner: "root" -cups_etc_files_perms_grp: "lp" +cups_etc_files_perms_group: "lp" cups_etc_files_mode: 0644 -cups_expect_pkgs: - - "expect" - - "python-pexpect" cups_ppd_shared_location: "/opt/share/ppd" -cups_ricoh_ppd_location: "/opt/OpenPrinting-Ricoh/ppds/Ricoh" \ No newline at end of file +cups_ricoh_ppd_location: "/opt/OpenPrinting-Ricoh/ppds/Ricoh" diff --git a/files/hp-plugin-install.exp b/files/hp-plugin-install.exp index 85bc45e..47fa78c 100644 --- a/files/hp-plugin-install.exp +++ b/files/hp-plugin-install.exp @@ -23,6 +23,8 @@ send -- "hp-plugin -i\r" expect "Do you wish to download and re-install the plug-in? (y=yes*, n=no, q=quit) ?" { send -- "y\r" } expect "Enter option (d=download*, p=specify path, q=quit) ?" { send -- "d\r" } expect "Do you accept the license terms for the plug-in (y=yes*, n=no, q=quit) ?" { send -- "y\r" } +expect "Do you still want to install the plug-in" { send -- "n\r" } +expect "Network connection not detected" { expect eof } # Finally exiting the shell created above. expect ":" { send -- "exit\r" } diff --git a/library/cups_lpadmin.py b/library/cups_lpadmin.py index b73871a..b0388a7 100644 --- a/library/cups_lpadmin.py +++ b/library/cups_lpadmin.py @@ -1,29 +1,28 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -""" -(c) 2015, David Symons (Multimac) -(c) 2016, Konstantin Shalygin -(c) 2016, Hitesh Prabhakar - -This file is part of Ansible - -This module is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This software is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this software. If not, see . -""" - - -# =========================================== +# (c) 2015, David Symons (Multimac) +# (c) 2016, Hitesh Prabhakar +# (c) 2016-2017, Konstantin Shalygin +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see + +ANSIBLE_METADATA = {'status': ['stableinterface'], + 'supported_by': 'community', + 'version': '1.0'} DOCUMENTATION = ''' @@ -44,178 +43,175 @@ - CUPS 1.7+ options: name: - description: - - Name of the printer in CUPS. required: false default: null - purge: description: - - Task to purge all printers in CUPS. Convenient before deploy. + - Name of the printer in CUPS. + purge: required: false default: false choices: ["true", "false"] - state: description: - - Whether the printer should or not be in CUPS. + - Task to purge all printers in CUPS. Convenient before deploy. + state: required: false default: present choices: ["present", "absent"] - printer_or_class: description: - - State whether the object/item we are working on is a printer or class. + - Whether the printer should or not be in CUPS. + printer_or_class: required: false default: printer choices: ["printer", "class"] - driver: description: - - System V interface or PPD file. + - State whether the object/item we are working on is a printer or class. + driver: required: false default: model choices: ["model", "ppd"] - uri: description: - - The URI to use when connecting to the printer. This is only required in the present state. + - System V interface or PPD file. + uri: required: false default: null - enabled: description: - - Whether or not the printer should be enabled and accepting jobs. + - The URI to use when connecting to the printer. This is only required in the present state. + enabled: required: false default: true choices: ["true", "false"] - shared: description: - - Whether or not the printer should be shared on the network. + - Whether or not the printer should be enabled and accepting jobs. + shared: required: false default: false choices: ["true", "false"] - model: description: - - The System V interface or PPD file to be used for the printer. + - Whether or not the printer should be shared on the network. + model: required: false default: null - default: description: - - Set default server printer. Only one printer can be default. + - The System V interface or PPD file to be used for the printer. + default: required: false default: false choices: ["true", "false"] + description: + - Set default server printer. Only one printer can be default. info: + required: false + default: null description: - The textual description of the printer. + location: required: false default: null - location: description: - The textual location of the printer. + assign_cups_policy: required: false default: null - assign_cups_policy: description: - Assign a policy defined in /etc/cups/cupsd.conf to this printer. - required: false - default: null class_members: - description: - - A list of printers to be added to this class. required: false default: [] type: list - report_ipp_supply_levels: description: - - Whether or not the printer must report supply status via IPP. + - A list of printers to be added to this class. + report_ipp_supply_levels: required: false default: true choices: ["true", "false"] - report_snmp_supply_levels: description: - - Whether or not the printer must report supply status via SNMP (RFC 3805). + - Whether or not the printer must report supply status via IPP. + report_snmp_supply_levels: required: false default: true choices: ["true", "false"] + description: + - Whether or not the printer must report supply status via SNMP (RFC 3805). job_kb_limit: + required: false + default: null description: - Limit jobs to this printer (in KB) + job_quota_limit: required: false default: null - job_quota_limit: description: - Sets the accounting period for per-user quotas. The value is an integer number of seconds. + job_page_limit: required: false default: null - job_page_limit: description: - Sets the page limit for per-user quotas. The value is the integer number of pages that can be printed. - Double sided pages are counted as 2. - required: false - default: null options: - description: - - A dictionary of key-value pairs describing printer options and their required value. default: {} required: false + description: + - A dictionary of key-value pairs describing printer options and their required value. ''' -# =========================================== - -EXAMPLES = ''' +EXAMPLES = r''' # Creates HP MFP via ethernet, set default A4 paper size and make this printer - as server default. +# as server default. - cups_lpadmin: - name: 'HP_M1536' - state: 'present' - printer_or_class: 'printer' - uri: 'hp:/net/HP_LaserJet_M1536dnf_MFP?ip=192.168.1.2' - model: 'drv:///hp/hpcups.drv/hp-laserjet_m1539dnf_mfp-pcl3.ppd' - default: 'true' - location: 'Room 404' - info: 'MFP, but duplex broken, as usual on this model' - printer_assign_policy: 'students' - report_ipp_supply_levels: 'true' - report_snmp_supply_levels: 'false' + name: "HP_M1536" + state: "present" + printer_or_class: "printer" + uri: "hp:/net/HP_LaserJet_M1536dnf_MFP?ip=192.168.1.2" + model: "drv:///hp/hpcups.drv/hp-laserjet_m1539dnf_mfp-pcl3.ppd" + default: "true" + location: "Room 404" + info: "MFP, but duplex broken, as usual on this model" + printer_assign_policy: "students" + report_ipp_supply_levels: "true" + report_snmp_supply_levels: "false" options: - media: 'iso_a4_210x297mm' + media: "iso_a4_210x297mm" # Creates HP Printer via IPP (shared USB printer in another CUPS instance). - Very important include 'snmp=false' to prevent adopt 'parent' driver, - because if 'parent' receive not raw job this job have fail (filter failed). +# Very important disable snmp to prevent adopt 'parent' driver, because if +# 'parent' receive not raw job this job have fail (filter failed). - cups_lpadmin: - name: 'HP_P2055' - state: 'present' - uri: 'ipp://192.168.2.127:631/printers/HP_P2055?snmp=false' - model: 'raw' + name: "HP_P2055" + state: "present" + uri: "ipp://192.168.2.127:631/printers/HP_P2055?snmp=false" + model: "raw" options: - media: 'iso_a4_210x297mm' + media: "iso_a4_210x297mm" # Create CUPS Class. - cups_lpadmin: - name: 'StudentClass' - state: 'present' - printer_or_class: 'class' + name: "StudentClass" + state: "present" + printer_or_class: "class" class_members: - CampusPrinter1 - CampusPrinter2 - info: 'Printers for students' - location: 'Room 404' + info: "Printers for students" + location: "Room 404" # Deletes the printers/classes. - cups_lpadmin: - name: 'HP_P2055' - state: 'absent' - printer_or_class: 'printer' + name: "HP_P2055" + state: "absent" + printer_or_class: "printer" - cups_lpadmin: - name: 'StudentClass' - state: 'absent' - printer_or_class: 'class' + name: "StudentClass" + state: "absent" + printer_or_class: "class" # Purge all printers/classes. Useful when does not matter what we have now, client always receive new configuration. -- cups_lpadmin: purge='true' -''' -# =========================================== +- cups_lpadmin: purge='true' +''' RETURN = ''' purge: @@ -267,13 +263,16 @@ description: A concatenated string of all the commands run. returned: always type: string - sample: "\nlpstat -p TEST \nlpinfo -l -m \nlpoptions -p TEST \nlpstat -p TEST \nlpstat -p TEST \nlpadmin -p TEST -o cupsIPPSupplies=true -o cupsSNMPSupplies=true \nlpoptions -p TEST -l " + sample: "lpstat -p TEST + lpinfo -l -m + lpoptions -p TEST + lpstat -p TEST + lpstat -p TEST + lpadmin -p TEST -o cupsIPPSupplies=true -o cupsSNMPSupplies=true + lpoptions -p TEST -l" ''' -# =========================================== - - class CUPSCommand(object): """ This is the main class that directly deals with the lpadmin command. @@ -379,7 +378,10 @@ def check_settings(self): """ msgs = [] - if self.state == 'printer': + if self.purge: + return + + if self.state == 'present': if not self.printer_or_class: msgs.append("When state=present printer or class must be defined.") @@ -537,7 +539,7 @@ def _printer_get_installed_drivers(self): kv = l.split('=', 1) # Strip out any excess whitespace from the key/value - kv = tuple(map(str.strip, kv)) + kv = map(str.strip, kv) curr[kv[0]] = kv[1] @@ -680,7 +682,7 @@ def _printer_install_options(self): """ cmd = ['lpadmin', '-p', self.name] - for k, v in self.options.iteritems(): + for k, v in self.options.items(): cmd.extend(['-o', '{0}={1}'.format(k, v)]) if self.default: @@ -1133,9 +1135,6 @@ def start_process(self): return result -# =========================================== - - def main(): """ main function that populates this Ansible module with variables and sets it in motion. diff --git a/meta/main.yml b/meta/main.yml index eea3690..0dd18ec 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -3,19 +3,28 @@ galaxy_info: author: Hitesh Prabhakar description: Installs CUPS, installs necessary PPDs and installs printers and classes on CUPS license: MIT - min_ansible_version: 2.1 + min_ansible_version: 2.9 platforms: - name: Debian versions: + - buster - stretch - jessie - wheezy - name: Ubuntu versions: + - focal + - bionic - xenial - trusty - - precise - + - name: EL + versions: + - 6 + - 7 + - name: SLES + versions: + - all + galaxy_tags: - cups - printing diff --git a/tasks/cups_cleanup.yml b/tasks/cups_cleanup.yml index 58b895e..7c90dde 100644 --- a/tasks/cups_cleanup.yml +++ b/tasks/cups_cleanup.yml @@ -1,18 +1,19 @@ -- block: - - name: Delete {{ cups_tmp_location }} +--- +- block: + - name: Delete temporary files at {{ cups_tmp_location }} file: - path: "{{cups_tmp_location}}" + path: "{{ cups_tmp_location }}" state: absent - # As grep was used in the initial command whos output is registered as cups_papercut_expect_pkgs_already_installed. - # The results dict will contain the results if the package already existed or not. If there output is none or the - # command failed to find "Install ok installed" then it means the package wasn't installed beforehand and therfore + # dpkg|grep was used in the initial command, and its status output is registered in + # cups_papercut_expect_pkgs_already_installed. The results dict will contain the results if + # the package already existed or not. If there output is none or the command failed to find + # "Install ok installed" then it means the package wasn't installed beforehand and therfore # can be uninstalled after the precessing of this script. - name: Uninstall the expect pacakges if installed before - apt: name={{ item.0 }} state=absent - when: (item.1|failed) or (item.1.stdout == "") - with_together: - - "{{cups_expect_pkgs}}" - - "{{cups_expect_pkgs_already_installed.results}}" - - ignore_errors: True \ No newline at end of file + package: + name: "{{ item }}" + state: absent + when: cups_expect_install.changed + with_items: "{{ cups_expect_packages }}" + ignore_errors: true diff --git a/tasks/cups_configure.yml b/tasks/cups_configure.yml index d3f2cca..a217c01 100644 --- a/tasks/cups_configure.yml +++ b/tasks/cups_configure.yml @@ -1,45 +1,44 @@ --- -- name: Shutdown cups service(s) - service: - name: "{{item}}" - state: stopped - with_items: - - "{{cups_services}}" - -- name: Copying over cupsd.conf using template if defined to {{cups_etc_location}}/cupsd.conf. +- name: Copying over cupsd.conf using template if defined to {{ cups_etc_location }}/cupsd.conf. template: - src: "{{cups_cupsd_conf_template}}" - dest: "{{cups_etc_location}}/cupsd.conf" - owner: "{{cups_etc_files_perms_owner}}" - group: "{{cups_etc_files_perms_grp}}" - mode: "{{cups_etc_files_mode}}" - when: cups_cupsd_conf_template|default("") != "" + src: "{{ cups_cupsd_conf_template }}" + dest: "{{ cups_etc_location }}/cupsd.conf" + owner: "{{ cups_etc_files_perms_owner }}" + group: "{{ cups_etc_files_perms_group }}" + mode: "{{ cups_etc_files_mode }}" + register: restart_required + when: cups_cupsd_conf_template|default("") -- name: Copying over cups-browsed.conf using template if defined to {{cups_etc_location}}/cups-browsed.conf. +- name: Copying over cups-browsed.conf using template if defined to {{ cups_etc_location }}/cups-browsed.conf. template: - src: "{{cups_cups_browsed_conf_template}}" - dest: "{{cups_etc_location}}/cups-browsed.conf" - owner: "{{cups_etc_files_perms_owner}}" - group: "{{cups_etc_files_perms_grp}}" - mode: "{{cups_etc_files_mode}}" - when: cups_cups_browsed_conf_template|default("") != "" + src: "{{ cups_cups_browsed_conf_template }}" + dest: "{{ cups_etc_location }}/cups-browsed.conf" + owner: "{{ cups_etc_files_perms_owner }}" + group: "{{ cups_etc_files_perms_group }}" + mode: "{{ cups_etc_files_mode }}" + register: restart_required + when: cups_cups_browsed_conf_template|default("") -- name: Copying over snmp.conf using template if defined to {{cups_etc_location}}/snmp.conf. +- name: Copying over snmp.conf using template if defined to {{ cups_etc_location }}/snmp.conf. template: - src: "{{cups_snmp_conf_template}}" - dest: "{{cups_etc_location}}/snmp.conf" - owner: "{{cups_etc_files_perms_owner}}" - group: "{{cups_etc_files_perms_grp}}" - mode: "{{cups_etc_files_mode}}" - when: cups_snmp_conf_template|default("") != "" + src: "{{ cups_snmp_conf_template }}" + dest: "{{ cups_etc_location }}/snmp.conf" + owner: "{{ cups_etc_files_perms_owner }}" + group: "{{ cups_etc_files_perms_group }}" + mode: "{{ cups_etc_files_mode }}" + register: restart_required + when: cups_snmp_conf_template|default("") -- name: Include - Copy SSL certificates if necessary variables are defined - cups_source_ssl_private_key_location AND cups_source_ssl_public_key_location. +- name: Include - Copy SSL certificates if necessary variables are defined - cups_source_ssl_{public,private}_key_location include: cups_install_ssl_cert.yml - when: (cups_source_ssl_private_key_location|default("") != "") and (cups_source_ssl_public_key_location|default("") != "") + register: restart_required + when: (cups_source_ssl_private_key_location|default("")) and (cups_source_ssl_public_key_location|default("")) -- name: Start back up cups service(s) - service: - name: "{{item}}" - state: started +- name: restart cups service(s) + service: + name: "{{ item }}" + state: restarted + enabled: yes with_items: - - "{{cups_services}}" \ No newline at end of file + - "{{ cups_services }}" + when: restart_required is defined and restart_required.changed diff --git a/tasks/cups_install.yml b/tasks/cups_install.yml index 676a6ac..a68fa3d 100644 --- a/tasks/cups_install.yml +++ b/tasks/cups_install.yml @@ -1,17 +1,31 @@ --- - name: Install CUPS - apt: name={{ item }} state=latest + package: + name: "{{ cups_packages_to_install }}" + state: present + +- name: Ensure lpadmin group exists + group: + name: "{{ cups_admin_group }}" + state: present + +- name: Ensure lpadmin permissions + lineinfile: + path: "{{ item }}" + regexp: "^SystemGroup" + line: "SystemGroup {{ cups_admin_grp }}" with_items: - - "{{cups_packages_to_install}}" + - "/etc/cups/cupsd.conf" + - "/etc/cups/cups-files.conf" - name: Add accounts to lpadmin group (CUPS admin) user: - name: "{{item}}" + name: "{{ item }}" append: yes - groups: "{{cups_admin_grp}}" - with_items: - - "{{cups_lpadmin_users}}" + groups: "{{ cups_admin_group }}" + with_items: + - "{{ cups_lpadmin_users }}" - name: Include - CUPS-LPD include: cups_install_lpd.yml - when: cups_lpd \ No newline at end of file + when: cups_lpd diff --git a/tasks/cups_install_lpd.yml b/tasks/cups_install_lpd.yml index 0b247fd..b0c1fbe 100644 --- a/tasks/cups_install_lpd.yml +++ b/tasks/cups_install_lpd.yml @@ -1,17 +1,21 @@ --- - name: Install xinetd for cups-lpd - apt: name=xinetd state=latest + block: + - name: Install xinetd for cups-lpd + package: + name: xinetd + state: present -- name: Create cups-lpd user - {{ cups_lpd_usn }} - user: - name: "{{cups_lpd_usn}}" - append: yes - groups: "{{cups_admin_grp}}" + - name: Create cups-lpd user - {{ cups_lpd_user }} + user: + name: "{{ cups_lpd_user }}" + append: yes + groups: "{{ cups_admin_group }}" -- name: Copying over cups-lpd using cups-lpd.j2 template - template: - src: "cups-lpd.j2" - dest: "{{cups_xinetd_location}}/cups-lpd" - owner: root - group: root - mode: 0755 \ No newline at end of file + - name: Copying over cups-lpd using cups-lpd.j2 template + template: + src: "cups-lpd.j2" + dest: "{{ cups_xinetd_location }}/cups-lpd" + owner: root + group: root + mode: 0644 diff --git a/tasks/cups_install_ssl_cert.yml b/tasks/cups_install_ssl_cert.yml index 29d676b..aa2396a 100644 --- a/tasks/cups_install_ssl_cert.yml +++ b/tasks/cups_install_ssl_cert.yml @@ -1,18 +1,18 @@ --- - name: Copying the public key over to final destination copy: - src: "{{cups_source_ssl_public_key_location}}" - dest: "{{cups_etc_location}}/ssl/{{ansible_fqdn}}.crt" + src: "{{ cups_source_ssl_public_key_location }}" + dest: "{{ cups_etc_location }}/ssl/{{ ansible_fqdn }}.crt" owner: root group: root mode: 0600 - remote_src: True + remote_src: true - name: Copying the private key copy: - src: "{{cups_source_ssl_private_key_location}}" - dest: "{{cups_etc_location}}/ssl/{{ansible_fqdn}}.key" + src: "{{ cups_source_ssl_private_key_location }}" + dest: "{{ cups_etc_location }}/ssl/{{ ansible_fqdn }}.key" owner: root group: root mode: 0600 - remote_src: True \ No newline at end of file + remote_src: true \ No newline at end of file diff --git a/tasks/cups_pre_install.yml b/tasks/cups_pre_install.yml deleted file mode 100644 index de6e646..0000000 --- a/tasks/cups_pre_install.yml +++ /dev/null @@ -1,44 +0,0 @@ ---- -- name: Creating CUPS tmp location {{ cups_tmp_location }} - file: - path: "{{cups_tmp_location}}" - recurse: yes - state: directory - -- name: Creating {{ cups_ppd_shared_location }} - file: - path: "{{cups_ppd_shared_location}}" - recurse: yes - state: directory - -- block: - - name: Add OpenPrinting APT Key - apt_key: - id: "{{cups_openprinting_apt_key_id}}" - keyserver: "{{cups_openprinting_key_server}}" - - - name: Add OpenPrinting Package repo - apt_repository: - repo: "{{cups_openprinting_repo}}" - state: present - update_cache: yes - when: cups_openprinting_apt_required is defined and cups_openprinting_apt_required == True - -- name: Update apt cache. - apt: - update_cache: yes - # upgrade: safe - -# If the output is none or the command failed to find "install ok installed" then it means the package wasn't installed beforehand -- name: Check and register if expect related packages are already installed. - command: dpkg -s {{item}} | grep 'install ok installed' - register: cups_expect_pkgs_already_installed - with_items: - - "{{cups_expect_pkgs}}" - changed_when: False - failed_when: False - -- name: Ensure expect related packages are installed to guide us through CUPS installation. - apt: name={{ item }} state=present - with_items: - - "{{cups_expect_pkgs}}" diff --git a/tasks/cups_pre_install_debian.yml b/tasks/cups_pre_install_debian.yml new file mode 100644 index 0000000..894dd00 --- /dev/null +++ b/tasks/cups_pre_install_debian.yml @@ -0,0 +1,31 @@ +--- +- name: Creating CUPS tmp location {{ cups_tmp_location }} + file: + path: "{{ cups_tmp_location }}" + recurse: yes + state: directory + +- name: Creating {{ cups_ppd_shared_location }} + file: + path: "{{ cups_ppd_shared_location }}" + recurse: yes + state: directory + +- block: + - name: Add OpenPrinting APT Key + apt_key: + id: "{{ cups_openprinting_apt_key_id }}" + keyserver: "{{ cups_openprinting_key_server }}" + + - name: Add OpenPrinting Package repo + apt_repository: + repo: "{{ cups_openprinting_repo }}" + state: present + update_cache: yes + when: cups_openprinting_apt_required is defined and cups_openprinting_apt_required + +- name: Ensure expect related packages are installed to guide us through CUPS installation. + package: + name: "{{ cups_expect_pkgs }}" + state: present + register: cups_expect_install diff --git a/tasks/cups_pre_install_rpm.yml b/tasks/cups_pre_install_rpm.yml new file mode 100644 index 0000000..354051d --- /dev/null +++ b/tasks/cups_pre_install_rpm.yml @@ -0,0 +1,34 @@ +--- +- name: Creating CUPS tmp location {{ cups_tmp_location }} + file: + path: "{{ cups_tmp_location }}" + recurse: yes + state: directory + +- name: Creating {{ cups_ppd_shared_location }} + file: + path: "{{ cups_ppd_shared_location }}" + recurse: yes + state: directory + +- block: + - name: install lsb + yum: + name: lsb + state: present + + - name: Add Openprinting Repo + yum_repository: + name: openprinting + description: OpenPrinting LSB-based driver packages + baseurl: "{{ cups_openprinting_rpm_repo }}" + gpgcheck: no + when: cups_openprinting_required is defined and cups_openprinting_required + +- name: Ensure expect related packages are installed to guide us through CUPS installation. + yum: + name: "{{ item }}" + state: present + register: cups_expect_install + with_items: + - "{{ cups_expect_packages }}" diff --git a/tasks/cups_pre_install_suse.yml b/tasks/cups_pre_install_suse.yml new file mode 100644 index 0000000..a5ef385 --- /dev/null +++ b/tasks/cups_pre_install_suse.yml @@ -0,0 +1,34 @@ +--- +- name: Creating CUPS tmp location {{ cups_tmp_location }} + file: + path: "{{ cups_tmp_location }}" + recurse: yes + state: directory + +- name: Creating {{ cups_ppd_shared_location }} + file: + path: "{{ cups_ppd_shared_location }}" + recurse: yes + state: directory + +- block: + - name: install lsb + yum: + name: lsb + state: present + + - name: Add Openprinting Repo + yum_repository: + name: openprinting + description: OpenPrinting LSB-based driver packages + baseurl: "{{ cups_openprinting_yum_repo }}" + gpgcheck: no + when: cups_openprinting_required is defined and cups_openprinting_required + +- name: Ensure expect related packages are installed to guide us through CUPS installation. + yum: + name: "{{ item }}" + state: present + register: cups_expect_install + with_items: + - "{{ cups_expect_packages }}" diff --git a/tasks/main.yml b/tasks/main.yml index 117b327..093ac2f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,7 +1,25 @@ --- + - block: + - name: include Debian / Ubuntu vars + include_vars: debian.yml + when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' + + - name: include Red Hat / CentOS vars + include_vars: redhat.yml + when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' + + - name: include Suse vars + include_vars: suse.yml + when: ansible_distribution == 'SLES' or ansible_distribution == 'openSUSE Leap' + + - name: Include - Pre-Install steps + include: cups_pre_install_debian.yml + when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' + - name: Include - Pre-Install steps - include: cups_pre_install.yml + include: cups_pre_install_rpm.yml + when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' or ansible_distribution == 'SLES' or ansible_distribution == 'openSUSE Leap' - name: Include - Install CUPS include: cups_install.yml @@ -17,4 +35,4 @@ always: - name: Include - CUPS Cleanup - include: cups_cleanup.yml \ No newline at end of file + include: cups_cleanup.yml diff --git a/tasks/ppd_hp.yml b/tasks/ppd_hp.yml index 62a030c..62745d6 100644 --- a/tasks/ppd_hp.yml +++ b/tasks/ppd_hp.yml @@ -1,12 +1,16 @@ --- - name: Install HPLIP - apt: name=hplip state=latest + package: + name: hplip + state: present - name: Copy hp-plugin-install.exp install script to {{ cups_tmp_location }} copy: src: "files/hp-plugin-install.exp" - dest: "{{cups_tmp_location}}/hp-plugin-install.exp" + dest: "{{ cups_tmp_location }}/hp-plugin-install.exp" mode: a+rx -- name: Installing HP Plugin using an except script to avoid user interaction - command: "{{cups_tmp_location}}/hp-plugin-install.exp" \ No newline at end of file +- name: Installing HP Plugin using an Expect script to avoid user interaction + command: "{{ cups_tmp_location }}/hp-plugin-install.exp" + args: + creates: '/usr/share/hplip/prnt/plugins/hbpl1.so' diff --git a/tasks/ppd_install.yml b/tasks/ppd_install.yml index bd87ee4..a43928d 100644 --- a/tasks/ppd_install.yml +++ b/tasks/ppd_install.yml @@ -9,9 +9,9 @@ - name: Copy PPDs in the ppds_to_be_copied folder copy: - src: "{{cups_ppd_files_to_be_copied}}/" - dest: "{{cups_ppd_shared_location}}/" + src: "{{ cups_ppd_files_to_be_copied }}/" + dest: "{{ cups_ppd_shared_location }}/" owner: root group: root mode: 0644 - when: cups_ppd_files_to_be_copied|default("") != "" \ No newline at end of file + when: cups_ppd_files_to_be_copied |default(false) diff --git a/tasks/ppd_ricoh.yml b/tasks/ppd_ricoh.yml index 95e92f1..2956e8b 100644 --- a/tasks/ppd_ricoh.yml +++ b/tasks/ppd_ricoh.yml @@ -1,8 +1,11 @@ --- - name: Install OpenPrinting Ricoh drivers - apt: name=openprinting-ppds-postscript-ricoh state=latest + package: + name: openprinting-ppds-postscript-ricoh + state: present - name: Extracting PPDs shell: find . -name '*.gz' -exec gzip --decompress --quiet {} \; args: - chdir: "{{cups_ricoh_ppd_location}}" \ No newline at end of file + chdir: "{{ cups_ricoh_ppd_location }}" + creates: "{{ cups_ricoh_ppd_location }}/Ricoh-Aficio_CL5000-Postscript-Ricoh-en.ppd" diff --git a/tasks/printer_and_class_install.yml b/tasks/printer_and_class_install.yml index 8504080..27c9044 100644 --- a/tasks/printer_and_class_install.yml +++ b/tasks/printer_and_class_install.yml @@ -1,46 +1,46 @@ --- - name: Removing all printers and classes defined in cups_printers_printers_and_classes_to_be_removed. cups_lpadmin: - name: "{{item}}" + name: "{{ item }}" state: "absent" with_items: - - "{{cups_printers_and_classes_to_be_removed}}" + - "{{ cups_printers_and_classes_to_be_removed }}" - name: Removing all printers and classes on server. cups_lpadmin: - purge: True + purge: true when: cups_purge_all_printers_and_classes - name: Install printers using cups_lpadmin cups_lpadmin: - name: "{{item.name}}" + name: "{{ item.name }}" printer_or_class: "printer" - state: "{{item.state|default(cups_printer_default_state)}}" - enabled: "{{item.enabled|default(cups_printer_default_enabled)}}" - uri: "{{cups_printer_uri_prefix}}{{item.uri}}" - default: "{{item.default_printer|default(omit)}}" - model: "{{item.driver|default(omit)}}" - location: "{{item.location|default(omit)}}" - info: "{{item.info|default(omit)}}" - report_ipp_supply_levels: "{{item.report_ipp_supply_levels|default(cups_printer_default_report_ipp_supplies)}}" - report_snmp_supply_levels: "{{item.report_snmp_supply_levels|default(cups_printer_default_report_snmp_supplies)}}" - shared: "{{item.shared|default(cups_printer_default_is_shared)}}" - assign_cups_policy: "{{item.assign_cups_policy|default(cups_printer_default_assign_cups_policy)}}" - job_kb_limit: "{{item.job_kb_limit|default(omit)}}" - job_quota_limit: "{{item.job_quota_limit|default(omit)}}" - job_page_limit: "{{item.job_page_limit|default(omit)}}" - options: "{{item.options|default(omit)}}" + state: "{{ item.state |default(cups_printer_default_state) }}" + enabled: "{{ item.enabled |default(cups_printer_default_enabled) }}" + uri: "{{ cups_printer_uri_prefix }}{{ item.uri }}" + default: "{{ item.default_printer |default(omit) }}" + model: "{{ item.driver |default(omit) }}" + location: "{{ item.location |default(omit) }}" + info: "{{ item.info |default(omit) }}" + report_ipp_supply_levels: "{{ item.report_ipp_supply_levels |default(cups_printer_default_report_ipp_supplies) }}" + report_snmp_supply_levels: "{{ item.report_snmp_supply_levels |default(cups_printer_default_report_snmp_supplies) }}" + shared: "{{ item.shared |default(cups_printer_default_is_shared) }}" + assign_cups_policy: "{{ item.assign_cups_policy |default(cups_printer_default_assign_cups_policy) }}" + job_kb_limit: "{{ item.job_kb_limit |default(omit) }}" + job_quota_limit: "{{ item.job_quota_limit |default(omit) }}" + job_page_limit: "{{ item.job_page_limit |default(omit) }}" + options: "{{ item.options |default(omit) }}" with_items: - - "{{cups_printer_list}}" + - "{{ cups_printer_list }}" - name: Create printer classes and assign printers to them cups_lpadmin: - name: "{{item.name}}" + name: "{{ item.name }}" printer_or_class: "class" - state: "{{item.state|default(cups_class_default_state)}}" - location: "{{item.location|default(omit)}}" - info: "{{item.info|default(omit)}}" - shared: "{{item.shared|default(cups_class_default_is_shared)}}" - class_members: "{{item.members}}" + state: "{{ item.state |default(cups_class_default_state) }}" + location: "{{ item.location |default(omit) }}" + info: "{{ item.info |default(omit) }}" + shared: "{{ item.shared |default(cups_class_default_is_shared) }}" + class_members: "{{ item.members }}" with_items: - - "{{cups_class_list}}" \ No newline at end of file + - "{{ cups_class_list }}" diff --git a/templates/cups-lpd.j2 b/templates/cups-lpd.j2 index c8540a3..c1dc993 100644 --- a/templates/cups-lpd.j2 +++ b/templates/cups-lpd.j2 @@ -7,8 +7,8 @@ service printer protocol = tcp port = 515 wait = no - user = {{ cups_lpd_usn }} - group = {{ cups_admin_grp }} + user = {{ cups_lpd_user }} + group = {{ cups_admin_group }} server = /usr/lib/cups/daemon/cups-lpd server_args = -o document-format=application/octet-stream disable = no diff --git a/vars/debian.yml b/vars/debian.yml new file mode 100644 index 0000000..8c9ae8c --- /dev/null +++ b/vars/debian.yml @@ -0,0 +1,5 @@ +--- + +cups_expect_packages: + - "expect" + - "python-pexpect" diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..e27482f --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,3 @@ +--- + +cups_expect_pkgs_already_installed: '' \ No newline at end of file diff --git a/vars/redhat.yml b/vars/redhat.yml new file mode 100644 index 0000000..183b975 --- /dev/null +++ b/vars/redhat.yml @@ -0,0 +1,5 @@ +--- + +cups_expect_packages: + - "expect" + - "pexpect" diff --git a/vars/suse.yml b/vars/suse.yml new file mode 100644 index 0000000..f205073 --- /dev/null +++ b/vars/suse.yml @@ -0,0 +1,6 @@ +--- + +cups_expect_packages: + - "expect" + - "python-pexpect" + - "python3-pexpect"