- name: remove all install
  shell: rm -rf /tmp/slurm-{{ slurm_version }}
  sudo: true 
  when: force_slurm_recompile is defined

- name: remove all install
  shell: rm -rf {{ slurm_dir }}
  sudo: true 
  when: force_slurm_recompile is defined

- name: unarchive slurm
  unarchive:
    src: "http://consistency0/src/slurm-{{ slurm_version }}.tar.bz2"
    dest: /tmp
    remote_src: yes
    creates: "{{ slurm_dir }}/bin/srun"

- name: stat srun
  stat: path="{{ slurm_dir }}/bin/srun"
  register: stat_srun


- name: configure slurm
  command: /tmp/slurm-{{ slurm_version }}/configure --prefix={{ slurm_dir }} --with-munge={{ munge_dir }} --enable-pam --with-pmix=/usr/local/pmix/latest
  args:
    creates: "{{ slurm_dir }}/bin/srun"
    chdir: /tmp/slurm-{{ slurm_version }}
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: build slurm
  command: make
  args:
    creates: "{{ slurm_dir }}/bin/srun"
    chdir: /tmp/slurm-{{ slurm_version }}
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: install slurm
  shell: make install
  sudo: true
  args:
    chdir: /tmp/slurm-{{ slurm_version }}
    creates: "{{ slurm_dir }}/bin/srun"
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: build pmi
  command: make
  args:
    chdir: /tmp/slurm-{{ slurm_version }}/contribs/pmi
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: install pmi
  shell: make install
  sudo: true
  args:
    chdir: /tmp/slurm-{{ slurm_version }}/contribs/pmi
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: build pmi2
  command: make
  args:
    chdir: /tmp/slurm-{{ slurm_version }}/contribs/pmi2
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: install pmi2
  shell: make install
  sudo: true
  args:
    chdir: /tmp/slurm-{{ slurm_version }}/contribs/pmi2
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: build pam_slurm
  command: make
  args:
    chdir: /tmp/slurm-{{ slurm_version }}/contribs/pam
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: install pam_slurm
  shell: make install
  sudo: true
  args:
    chdir: /tmp/slurm-{{ slurm_version }}/contribs/pam
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: build pam_slurm_adopt
  make:
    chdir: /tmp/slurm-{{ slurm_version }}/contribs/pam_slurm_adopt
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: install pam_slurm_adopt
  make:
    chdir: /tmp/slurm-{{ slurm_version }}/contribs/pam_slurm_adopt
    target: install
  when: force_slurm_recompile is defined or not stat_srun.stat.exists
  sudo: true

- name: remove exist-slurm-latest-link
  shell: unlink  /opt/slurm-latest
  sudo: true
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: put slurm-latest-link
  shell: ln -s  {{ slurm_dir }}  /opt/slurm-latest
  sudo: true
  when: force_slurm_recompile is defined or not stat_srun.stat.exists

- name: add slurm log rotate config
  template: src=slurmlog.j2 dest=/etc/logrotate.d/slurm mode=644
  sudo: true
