---
- hosts: ethz-nfs
  vars:
    nfsserver: 10.0.255.254
    nfspath: /nfs/matlab/MATLAB
    nfsmount: /usr/local/MATLAB
  vars_files:
    - vars/os
  tasks:
    - action: file path=/usr/local/MATLAB state=directory
    - include: common/tasks/nfs-clients.yml
  handlers:
    - include: common/handlers/main.yml


- hosts: mdce_worker:mdce_master
  vars:
    nfsmount: /usr/local/MATLAB
    mbin: "{{nfsmount}}/R2013a/toolbox/distcomp/bin/"
  tasks:
    - include: common/tasks/deb.yml
    - name: install missing X11 packages
      action: apt pkg={{item}} state=installed
      with_items:
        - libxt6
        - libxmu6
    - name: start MDCE daemon
      action: shell {{mbin}}/mdce status | grep PID || (nohup {{mbin}}/mdce start; sleep 10)
      ignore_errors: true

    - include: common/tasks/iptables.yml trusted_hosts={{groups.all}}
  handlers:
    - include: common/handlers/main.yml

- hosts: mdce_master
  vars:
    nfsmount: /usr/local/MATLAB
    mbin: "{{nfsmount}}/R2013a/toolbox/distcomp/bin/"
  tasks:
    - action: shell nohup {{mbin}}/startjobmanager -name AnsibleMatlabCluster
      ignore_errors: true


- hosts: mdce_worker
  vars:
    nfsmount: /usr/local/MATLAB
    mbin: "{{nfsmount}}/R2013a/toolbox/distcomp/bin/"
  tasks:
    # I don't know if it's necessary to run a worker per core or just one per machine
    # - action: shell for i in `seq 1 $(nproc)`; do nohup $mbin/startworker -jobmanager AnsibleMatlabCluster -jobmanagerhost ${groups.mdce_master[0]} ; done; echo "done"
    #   ignore_errors: true
    - action: shell nohup $mbin/startworker -jobmanager AnsibleMatlabCluster -jobmanagerhost ${groups.mdce_master[0]}
      ignore_errors: true
