- name: antea
  hosts: antea.fi.muni.cz
  vars:
    postgres_server: false
    nftables:
      pds_local: true
      nfs: true
      snmp: false
    backup_users:
      - name: pontos01
        uid: 502
      - name: pontos02
        uid: 501
      - name: pontos03
        uid: 500
      - name: pontos04
        uid: 995
      - name: antea
        uid: 993
      - name: anna
        uid: 504
      - name: hesperia
        uid: 505

  tasks:
      - fail:
          msg: possibly wrong server?
        when: ansible_distribution != 'Debian'

      - import_role:
          name: common_deb

      - name: "Setup iSCSI"
        block:
          - name: "Instal iSCSI"
            apt:
              pkg:
                - open-iscsi

          - name: "setup iSCSI service"
            copy:
              src: antea/iscsi-thecus.service
              dest: /etc/systemd/system
            register: iscsi_service_file

          - name: "enable & start iSCSI service"
            systemd:
              name: "iscsi-thecus"
              state: '{{"re" if iscsi_service_file.changed else ""}}started'
              enabled: true
              daemon_reload: '{{iscsi_service_file.changed}}'

          - name: "iSCSI: backup-tar in fstab"
            mount:
              path: "/backup-tar"
              src: '/dev/vg.antea.thecus/backup-tar'
              fstype: "xfs"
              opts: "noauto,nofail,_netdev,relatime,attr2,inode64,noquota,x-systemd.automount,x-systemd-requires=iscsi-thecus.service"
              state: "mounted"

      - name: "Backup users & groups"
        block:
          - name: Backup group
            group:
              name: 'backup-remote'
              gid: 502

          - name: Backup users
            user:
              name: 'backup-{{item.name}}'
              uid: '{{item.uid}}'
              home: '/backup-tar/{{item.name}}'
              group: 'backup-remote'
              shell: /bin/bash
            loop: "{{backup_users}}"

          - name: "Aug group for backups"
            group:
              name: 'backup-aux'
              gid: 501

          - name: "Aux users for backups"
            user:
              name: 'checker' # for checker@hesperia
              uid: 1001
              shell: '/usr/sbin/nologin'
              home: '/var/empty'
              group: 'backup-aux'

      - import_role:
          name: pds_mount

#      - import_role:
#          name: ghc_deb

      - import_role:
          name: pds_deb
