diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e790e03 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vagrant/* +**/*~ +**/*.swp +**/*.retry diff --git a/README.md b/README.md index d41bc60..a36ae00 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. @@ -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: @@ -89,6 +92,6 @@ * `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_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..904c1bc 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -12,11 +12,13 @@ cups_snmp_conf_template: "" cups_hplip: True cups_ricoh_openprinting_ppds: True -cups_openprinting_apt_required: "{{cups_ricoh_openprinting_ppds}}" +cups_openprinting_required: "{{cups_ricoh_openprinting_ppds}}" 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" +cups_openprinting_apt_repo: "deb http://www.openprinting.org/download/printdriver/debian/ lsb3.2 main" + +cups_openprinting_rpm_repo: "http://www.openprinting.org/download/printdriver/components/lsb3.2/main/RPMS" cups_ppd_files_to_be_copied: "" @@ -76,8 +78,5 @@ cups_etc_files_perms_owner: "root" cups_etc_files_perms_grp: "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/tasks/cups_cleanup.yml b/tasks/cups_cleanup.yml index 58b895e..7c1fb76 100644 --- a/tasks/cups_cleanup.yml +++ b/tasks/cups_cleanup.yml @@ -9,10 +9,10 @@ # 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_install.yml b/tasks/cups_install.yml index 676a6ac..e1ff8e3 100644 --- a/tasks/cups_install.yml +++ b/tasks/cups_install.yml @@ -1,9 +1,25 @@ --- - name: Install CUPS - apt: name={{ item }} state=latest + package: + name: "{{item}}" + state: latest with_items: - "{{cups_packages_to_install}}" +- name: ensure lpadmin group exists + group: + name: "{{cups_admin_grp}}" + state: present + +- name: ensure lpadmin permitions + lineinfile: + path: "{{item}}" + regexp: "^SystemGroup" + line: "SystemGroup {{cups_admin_grp}}" + with_items: + - "/etc/cups/cupsd.conf" + - "/etc/cups/cups-files.conf" + - name: Add accounts to lpadmin group (CUPS admin) user: name: "{{item}}" @@ -14,4 +30,4 @@ - 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..efe5d1e 100644 --- a/tasks/cups_install_lpd.yml +++ b/tasks/cups_install_lpd.yml @@ -1,6 +1,8 @@ --- - name: Install xinetd for cups-lpd - apt: name=xinetd state=latest + package: + name: xinetd + state: latest - name: Create cups-lpd user - {{ cups_lpd_usn }} user: @@ -14,4 +16,4 @@ dest: "{{cups_xinetd_location}}/cups-lpd" owner: root group: root - mode: 0755 \ No newline at end of file + mode: 0755 diff --git a/tasks/cups_pre_install.yml b/tasks/cups_pre_install_debian.yml similarity index 57% rename from tasks/cups_pre_install.yml rename to tasks/cups_pre_install_debian.yml index de6e646..fe3d168 100644 --- a/tasks/cups_pre_install.yml +++ b/tasks/cups_pre_install_debian.yml @@ -19,26 +19,18 @@ - name: Add OpenPrinting Package repo apt_repository: - repo: "{{cups_openprinting_repo}}" + repo: "{{cups_openprinting_apt_repo}}" state: present update_cache: yes - when: cups_openprinting_apt_required is defined and cups_openprinting_apt_required == True + when: cups_openprinting_required is defined and cups_openprinting_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 + register: cups_expect_install with_items: - - "{{cups_expect_pkgs}}" + - "{{cups_expect_packages}}" diff --git a/tasks/cups_pre_install_rpm.yml b/tasks/cups_pre_install_rpm.yml new file mode 100644 index 0000000..1d548ad --- /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 == True + +- 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..482b4a4 --- /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 == True + +- 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..c220519 100644 --- a/tasks/ppd_hp.yml +++ b/tasks/ppd_hp.yml @@ -1,6 +1,8 @@ --- - name: Install HPLIP - apt: name=hplip state=latest + package: + name: hplip + state: latest - name: Copy hp-plugin-install.exp install script to {{ cups_tmp_location }} copy: @@ -9,4 +11,4 @@ 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 + command: "{{cups_tmp_location}}/hp-plugin-install.exp" diff --git a/tasks/ppd_ricoh.yml b/tasks/ppd_ricoh.yml index 95e92f1..f3b838e 100644 --- a/tasks/ppd_ricoh.yml +++ b/tasks/ppd_ricoh.yml @@ -1,8 +1,10 @@ --- - name: Install OpenPrinting Ricoh drivers - apt: name=openprinting-ppds-postscript-ricoh state=latest + package: + name: openprinting-ppds-postscript-ricoh + state: latest - 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}}" 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/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"