- import_playbook: "/srv/web/infra/ansible/playbooks/include/virt-create.yml"
  vars:
    myhosts: "download_ibiblio:download_cc_rdu:download_iad2"

- name: Download servers
  hosts: download
  user: root
  gather_facts: False

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - /srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml

  tasks:

  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"


- name: post-initial-steps
  hosts: download
  user: root
  gather_facts: True

  vars_files:
   - /srv/web/infra/ansible/vars/global.yml
   - "/srv/private/ansible/vars.yml"
   - "/srv/web/infra/ansible/vars/{{ ansible_distribution }}.yml"

  roles:
  - base
  - rkhunter
  - nagios_client
  - hosts
  - { role: openvpn/client, when: vpn == True }
  - ipa/client
  - collectd/base
  - apache
  - download
  - rsyncd
  - { role: nfs/client, when: datacenter == "iad2" or datacenter == "rdu", mnt_dir: '/srv/pub',  nfs_src_dir: 'fedora_ftp/fedora.redhat.com/pub' }
  - { role: nfs/client, when: datacenter == "iad2" or datacenter == "rdu", mnt_dir: '/srv/pub/archive',  nfs_src_dir: 'fedora_ftp_archive' }
  - { role: nfs/client, when: datacenter == "iad2", mnt_dir: '/mnt/fedora_koji',  nfs_src_dir: 'fedora_koji' } # needed for internal sync and odcs
  - { role: nfs/client, when: datacenter == "iad2", mnt_dir: '/mnt/odcs',  nfs_src_dir: 'fedora_odcs' } # needed for internal sync
  - sudo

  pre_tasks:
  - include_vars: dir=/srv/web/infra/ansible/vars/all/ ignore_files=README
  - import_tasks: "{{ tasks_path }}/yumrepos.yml"

  tasks:
  - import_tasks: "{{ tasks_path }}/motd.yml"

  - name: put in script for syncing fedora on download-ib01
    copy: src="{{ files }}/download/sync-up-downloads.sh.ib01" dest=/usr/local/bin/sync-up-downloads owner=root group=root mode=755
    when: inventory_hostname == 'download-ib01.fedoraproject.org'
  - name: put in script for syncing fedora-alt on download-ib01
    copy: src="{{ files }}/download/sync-up-other.sh.ib01" dest=/usr/local/bin/sync-up-other owner=root group=root mode=755
    when: inventory_hostname == 'download-ib01.fedoraproject.org'
  - name: put in script for syncing centos on download-ib01
    copy: src="{{ files }}/download/sync-up-centos.sh.ib01" dest=/usr/local/bin/sync-up-centos owner=root group=root mode=755
    when: inventory_hostname == 'download-ib01.fedoraproject.org'
  - name: put in cron job for syncing
    copy: src="{{ files }}/download/download-sync.cron.ib01"  dest=/etc/cron.d/download-sync owner=root group=root mode=644
    when: inventory_hostname == 'download-ib01.fedoraproject.org'
  - name: put in last sync scrypt for download-ib01
    copy: src="{{ files}}/download/last-sync" dest=/usr/local/bin/last-sync mode=0755
    when: inventory_hostname == 'download-ib01.fedoraproject.org'
  - name: install bc so last-sync works.
    package: name=bc state=present
    when: inventory_hostname == 'download-ib01.fedoraproject.org' 

  - name: put in script for syncing on download-cc-rdu01
    copy: src="{{ files }}/download/sync-up-downloads.sh.cc-rdu01" dest=/usr/local/bin/sync-up-downloads owner=root group=root mode=755
    when: inventory_hostname == 'download-cc-rdu01.fedoraproject.org'
  - name: put in script for syncing centos on download-cc-rdu01
    copy: src="{{ files }}/download/sync-up-centos.sh.cc-rdu01" dest=/usr/local/bin/sync-up-centos owner=root group=root mode=755
    when: inventory_hostname == 'download-cc-rdu01.fedoraproject.org'
  - name: put in cron job for syncing on download-cc-rdu01
    copy: src="{{ files }}/download/download-sync.cron.cc-rdu01"  dest=/etc/cron.d/download-sync owner=root group=root mode=644
    when: inventory_hostname == 'download-cc-rdu01.fedoraproject.org'
  - name: put in last sync scrypt for download-cc-rdu01
    copy: src="{{ files}}/download/last-sync" dest=/usr/local/bin/last-sync mode=0755
    when: inventory_hostname == 'download-cc-rdu01.fedoraproject.org'

  - name: make a mnt/koji link
    file: state=link src=/mnt/fedora_koji/koji dest=/mnt/koji
    when: datacenter == "iad2"
    
  handlers:
  - import_tasks: "{{ handlers_path }}/restart_services.yml"

