- name: remove some old copr repos for things now in the infra repo.
  file: dest="/etc/yum.repos.d/{{item}}" state=absent
  with_items:
    - patternfly-patternfly1-epel-7.repo
    - ralph-pdc-deps-epel-7.repo
    - sochotni-pdc-test-epel-7.repo
  tags: pdc

- name: install needed packages
  package: pkg={{ item }} state=present
  with_items:
  - patternfly1
  - python-pdc
  - xmlsec1
  - mod_auth_mellon
  tags: pdc

- name: Copy over settings_local.py
  template: src=settings_local.py
            dest=/usr/lib/python2.7/site-packages/pdc/settings_local.py
            mode=0600 owner=apache group=apache
  notify: reload httpd
  tags: pdc

- name: Create directory structure for exportbranches command
  file: dest={{item.dest}} state={{item.state}} owner=apache group=apache
  with_items:
  - dest: /usr/lib/python2.7/site-packages/pdc/apps/componentbranch/management
    state: directory
  - dest: /usr/lib/python2.7/site-packages/pdc/apps/componentbranch/management/commands/
    state: directory
  tags:
    - pdc
    - cron

- name: Create files for exportbranches command if they do not already exist
  copy: dest={{item.dest}} owner=apache group=apache content='' force=no
  with_items:
  - dest: /usr/lib/python2.7/site-packages/pdc/apps/componentbranch/management/__init__.py
  - dest: /usr/lib/python2.7/site-packages/pdc/apps/componentbranch/management/commands/__init__.py
  tags:
    - pdc
    - cron

- name: Copy over the exportbranches command
  copy:
    dest: /usr/lib/python2.7/site-packages/pdc/apps/componentbranch/management/commands/exportbranches.py
    src: exportbranches.py
  tags:
    - pdc
    - cron

- name: create directory for the active_branches cache
  file: path=/var/www/html/extras/ state=directory owner=apache group=apache
  tags:
  - pdc
  - cron

- name: cron to generate cache of active component branches for pagure-sync-bugzilla
  cron: name="export-branches" minute="15" user="apache"
      job="/usr/local/bin/lock-wrapper export-branches 'python /usr/lib/python2.7/site-packages/pdc/manage.py exportbranches > /var/www/html/extras/active_branches.json.tmp && mv /var/www/html/extras/active_branches.json.tmp /var/www/html/extras/active_branches.json'"
      cron_file=export-branches
  tags:
  - pdc
  - cron

- name: Copy over httpd config
  template: src=pdc.conf dest=/etc/httpd/conf.d/pdc.conf
  notify: reload httpd
  tags: pdc

- name: ensure selinux lets httpd do the stuff we need.
  seboolean: name={{ item }} persistent=yes state=yes
  with_items:
  - httpd_can_network_connect_db
  - httpd_can_sendmail
  # XXX - Someday for fedmsg
  #- httpd_can_network_connect
  tags:
  - pdc
  - selinux

- name: create /etc/httpd/saml2
  file: state=directory
        path=/etc/httpd/saml2
        owner=apache group=apache mode=0775
  tags: pdc

- name: Install saml2 idp file (which describes our ipsilon instances).
  copy: src="{{ private }}/files/saml2/idp-{{env}}.xml"
        dest="/etc/httpd/saml2/idp-metadata.xml"
        owner="apache" group="apache" mode=0600
  notify: reload httpd
  tags: pdc

- name: Copy over the metadata.xml rebuild script
  copy:
    src: create-metadata.sh
    dest: /etc/httpd/saml2/create-metadata.sh
    mode: 0755
  notify:
    - rebuild metadata
    - reload httpd
  tags: pdc

- name: Install domain-specific saml2 certs
  copy: src="{{ private }}/files/saml2/{{ pdc_domain }}/{{ item }}"
        dest="/etc/httpd/saml2/{{ item }}"
        owner="apache" group="apache" mode=0600
  with_items:
    - certificate.pem
    - certificate.key
  notify:
    - rebuild metadata
    - reload httpd
  tags: pdc
