---
# Creates the c3infodesk-cups docker image

###
### LINKS
###
# https://docs.ansible.com/ansible/latest/collections/community/docker/docker_image_module.html

- name: CUPS | Check if the image already exists on the system
  community.docker.docker_image_info:
    name: "{{ c3infodesk_printer_docker_img_cups_name }}"
  register: result_check_image

- name: CUPS | Check image exists answer
  ansible.builtin.debug:
    msg: "Image already exists on target"
  when: result_check_image.images | length > 0

- name: CUPS | Build the docker image
  ansible.builtin.command:
    cmd: docker build . -t "{{ c3infodesk_printer_docker_img_cups_name }}":"{{ c3infodesk_printer_docker_img_cups_tag }}" -f docker/cups/Dockerfile
  args:
    chdir: "{{ c3infodesk_printer_folder }}"
  register: build_img_result
  when: result_check_image.images | length <= 0
  changed_when: build_img_result.rc != 0

- name: CUPS | DEBUG -> Output from creating the docker image
  ansible.builtin.debug:
    msg: "{{ build_img_result }}"
  when:
  - c3infodesk_printer_debug_create_image_cups | bool
  - build_img_result is defined
