---
# Configuration for the tahrir webapp

- name: install needed packages
  package:
    name: "{{ item }}"
    state: present
  with_items:
  - python-tahrir
  - python-psycopg2
  - python-memcached
  - python-rdflib
  - libsemanage-python
  - git-core
  tags:
  - packages
  - badges
  - badges/frontend

- name: create tahrir user
  user: 
    user: tahrir
    shell: /sbin/nologin
    home: /usr/share/tahrir
  tags:
  - config
  - badges
  - badges/frontend

- name: copy tahrir app configuration
  template:
    src: "{{ item }}" 
    dest: "/etc/tahrir/{{ item }}"
    owner: tahrir
    group: tahrir
    mode: 0600
  with_items:
  - tahrir.ini
  tags:
  - config
  - badges
  - badges/frontend
  notify:
  - restart apache

- name: copy tahrir wsgi script
  copy:
    src: "{{ item }}"
    dest: "/usr/share/tahrir/{{ item }}"
    owner: apache
    group: apache
    mode: 0644
  with_items:
  - tahrir.wsgi
  tags:
  - config
  - badges
  - badges/frontend
  notify:
  - restart apache

- name: copy tahrir httpd config
  template:
    src: "{{ item }}"
    dest: "/etc/httpd/conf.d/{{ item }}"
    owner: apache
    group: apache
    mode: 0644
  with_items:
  - tahrir.conf
  tags:
  - config
  - badges
  - badges/frontend
  notify:
  - restart apache

- name: make badge rst directory
  file:
    path: /usr/share/badges/sitedocs
    state: directory
    owner: root
    group: root
    mode: 0755
  tags:
  - config
  - assets
  - badges
  - badges/frontend

- name: copy over all our .rst site docs
  copy:
    src: "{{ item }}"
    dest: /usr/share/badges/sitedocs
    owner: root
    group: root
    mode: 0644
  with_fileglob:
  - fedora-sitedocs/*.rst
  tags:
  - config
  - assets
  - badges
  - badges/frontend

- name: create checkout dir
  file:
    name: /srv/badges_checkout
    state: directory
  tags:
  - badges
  - badges/frontend

- name: clone directory
  git:
    repo: https://pagure.io/fedora-badges.git
    dest: /srv/badges_checkout
  tags:
  - badges
  - badges/frontend

- name: add script
  copy:
    dest: /usr/local/bin/update_checkout.sh
    src: update_checkout.sh
    mode: 0755
  tags:
  - badges
  - badges/frontend

- name: add cron for update
  cron:
    name: "update checkout"
    job: /usr/local/bin/update_checkout.sh
    minute: "*/15"
  tags:
  - badges
  - badges/frontend

- name: ensure selinux lets httpd talk to postgres, memcached, and fedmsg
  seboolean:
    name: "{{item}}"
    persistent: yes
    state: yes
  with_items:
  - httpd_can_network_connect_db
  - httpd_can_network_memcache
  - httpd_can_network_connect
  tags:
  - selinux
  - badges
  - badges/frontend
