# Optional vars
# - checkcompose_server
##      string - hostname of openQA server to connect to (if not set, openQA
##               client configuration will determine this, default will be
##               localhost)
# - checkcompose_url
##      string - base URL for openQA result links (if not set, will be
##               the URL the client actually wound up connecting to)
# - checkcompose_wait
##      string - (digits) time in minutes to wait for openQA tests to complete
##               before sending the report (defaults to 480)
# - checkcompose_emailfrom
##      string - Email address to send report from (if not set, no report sent)
# - checkcompose_emailto
##      string - Email address to send report to (if not set but email-from
##               set, report will go to email-from, for testing usually)
##               Split multiple addresses with spaces
# - checkcompose_atomic_emailto
##      string - Email address to send report for Fedora-Atomic composes to
##               Split multiple addresses with spaces
# - checkcompose_atomic_emailerror
##      string - Set to 'true' if reports for Fedora-Atomic composes should
##               only be mailed out if any tests did not pass
# - checkcompose_smtp
##      string - SMTP server to use for sending the report
# - checkcompose_json
##      string - File to append JSON-formatted report summary to
# - checkcompose_loglevel
##      string - log level
#
# NOTE: this is missing /etc/openqa/client.conf configuration, for now;
# we're assuming it'll be deployed on the openqa server boxes and hence
# client.conf will be in place (and localhost default would be correct
# anyhow). We also get lazy and assume fedora_openqa will be installed
# by openqa/dispatcher role; ideally we should factor this out into a
# shared task or something.

#- name: Install required packages (testing)
#  dnf: name={{ item }} state=present enablerepo="updates-testing"
#  with_items:
#  - python3-fedfind
#  tags:
#  - packages

- name: Install required packages
  dnf:
    name: ['python3-fedfind', 'python3-fedmsg', 'python3-openqa_client',
           'python3-setuptools', 'python3-six']
    state: present
  tags:
  - packages

- name: Check out check-compose
  git:
    repo: https://pagure.io/fedora-qa/check-compose.git
    dest: /root/check-compose
  register: gitcc

- name: Install check-compose
  command: "python3 setup.py install --nodeps"
  args:
    chdir: /root/check-compose
  when: "gitcc is changed"
  notify:
  - restart fedmsg-hub

- name: Enable fedmsg consumer
  template: src=checkcomp_consumer.py.j2 dest=/etc/fedmsg.d/checkcomp_consumer.py owner=root group=root mode=0644
  notify:
  - restart fedmsg-hub
  tags:
  - config

- name: Install config file
  template: src=check-compose.conf.j2 dest=/etc/check-compose.conf mode=0644
  tags:
  - config
