---
- name: Slurm common Playbook
  hosts: slurm_master:slurm_clients
  vars:
    slurm_src_baseurl: "{{slurm_source_baseurl|default('http://www.schedmd.com/download/archive/')}}"
    slurm_src_filename: "{{slurm_source_filename|default('slurm-14.03.9.tar.bz2')}}"
    slurm_pkg_name: "{{slurm_package_name|default('slurm-14.03.9-1.el6.x86_64.rpm')}}"
  vars_files:
    - vars/os
  tasks:
    - set_fact:
        slurm_name: slurm-llnl
        slurmdbd_name: slurm-llnl-slurmdbd
      when: is_debian_or_ubuntu
      tags: slurm

    - set_fact:
        slurm_name: slurm
        slurmdbd_name: slurmdbd
      when: is_centos
      tags: slurm

    - include: common/tasks/ssh_host_based_authentication.yml hosts={{groups.all}}
    - include: slurm/tasks/main.yml
    - include: common/tasks/iptables.yml trusted_hosts={{groups.all}} default_accept=1

    - include: cluster/tasks/packages.yml
  handlers:
    - include: common/handlers/main.yml
    - include: slurm/handlers/main.yml


- name: Slurm master Playbook
  hosts: slurm_master
  vars:
    slurmdbd_mysql_db: "{{slurm_mysql_db|default('slurm')}}"
    slurmdbd_mysql_user: "{{slurm_mysql_user|default('slurm')}}"
    slurmdbd_mysql_pwd: "{{slurm_mysql_pwd|default('ua7diKee')}}"
  vars_files:
    - vars/os
  tasks: 
    - include: common/tasks/nfs.yml

    - nfsexport: path=/home dest=/etc/exports clients="{{groups.slurm_clients}}" options=rw,no_root_squash,sync state=exported
      notify: 
        - ensure nfs service is running
        - reload exports

      tags:
        - nfs

    - include: slurm/tasks/master.yml
  handlers:
    - include: common/handlers/main.yml
    - include: slurm/handlers/main.yml

- name: Slurm worker nodes Playbook
  hosts: slurm_clients
  vars_files:
    - vars/os
  tasks: 
    - include: common/tasks/nfs-clients.yml nfsserver={{groups.slurm_master[0]}} nfspath=/home nfsmount=/home
  handlers:
    - include: common/handlers/main.yml
    - include: slurm/handlers/main.yml

# Get infos with
# ansible -i hostsfile -m setup hostname