---
- name: Check input variable
  ansible.builtin.fail:
    msg: |
      la variable zimbraMailDomain est obligatoire pour
      utiliser le role set-logo.
      Veuillez la rajouter dans les host_vars
  when:
    - zimbraMailDomain is not defined

- name: Check param - zmprov gd zimbraPublicServiceHostname
  ansible.builtin.shell: |
    set -e -o pipefail
    /opt/zimbra/bin/zmprov gd {{ zimbraMailDomain }} zimbraPublicServiceHostname | sed -n 2p | awk '{print $2}'
  register: zps_hostname
  changed_when: false
  args:
    executable: /bin/bash

- name: Stop run if zimbraPublicServiceHostname param not set
  ansible.builtin.fail:
    msg: |
      Veuillez d'abord renseigner
      la configuration zimbraPublicServiceHostname
      du domaine {{ zimbraMailDomain }}
  when:
    - zps_hostname.stdout == ""

- name: Check param - zmprov gd zimbraPublicServiceProtocol
  ansible.builtin.shell: |
    set -e -o pipefail
    /opt/zimbra/bin/zmprov gd {{ zimbraMailDomain }} zimbraPublicServiceProtocol | sed -n 2p | awk '{print $2}'
  register: zps_protocol
  changed_when: false
  args:
    executable: /bin/bash

- name: Stop run if zimbraPublicServiceProtocol param not set
  ansible.builtin.fail:
    msg: |
      Veuillez d'abord renseigner
      la configuration zimbraPublicServiceProtocol
      du domaine {{ zimbraMailDomain }}
  when:
    - zps_protocol.stdout == ""

- name: Check param - zmprov gd zimbraPublicServicePort
  ansible.builtin.shell: |
    set -e -o pipefail
    /opt/zimbra/bin/zmprov gd {{ zimbraMailDomain }} zimbraPublicServicePort | sed -n 2p | awk '{print $2}'
  register: zps_port
  changed_when: false
  args:
    executable: /bin/bash

- name: Stop run if zimbraPublicServicePort param not set
  ansible.builtin.fail:
    msg: |
      Veuillez d'abord renseigner
      la configuration zimbraPublicServicePort
      du domaine {{ zimbraMailDomain }}
  when:
    - zps_port.stdout == ""
