- name: install packages
  package: name={{ item }} state=present
  with_items:
  - koschei-admin
  - koschei-backend
  - koschei-backend-fedora
  - koschei-backend-copr
  - postgresql
  - jq
  tags:
  - koschei
  - packages

- name: create systemd config directories
  file: >
    path="/etc/systemd/system/{{ item }}.service.d"
    state=directory
  with_items: "{{ koschei_backend_services }}"
  notify:
  - reload systemd
  tags:
  - koschei
  - config
  - service

- name: install systemd config files (memory)
  copy: >
    src=systemd-memory-limit.conf
    dest=/etc/systemd/system/{{ item }}.service.d/memory-limit.conf
  with_items:
  - koschei-build-resolver
  - koschei-repo-resolver
  notify:
  - reload systemd
  - restart koschei-build-resolver
  - restart koschei-repo-resolver
  tags:
  - koschei
  - config
  - service

- name: install systemd config files (restart)
  template: >
    src=systemd-restart-limit.conf.j2
    dest=/etc/systemd/system/{{ item }}.service.d/restart.conf
  with_items: "{{ koschei_backend_services }}"
  notify:
  - reload systemd
  tags:
  - koschei
  - config
  - service

- name: install systemd config files (environment)
  template: >
    src=systemd-environment.conf.j2
    dest=/etc/systemd/system/{{ item }}.service.d/environment.conf
  with_items: "{{ koschei_backend_services }}"
  notify:
  - reload systemd
  - restart koschei backend services
  tags:
  - koschei
  - config
  - service

- name: install config files
  template: >
    src="{{ item }}.j2"
    dest="/etc/koschei/{{ item }}"
    owner=koschei
    group=koschei
    mode=0400
  with_items:
  - config-admin.cfg
  - config-backend.cfg
  - copr-config
  notify:
  - restart koschei backend services
  tags:
  - koschei
  - config

- name: install koschei fedmsg config
  copy: src=koschei.py dest=/etc/fedmsg.d/koschei.py
  notify:
  - restart koschei backend services
  tags:
  - koschei
  - config
  - fedmsgdconfig

- name: install koji client config file
  template: >
    src="koji.conf.j2"
    dest="/etc/koji.conf"
  tags:
  - koschei
  - config

- name: enable services to start on boot
  service: name={{ item }} state=started enabled=true
  with_items: "{{ koschei_backend_services }}"
  tags:
  - koschei
  - service

- name: Copy the cleanup cronjob
  template: src=cron-db-cleanup.j2 dest=/etc/cron.d/cron-db-cleanup
  tags:
  - koschei
  - config

- name: Copy refresh-group script
  copy: >
    src={{ item }}
    dest=/usr/local/bin/{{ item }}
    mode=755
  with_items:
  - koschei-refresh-group
  - koschei-refresh-distgit-group
  - koschei-refresh-module
  - koschei-track-group
  tags:
  - koschei
  - config

- name: Copy the group refresh cronjob
  template: src=cron-refresh-groups.j2 dest=/etc/cron.d/cron-refresh-groups
  tags:
  - koschei
  - config

- name: access to postgres for scripts
  template: src=pgpass.j2 dest=/var/cache/koschei/.pgpass
            owner=koschei group=koschei mode=0600
  tags:
  - koschei
  - config
