# create a new backup server system
# NOTE: should be used with --limit most of the time
# NOTE: make sure there is room/space for this instance on the buildvmhost
# NOTE: most of these vars_path come from group_vars/backup_server or from hostvars

- name: make backup server system
  hosts: backup01.phx2.fedoraproject.org
  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
  - denyhosts
  - nagios_client
  - hosts
  - fas_client
  - sudo
  - collectd/base
  - { role: nfs/client,
      mnt_dir: '/fedora_backups',
      nfs_mount_opts: "rw,hard,bg,intr,noatime,nodev,nosuid,nfsvers=3",
      nfs_src_dir: 'fedora_backups' }
  - openvpn/client

  tasks:
  - include: "{{ tasks }}/yumrepos.yml"
  - include: "{{ tasks }}/2fa_client.yml"
  - include: "{{ tasks }}/motd.yml"
  - include: "{{ tasks }}/rdiff_backup_server.yml"

  - name: Create GNOME backup user
    user: name=gnomebackup state=present home=/fedora_backups/gnome/ createhome=yes shell=/sbin/nologin

  - name:  Add a Directory for the Excludes list for each of the backed up GNOME machines
    file: dest=/fedora_backups/gnome/excludes owner=gnomebackup group=gnomebackup state=directory

  - name: Install the GNOME SSH configuration file
    copy: src="{{ files }}/gnome/ssh_config" dest=/usr/local/etc/gnome_ssh_config mode=0600 owner=gnomebackup

  - name: Install GNOME backup key
    copy: src="{{ private }}/files/gnome/backup_id.rsa" dest=/usr/local/etc/gnome_backup_id.rsa mode=0600 owner=gnomebackup

  - name: Install GNOME backup script
    copy: src="{{ files }}/gnome/backup.sh" dest=/usr/local/bin/gnome_backup mode=0700 owner=gnomebackup

  - name: Schedule the GNOME backup script
    cron: name="Backup" hour=5 minute=0 job="(cd /fedora_backups/gnome/; /usr/local/bin/lock-wrapper gnomebackup /usr/local/bin/gnome_backup)" user=gnomebackup

  - name:  Add a Directory for each of the GNOME machines
    file: dest=/fedora_backups/gnome/{{ item }} owner=gnomebackup group=gnomebackup state=directory
    with_items: 
    - signal.gnome.org
    - webapps2.gnome.org
    - clutter.gnome.org
    - blogs.gnome.org
    - view.gnome.org
    - puppet.gnome.org
    - extensions.gnome.org
    - chooser.gnome.org
    - git.gnome.org
    - webapps.gnome.org
    - socket.gnome.org
    - bugzilla-web.gnome.org
    - progress.gnome.org
    - clipboard.gnome.org
    - drawable.gnome.org
    - vbox.gnome.org
    - cloud-ssh.gnome.org
    - bastion.gnome.org
    - spinner.gnome.org
    - master.gnome.org
    - live.gnome.org
    - combobox.gnome.org
    - restaurant.gnome.org
    - expander.gnome.org
    - accelerator.gnome.org
    - range.gnome.org
    - pentagon.gimp.org
    - account.gnome.org
    - bugzilla-new.gnome.org

  handlers:
  - include: "{{ handlers }}/restart_services.yml"
