Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redhat/CentOS support, bug fix to tasks/printer_and_class_install.yml #9

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.idea
*.DS_Store
*vars/*
*templates/*
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ script:
|| (echo 'Status code 200 test: fail' && exit 1)

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
webhooks: https://galaxy.ansible.com/api/v1/notifications/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 12 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
6 changes: 6 additions & 0 deletions tasks/apt_cups_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Install CUPS
apt: name={{ item }} state=latest
with_items:
- "{{ apt_cups_packages_to_install }}"
...
33 changes: 33 additions & 0 deletions tasks/apt_pre_install_packages.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
...
13 changes: 8 additions & 5 deletions tasks/cups_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- "{{apt_cups_expect_pkgs}}"
- "{{apt_cups_expect_pkgs_already_installed.results}}"

ignore_errors: True
...
3 changes: 2 additions & 1 deletion tasks/cups_configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@
name: "{{item}}"
state: started
with_items:
- "{{cups_services}}"
- "{{cups_services}}"
...
21 changes: 16 additions & 5 deletions tasks/cups_install.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -14,4 +22,7 @@

- name: Include - CUPS-LPD
include: cups_install_lpd.yml
when: cups_lpd
when:
- (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu')
- cups_lpd
...
3 changes: 2 additions & 1 deletion tasks/cups_install_lpd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
dest: "{{cups_xinetd_location}}/cups-lpd"
owner: root
group: root
mode: 0755
mode: 0755
...
3 changes: 2 additions & 1 deletion tasks/cups_install_ssl_cert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
owner: root
group: root
mode: 0600
remote_src: True
remote_src: True
...
39 changes: 8 additions & 31 deletions tasks/cups_pre_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
...
3 changes: 2 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@

always:
- name: Include - CUPS Cleanup
include: cups_cleanup.yml
include: cups_cleanup.yml
...
3 changes: 2 additions & 1 deletion tasks/ppd_hp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
command: "{{cups_tmp_location}}/hp-plugin-install.exp"
...
10 changes: 8 additions & 2 deletions tasks/ppd_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -14,4 +19,5 @@
owner: root
group: root
mode: 0644
when: cups_ppd_files_to_be_copied|default("") != ""
when: cups_ppd_files_to_be_copied|default("") != ""
...
3 changes: 2 additions & 1 deletion tasks/ppd_ricoh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
- name: Extracting PPDs
shell: find . -name '*.gz' -exec gzip --decompress --quiet {} \;
args:
chdir: "{{cups_ricoh_ppd_location}}"
chdir: "{{cups_ricoh_ppd_location}}"
...
6 changes: 4 additions & 2 deletions tasks/printer_and_class_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)}}"
Expand All @@ -43,4 +44,5 @@
shared: "{{item.shared|default(cups_class_default_is_shared)}}"
class_members: "{{item.members}}"
with_items:
- "{{cups_class_list}}"
- "{{cups_class_list}}"
...
6 changes: 6 additions & 0 deletions tasks/yum_cups_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Installs CUPS
yum:
name: "{{ query('flattened', '{{ yum_cups_packages_to_install }}') }}"
state: installed
...
6 changes: 6 additions & 0 deletions tasks/yum_pre_install_packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Installs CUPS
yum:
name: "{{ query('flattened', '{{ yum_cups_pre_install_packages }}') }}"
state: installed
...
3 changes: 2 additions & 1 deletion tests/test-simple-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
- "TestPrinter2"

roles:
- ansible-cups
- ansible-cups
...