This playbook installs Lmod natively on the host system and configures baseline module hierarchy paths.
- name: Configure Lmod host
hosts: lmod
become: true
vars:
lmod_user: root
lmod_group: root
modulefiles_path: /apps/modulefiles
site_module_path: /etc/lmod/modules
tasks:
- name: Install lmod package
ansible.builtin.package:
name: lmod
state: present
- name: Ensure site module tree exists
ansible.builtin.file:
path: "{{ modulefiles_path }}"
state: directory
owner: "{{ lmod_user }}"
group: "{{ lmod_group }}"
mode: "0755"
- name: Ensure site module path exists
ansible.builtin.file:
path: "{{ site_module_path }}"
state: directory
owner: "{{ lmod_user }}"
group: "{{ lmod_group }}"
mode: "0755"
- name: Configure Lmod MODULEPATH
ansible.builtin.copy:
dest: /etc/lmod/init/lmod.sh
mode: "0644"
content: |
# Lmod initialization script
export LMOD_ROOT=/usr/share/lmod
export MODULEPATH={{ modulefiles_path }}:$MODULEPATH
export LMOD_DIR={{ modulefiles_path }}
export LMOD_CACHE_DIR=/tmp/lmodcache
# Source Lmod initialization
. $LMOD_ROOT/lmod/init/profile
- name: Create example compiler modulefile
ansible.builtin.copy:
dest: "{{ modulefiles_path }}/Compiler/gcc/11.2.0.lua"
mode: "0644"
content: |
help([[
This module loads the GCC compiler toolchain version 11.2.0
]])
local pkgname = "gcc"
local pkgversion = "11.2.0"
local pkgpath = pathJoin("/opt/compilers", pkgname, pkgversion)
prepend_path("PATH", pathJoin(pkgpath, "bin"))
prepend_path("LD_LIBRARY_PATH", pathJoin(pkgpath, "lib64"))
prepend_path("CPATH", pathJoin(pkgpath, "include"))
prepend_path("LIBRARY_PATH", pathJoin(pkgpath, "lib64"))
setenv("GCC_VERSION", pkgversion)
setenv("CC", "gcc")
setenv("CXX", "g++")
setenv("FC", "gfortran")
- name: Verify Lmod command
ansible.builtin.shell: . /etc/profile.d/lmod.sh && module --version
args:
executable: /bin/bash
register: lmod_version
changed_when: false
- name: Show Lmod version output
ansible.builtin.debug:
var: lmod_version.stdout_lines
- name: List available modules
ansible.builtin.shell: . /etc/profile.d/lmod.sh && module avail
args:
executable: /bin/bash
register: module_avail
changed_when: false
- name: Show available modules
ansible.builtin.debug:
var: module_avail.stderr_lines