---
- name: install copr-frontend packages
  package: name={{ item }} state=present
  with_items:
  - copr-frontend
  # workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1622513
  - python3-requests
  tags:
  - copr
  - packages

- name: install copr configs
  template: src=copr.conf dest=/etc/copr/copr.conf mode=600
  notify:
  - reload httpd
  tags:
  - copr
  - config

- name: copy apache files to conf.d (templates)
  template: src=httpd.conf dest=/etc/httpd/conf.d/coprs.conf
  notify:
  - reload httpd
  tags:
  - copr
  - config

- name: set staging banner for staging instance
  when: env == 'staging'
  copy: src=banner-include.html dest=/var/lib/copr/
  tags:
  - copr
  - config

# https://bugzilla.redhat.com/show_bug.cgi?id=1535689
- name: Allow execmem for Apache
  seboolean:
    name: httpd_execmem
    state: yes
    persistent: yes
  tags:
  - copr
  - selinux

- name: enable and start httpd
  service: name=httpd state=started enabled=yes
  tags:
  - copr
  - service

  # FIXME mizdebsk 2018-09-07: copr-frontend package available in
  # f28-updates and f28-infra is too old and it doesn't have
  # pagure-events.service service - a newer copr-frontend version
  # should be added to one of these tags.
- name: enable and start pagure-events
  service: name=pagure-events enabled=yes state=started
  when: not 'pagure-events.service is missing in latest copr-frontend rpm in f28 repos'
  tags:
  - copr
  - service

  # FIXME mizdebsk 2018-09-07: This task is currently disabled because
  # admin status should be treated as application data and does not
  # need to be Ansible-managed.  If it really needs to stay in Ansible
  # then 1) the task shoud be fixed not to report changes and 2) it
  # should allow setting different admins for staging and production.
- name: set up admins
  command: ./manage.py alter_user --admin {{ item }}
  become: yes
  become_user: copr-fe
  args:
    chdir: /usr/share/copr/coprs_frontend/
  when: not 'admin status is application data, not config'
  with_items:
  - msuchy
  - sgallagh
  - spot
  - nb
  - kevin

  # FIXME mizdebsk 2018-09-07: This task is currently disabled because
  # it is not idempotent - index rebuilding should probably be part of
  # upgrade playbook, not deployment playbook.
- name: rebuild indexes
  command: ./manage.py update_indexes
  become: yes
  become_user: copr-fe
  args:
    chdir: /usr/share/copr/coprs_frontend/
  when: not 'index rebuilding is not idempotent'
