diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d99368 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.idea +*.DS_Store +*vars/* +*templates/* diff --git a/.travis.yml b/.travis.yml index 7863934..588358b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,4 +44,4 @@ script: || (echo 'Status code 200 test: fail' && exit 1) notifications: - webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/README.md b/README.md index d41bc60..b8d0888 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ - xenial - trusty - precise +* Guest machine: Redhat/CentOS + - 7.X ## 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. diff --git a/defaults/main.yml b/defaults/main.yml index d1c39a8..807c941 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -63,9 +63,6 @@ cups_class_list: [] # - "TestPrinter1" # - "TestPrinter2" -cups_packages_to_install: - - cups - - cups-pdf cups_xinetd_location: "/etc/xinetd.d" cups_tmp_location: "/tmp/cups-ansible" cups_admin_grp: lpadmin @@ -76,8 +73,19 @@ cups_etc_files_perms_owner: "root" cups_etc_files_perms_grp: "lp" cups_etc_files_mode: 0644 -cups_expect_pkgs: +apt_cups_pre_install_packages: - "expect" - "python-pexpect" + +apt_cups_packages_to_install: + - cups + - cups-pdf + +yum_cups_pre_install_packages: + +yum_cups_packages_to_install: + - cups + - cups-pdf + cups_ppd_shared_location: "/opt/share/ppd" cups_ricoh_ppd_location: "/opt/OpenPrinting-Ricoh/ppds/Ricoh" \ No newline at end of file diff --git a/tasks/apt_cups_install.yml b/tasks/apt_cups_install.yml new file mode 100644 index 0000000..be1c777 --- /dev/null +++ b/tasks/apt_cups_install.yml @@ -0,0 +1,6 @@ +--- +- name: Install CUPS + apt: name={{ item }} state=latest + with_items: + - "{{ apt_cups_packages_to_install }}" +... \ No newline at end of file diff --git a/tasks/apt_pre_install_packages.yml b/tasks/apt_pre_install_packages.yml new file mode 100644 index 0000000..3245b4b --- /dev/null +++ b/tasks/apt_pre_install_packages.yml @@ -0,0 +1,33 @@ +--- +- 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: apt_cups_expect_pkgs_already_installed + with_items: + - "{{ apt_cups_pre_install_packages }}" + 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: + - "{{ apt_cups_pre_install_packages }}" +... \ No newline at end of file diff --git a/tasks/cups_cleanup.yml b/tasks/cups_cleanup.yml index 58b895e..3e5c1b9 100644 --- a/tasks/cups_cleanup.yml +++ b/tasks/cups_cleanup.yml @@ -10,9 +10,12 @@ # 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 == "") + when: + - ((item.1|failed) or (item.1.stdout == "")) + - (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu') with_together: - - "{{cups_expect_pkgs}}" - - "{{cups_expect_pkgs_already_installed.results}}" - - ignore_errors: True \ No newline at end of file + - "{{apt_cups_expect_pkgs}}" + - "{{apt_cups_expect_pkgs_already_installed.results}}" + + ignore_errors: True +... \ No newline at end of file diff --git a/tasks/cups_configure.yml b/tasks/cups_configure.yml index d3f2cca..b41ce04 100644 --- a/tasks/cups_configure.yml +++ b/tasks/cups_configure.yml @@ -42,4 +42,5 @@ name: "{{item}}" state: started with_items: - - "{{cups_services}}" \ No newline at end of file + - "{{cups_services}}" +... \ No newline at end of file diff --git a/tasks/cups_install.yml b/tasks/cups_install.yml index 676a6ac..f53a023 100644 --- a/tasks/cups_install.yml +++ b/tasks/cups_install.yml @@ -1,8 +1,16 @@ --- -- name: Install CUPS - apt: name={{ item }} state=latest - with_items: - - "{{cups_packages_to_install}}" +- name: Apt Packages Install CUPS + include: apt_cups_install.yml + when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' + +- name: Yum Packages Install CUPS + include: yum_cups_install.yml + when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' + +- name: Adds lpadmin group + group: + name: lpadmin + state: present - name: Add accounts to lpadmin group (CUPS admin) user: @@ -14,4 +22,7 @@ - name: Include - CUPS-LPD include: cups_install_lpd.yml - when: cups_lpd \ No newline at end of file + when: + - (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu') + - cups_lpd +... \ No newline at end of file diff --git a/tasks/cups_install_lpd.yml b/tasks/cups_install_lpd.yml index 0b247fd..a09fe34 100644 --- a/tasks/cups_install_lpd.yml +++ b/tasks/cups_install_lpd.yml @@ -14,4 +14,5 @@ dest: "{{cups_xinetd_location}}/cups-lpd" owner: root group: root - mode: 0755 \ No newline at end of file + mode: 0755 +... \ No newline at end of file diff --git a/tasks/cups_install_ssl_cert.yml b/tasks/cups_install_ssl_cert.yml index 29d676b..b0ea8e3 100644 --- a/tasks/cups_install_ssl_cert.yml +++ b/tasks/cups_install_ssl_cert.yml @@ -15,4 +15,5 @@ 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 index de6e646..7083c38 100644 --- a/tasks/cups_pre_install.yml +++ b/tasks/cups_pre_install.yml @@ -10,35 +10,12 @@ path: "{{cups_ppd_shared_location}}" recurse: yes state: directory + +- name: Apt Packages + include: apt_pre_install_packages.yml + when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' -- 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}}" +- name: Yum Packages + include: yum_pre_install_packages.yml + when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux' +... \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 117b327..88d2277 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -17,4 +17,5 @@ always: - name: Include - CUPS Cleanup - include: cups_cleanup.yml \ No newline at end of file + include: cups_cleanup.yml +... \ No newline at end of file diff --git a/tasks/ppd_hp.yml b/tasks/ppd_hp.yml index 62a030c..21077c6 100644 --- a/tasks/ppd_hp.yml +++ b/tasks/ppd_hp.yml @@ -9,4 +9,5 @@ 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" +... \ No newline at end of file diff --git a/tasks/ppd_install.yml b/tasks/ppd_install.yml index bd87ee4..8829eaa 100644 --- a/tasks/ppd_install.yml +++ b/tasks/ppd_install.yml @@ -2,10 +2,15 @@ - name: Include - Install Ricoh PPDs. include: ppd_ricoh.yml when: cups_ricoh_openprinting_ppds + when: + - (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu') + - cups_ricoh_openprinting_ppds - name: Include - HP PPDs - HPLIP. include: ppd_hp.yml - when: cups_hplip + when: + - (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu') + - cups_hplip - name: Copy PPDs in the ppds_to_be_copied folder copy: @@ -14,4 +19,5 @@ 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("") != "" +... \ No newline at end of file diff --git a/tasks/ppd_ricoh.yml b/tasks/ppd_ricoh.yml index 95e92f1..e21d9e8 100644 --- a/tasks/ppd_ricoh.yml +++ b/tasks/ppd_ricoh.yml @@ -5,4 +5,5 @@ - 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}}" +... \ No newline at end of file diff --git a/tasks/printer_and_class_install.yml b/tasks/printer_and_class_install.yml index 8504080..1c9c28b 100644 --- a/tasks/printer_and_class_install.yml +++ b/tasks/printer_and_class_install.yml @@ -19,7 +19,8 @@ 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)}}" + driver: "{{item.driver|default(omit)}}" + model: "{{item.model|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)}}" @@ -43,4 +44,5 @@ 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}}" +... \ No newline at end of file diff --git a/tasks/yum_cups_install.yml b/tasks/yum_cups_install.yml new file mode 100644 index 0000000..24c732b --- /dev/null +++ b/tasks/yum_cups_install.yml @@ -0,0 +1,6 @@ +--- +- name: Installs CUPS + yum: + name: "{{ query('flattened', '{{ yum_cups_packages_to_install }}') }}" + state: installed +... \ No newline at end of file diff --git a/tasks/yum_pre_install_packages.yml b/tasks/yum_pre_install_packages.yml new file mode 100644 index 0000000..10b3113 --- /dev/null +++ b/tasks/yum_pre_install_packages.yml @@ -0,0 +1,6 @@ +--- +- name: Installs CUPS + yum: + name: "{{ query('flattened', '{{ yum_cups_pre_install_packages }}') }}" + state: installed +... \ No newline at end of file diff --git a/tests/test-simple-playbook.yml b/tests/test-simple-playbook.yml index 14fd0ed..83c062d 100644 --- a/tests/test-simple-playbook.yml +++ b/tests/test-simple-playbook.yml @@ -20,4 +20,5 @@ - "TestPrinter2" roles: - - ansible-cups \ No newline at end of file + - ansible-cups +... \ No newline at end of file