aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roles
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-10-23 11:04:59 +0300
committerEgor Tensin <egor@tensin.name>2026-10-23 11:04:59 +0300
commitd22f20bc16fad1879f4ee5a61483c82cfe58fb36 (patch)
tree94a6b9c44ec1c36470aecddc52839add845f3501 /roles
parentimport sudo role from infra-metal (diff)
downloadinfra-ansible-d22f20bc16fad1879f4ee5a61483c82cfe58fb36.tar.gz
infra-ansible-d22f20bc16fad1879f4ee5a61483c82cfe58fb36.zip
import cups role from infra-metal
Diffstat (limited to 'roles')
-rw-r--r--roles/cups/README.md3
-rw-r--r--roles/cups/defaults/main.yml1
-rw-r--r--roles/cups/handlers/main.yml13
-rw-r--r--roles/cups/tasks/main.yml71
-rw-r--r--roles/cups/templates/papersize.j22
5 files changed, 90 insertions, 0 deletions
diff --git a/roles/cups/README.md b/roles/cups/README.md
new file mode 100644
index 0000000..9cde179
--- /dev/null
+++ b/roles/cups/README.md
@@ -0,0 +1,3 @@
+* Install CUPS.
+* Configure Avahi to enable automatic discovery.
+* Configure default paper size.
diff --git a/roles/cups/defaults/main.yml b/roles/cups/defaults/main.yml
new file mode 100644
index 0000000..0e3a3cb
--- /dev/null
+++ b/roles/cups/defaults/main.yml
@@ -0,0 +1 @@
+cups_papersize: A4
diff --git a/roles/cups/handlers/main.yml b/roles/cups/handlers/main.yml
new file mode 100644
index 0000000..ca35bae
--- /dev/null
+++ b/roles/cups/handlers/main.yml
@@ -0,0 +1,13 @@
+# Don't restart if it's not running.
+- name: Collect service facts
+ ansible.builtin.service_facts:
+ listen: cups_restart
+
+- name: Restart CUPS if necessary
+ become: true
+ when: |
+ 'cups.service' in ansible_facts.services and ansible_facts.services['cups.service'].state == 'running'
+ ansible.builtin.systemd_service:
+ name: cups
+ state: restarted
+ listen: cups_restart
diff --git a/roles/cups/tasks/main.yml b/roles/cups/tasks/main.yml
new file mode 100644
index 0000000..f513fe6
--- /dev/null
+++ b/roles/cups/tasks/main.yml
@@ -0,0 +1,71 @@
+# https://wiki.archlinux.org/title/Avahi#Hostname_resolution
+- name: Install nss-mdns
+ become: true
+ ansible.builtin.package:
+ name: nss-mdns
+ state: present
+
+# As of May '26, without this, automatic printer discovery didn't work normally
+# (in some weird way, where the printer would be discovered, but its status
+# won't be queued properly, etc.; who cares, it's obviously an insane tech to
+# begin with), see the link above.
+- name: Fix nsswitch.conf
+ become: true
+ ansible.builtin.lineinfile:
+ path: /etc/nsswitch.conf
+ search_string: 'hosts:'
+ line: 'hosts: mymachines mdns_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] files myhostname dns'
+ state: present
+ owner: root
+ group: root
+ mode: '0644'
+
+- name: Install CUPS & Avahi
+ become: true
+ ansible.builtin.package:
+ name:
+ - cups
+ - cups-pdf
+ - avahi
+ state: present
+
+- name: Enable & start CUPS
+ become: true
+ ansible.builtin.systemd_service:
+ name: cups
+ enabled: true
+ state: started
+
+- name: Enable & start Avahi
+ become: true
+ ansible.builtin.systemd_service:
+ name: avahi-daemon
+ enabled: true
+ state: started
+ notify: cups_restart
+
+- name: Configure default paper size
+ become: true
+ ansible.builtin.template:
+ src: papersize.j2
+ dest: /etc/papersize
+ owner: root
+ group: root
+ mode: '644'
+ notify: cups_restart
+
+- name: Configure logging to journald
+ become: true
+ ansible.builtin.lineinfile:
+ path: /etc/cups/cups-files.conf
+ create: false
+ search_string: '{{ item }}'
+ line: '{{ item }} syslog'
+ notify: cups_restart
+ loop:
+ - AccessLog
+ - ErrorLog
+ - PageLog
+
+- name: Run handlers if neccessary
+ ansible.builtin.meta: flush_handlers
diff --git a/roles/cups/templates/papersize.j2 b/roles/cups/templates/papersize.j2
new file mode 100644
index 0000000..587f8a8
--- /dev/null
+++ b/roles/cups/templates/papersize.j2
@@ -0,0 +1,2 @@
+{{ ansible_managed | comment }}
+{{ cups_papersize }}