printer-create.yml 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. ---
  2. - name: Install CUPS and create a print queue
  3. hosts: servera.lab.example.com
  4. become: true
  5. vars:
  6. queue_name: "office-printer"
  7. device_uri: "ipp://serverc.lab.example.com:631/printers/rht-printer"
  8. tasks:
  9. - name: the package for creating print queues is installed
  10. yum:
  11. name: cups
  12. state: present
  13. - name: the printing service is running and enabled
  14. service:
  15. name: cups
  16. state: started
  17. enabled: yes
  18. - name: check if print queue already exists
  19. command: lpstat -p "{{ queue_name }}"
  20. register: cmdout
  21. ignore_errors: true
  22. changed_when: false
  23. - name: the print queue exists
  24. command: lpadmin -p "{{ queue_name }}" -v "{{ device_uri }}"
  25. -m everywhere -E
  26. when: cmdout.rc != 0
  27. - name: check default printer
  28. command: lpstat -d
  29. register: curr_dest
  30. changed_when: false
  31. - name: the new print queue is the default queue
  32. command: lpadmin -d "{{ queue_name }}"
  33. when: curr_dest['stdout'] | regex_replace('^(.*):.') != queue_name