---
- include_vars: "{{ ansible_os_family }}.yml"

- name: install lua centos
  yum: name={{ item }} state=installed update_cache=yes
  with_items:
    - lua
    - lua-filesystem
    - lua-posix
    - tcl
    - rsync
    - gcc
    - lua-devel
  become: true
  when: ansible_os_family == 'RedHat'

- name: install lua RHEL7
  yum: name={{ item }} state=installed update_cache=yes enablerepo="Monash_University_EPEL7_EPEL_7_-_x86_64"
  with_items:
    - lua
    - lua-filesystem
    - lua-posix
    - tcl
    - rsync
    - gcc
    - lua-devel
  when:
   - '"DGX" in ansible_product_name'
   - '"RedHat" in ansible_distribution'
  become: true

- name: install lua debian
  apt: name=lmod state=installed
  become: true
  when: ansible_os_family == 'Debian'

- name: stat lmod
  stat: path="{{ soft_dir }}/lmod/{{ lmod_version }}"
  register: lmodstat

- name: Download LMOD
  get_url:
    url=http://consistency0/src/Lmod-{{ lmod_version }}.tar.bz2
    dest={{ source_dir }}/Lmod-{{ lmod_version }}.tar.bz2
    mode=0444
  when: ansible_os_family == 'RedHat' and not lmodstat.stat.exists

- name: Uncompress LMOD
  unarchive:
    src={{ source_dir }}/Lmod-{{ lmod_version }}.tar.bz2
    dest={{ source_dir }}
    copy=no
    creates={{ source_dir }}/Lmod-{{ lmod_version }}/README
  when: ansible_os_family == 'RedHat' and not lmodstat.stat.exists

- name: Compile and install Lmod
  shell: cd {{ source_dir }}/Lmod-{{ lmod_version }}; ./configure --prefix={{ soft_dir }} --with-mpathSearch=YES --with-caseIndependentSorting=YES && make install LUA_INCLUDE={{ lua_include }}
  args:
    creates: "{{ soft_dir }}/lmod/{{ lmod_version }}"
  become: true
  when: ansible_os_family == 'RedHat'