--- - name: Install CUPS and create a print queue hosts: servera.lab.example.com become: true vars: queue_name: "office-printer" device_uri: "ipp://serverc.lab.example.com:631/printers/rht-printer" tasks: - name: the package for creating print queues is installed yum: name: cups state: present - name: the printing service is running and enabled service: name: cups state: started enabled: yes - name: check if print queue already exists command: lpstat -p "{{ queue_name }}" register: cmdout ignore_errors: true changed_when: false - name: the print queue exists command: lpadmin -p "{{ queue_name }}" -v "{{ device_uri }}" -m everywhere -E when: cmdout.rc != 0 - name: check default printer command: lpstat -d register: curr_dest changed_when: false - name: the new print queue is the default queue command: lpadmin -d "{{ queue_name }}" when: curr_dest['stdout'] | regex_replace('^(.*):.') != queue_name