- name: Setup cups
  tags: cups
  become: true
  block:
    - name: Install cups
      ansible.builtin.apt:
        name: cups
        state: present

    - name: Copy cupsd.conf
      ansible.builtin.template:
        src: templates/cupsd.conf.j2
        dest: /etc/cups/cupsd.conf
        group: lp
        mode: "0644"
      notify: restart cups.service

    - name: Setup printers
      block:

        - name: Stop cups
          ansible.builtin.service:
            name: cups
            state: stopped

        - name: Copy printers.conf
          ansible.builtin.template:
            src: templates/printers.conf.j2
            dest: /etc/cups/printers.conf
            group: lp
            mode: "0600"
          notify: restart cups.service
