diff --git a/.docs/role_documentation_generator b/.docs/role_documentation_generator index 37f6cf5..e64fffb 100755 --- a/.docs/role_documentation_generator +++ b/.docs/role_documentation_generator @@ -40,52 +40,53 @@ if __name__ == "__main__": roles_rst.append("") # options - roles_rst.extend(["`Variables`", "^^^^^^^^^^^", ""]) - for option in specs["argument_specs"]["main"]["options"]: - roles_rst.extend([ - ".. _{}_variable:".format(option), - "", - "``{}``".format(option), - '"' * (len(option) + 4), - "", - ":Type: **{}**".format( - specs["argument_specs"]["main"]["options"][option]["type"] - ), - "", - ":Required: **{}**".format( - json_dumps( - specs["argument_specs"]["main"]["options"][option]["required"] - ) - ), - "", - ]) - if "choices" in specs["argument_specs"]["main"]["options"][option]: + if "options" in specs["argument_specs"]["main"]: + roles_rst.extend(["`Variables`", "^^^^^^^^^^^", ""]) + for option in specs["argument_specs"]["main"]["options"]: roles_rst.extend([ - ":Allowed Values: ``{}``".format( - json_dumps(specs["argument_specs"]["main"]["options"][option]["choices"]) - ) - ]) - if (not specs["argument_specs"]["main"]["options"][option]["required"] and - "default" in specs["argument_specs"]["main"]["options"][option]): - roles_rst.extend([ - ":Default: ``{}``".format( + ".. _{}_variable:".format(option), + "", + "``{}``".format(option), + '"' * (len(option) + 4), + "", + ":Type: **{}**".format( + specs["argument_specs"]["main"]["options"][option]["type"] + ), + "", + ":Required: **{}**".format( json_dumps( - specs["argument_specs"]["main"]["options"][option]["default"] + specs["argument_specs"]["main"]["options"][option]["required"] ) ), "", ]) - roles_rst.extend([ - ":Description: {}".format( - specs["argument_specs"]["main"]["options"][option]["description"] - ), - "", - ]) - if "raw" in specs["argument_specs"]["main"]["options"][option]: + if "choices" in specs["argument_specs"]["main"]["options"][option]: + roles_rst.extend([ + ":Allowed Values: ``{}``".format( + json_dumps(specs["argument_specs"]["main"]["options"][option]["choices"]) + ) + ]) + if (not specs["argument_specs"]["main"]["options"][option]["required"] and + "default" in specs["argument_specs"]["main"]["options"][option]): + roles_rst.extend([ + ":Default: ``{}``".format( + json_dumps( + specs["argument_specs"]["main"]["options"][option]["default"] + ) + ), + "", + ]) roles_rst.extend([ - specs["argument_specs"]["main"]["options"][option]["raw"], + ":Description: {}".format( + specs["argument_specs"]["main"]["options"][option]["description"] + ), "", ]) + if "raw" in specs["argument_specs"]["main"]["options"][option]: + roles_rst.extend([ + specs["argument_specs"]["main"]["options"][option]["raw"], + "", + ]) print("--- writing out documentation for NSP roles ---") out_dir = Path(__file__).parent.joinpath("source/reference") diff --git a/.docs/source/starting/setup.rst b/.docs/source/starting/setup.rst index eb6f2c0..0418436 100644 --- a/.docs/source/starting/setup.rst +++ b/.docs/source/starting/setup.rst @@ -377,7 +377,7 @@ We will name our spack environments according to the following schema ``core /dev/null 2>&1 - if [ "$?" -eq 0 ]; then - module --initial_load --no_redirect restore - fi - path: "{{ [NSP_install_root, 'init', 'profile'] | path_join }}" - owner: "{{ NSP_user }}" - group: "{{ NSP_group }}" - mode: "{{ NSP_file_permissions }}" - marker: "# {mark} LMOD MANAGED" - append_newline: true - prepend_newline: true - tags: - - lmod - -- name: Insert LMOD Init cshrc Configuration - ansible.builtin.blockinfile: - block: | - setenv LMOD_SYSTEM_NAME {{ NSP_system_name }} - setenv LMOD_PACKAGE_PATH {{ [NSP_install_root, 'lmod/hooks'] | path_join }} - setenv LMOD_AVAIL_STYLE nsp-pretty:system - setenv LMOD_MODULERCFILE {{ [NSP_install_root, 'lmod/etc/rc.lua'] | path_join }} - setenv LMOD_ADMIN_FILE {{ [NSP_install_root, 'lmod/etc/admin.list'] | path_join }} - setenv LMOD_RC {{ [NSP_install_root, 'lmod/etc/lmodrc.lua'] | path_join }} - - type module >&/dev/null - if ($status == 0) then - module --initial_load --no_redirect restore - endif - path: "{{ [NSP_install_root, 'init', 'cshrc'] | path_join }}" - owner: "{{ NSP_user }}" - group: "{{ NSP_group }}" - mode: "{{ NSP_file_permissions }}" - marker: "# {mark} LMOD MANAGED" - append_newline: true - prepend_newline: true - tags: - - lmod diff --git a/lmod/tasks/internal.yaml b/lmod/tasks/internal.yaml index 3dbca63..da12b9c 100644 --- a/lmod/tasks/internal.yaml +++ b/lmod/tasks/internal.yaml @@ -31,61 +31,3 @@ mode: "{{ NSP_file_permissions }}" tags: - lmod - -- name: Insert LMOD Init profile Configuration - ansible.builtin.blockinfile: - block: | - type module > /dev/null 2>&1 - if [ "$?" -eq 0 ]; then - clearLmod -q > /dev/null 2>&1 - unset LMOD_MODULEPATH_INIT - fi - - export LMOD_SYSTEM_NAME={{ NSP_system_name }} - export LMOD_SYSTEM_DEFAULT_MODULES=DefApps - export LMOD_PACKAGE_PATH={{ [NSP_install_root, 'lmod/hooks'] | path_join }} - export LMOD_AVAIL_STYLE=nsp-pretty:system - export LMOD_MODULERCFILE={{ [NSP_install_root, 'lmod/etc/rc.lua'] | path_join }} - export LMOD_ADMIN_FILE={{ [NSP_install_root, 'lmod/etc/admin.list'] | path_join }} - export LMOD_RC={{ [NSP_install_root, 'lmod/etc/lmodrc.lua'] | path_join }} - - source {{ [NSP_install_root, 'lmod/lmod/init/profile'] | path_join }} - module --initial_load --no_redirect restore - path: "{{ [NSP_install_root, 'init', 'profile'] | path_join }}" - owner: "{{ NSP_user }}" - group: "{{ NSP_group }}" - mode: "{{ NSP_file_permissions }}" - marker: "# {mark} LMOD MANAGED" - append_newline: true - prepend_newline: true - tags: - - lmod - -- name: Insert LMOD Init cshrc Configuration - ansible.builtin.blockinfile: - block: | - type module >&/dev/null - if ($status == 0) then - clearLmod -q >&/dev/null - unset LMOD_MODULEPATH_INIT - endif - - setenv LMOD_SYSTEM_NAME {{ NSP_system_name }} - setenv LMOD_SYSTEM_DEFAULT_MODULES DefApps - setenv LMOD_PACKAGE_PATH {{ [NSP_install_root, 'lmod/hooks'] | path_join }} - setenv LMOD_AVAIL_STYLE nsp-pretty:system - setenv LMOD_MODULERCFILE {{ [NSP_install_root, 'lmod/etc/rc.lua'] | path_join }} - setenv LMOD_ADMIN_FILE {{ [NSP_install_root, 'lmod/etc/admin.list'] | path_join }} - setenv LMOD_RC {{ [NSP_install_root, 'lmod/etc/lmodrc.lua'] | path_join }} - - source {{ [NSP_install_root, 'lmod/lmod/init/cshrc'] | path_join }} - module --initial_load --no_redirect restore - path: "{{ [NSP_install_root, 'init', 'cshrc'] | path_join }}" - owner: "{{ NSP_user }}" - group: "{{ NSP_group }}" - mode: "{{ NSP_file_permissions }}" - marker: "# {mark} LMOD MANAGED" - append_newline: true - prepend_newline: true - tags: - - lmod diff --git a/lmod/tasks/main.yaml b/lmod/tasks/main.yaml index 6377477..97f8793 100644 --- a/lmod/tasks/main.yaml +++ b/lmod/tasks/main.yaml @@ -31,6 +31,19 @@ tags: - lmod +- name: Generate LMOD Init Scripts + ansible.builtin.template: + src: "{{ item }}.j2" + dest: "{{ [NSP_install_root, 'lmod/etc/{}'.format(item)] | path_join }}" + owner: "{{ NSP_user }}" + group: "{{ NSP_group }}" + mode: "{{ NSP_executable_permissions }}" + loop: + - profile + - cshrc + tags: + - lmod + - name: Generate LMOD Configuration Files ansible.builtin.template: src: "{{ [playbook_dir, 'lmod/{}.j2'.format(item)] | path_join }}" @@ -81,10 +94,3 @@ when: NSP_LMOD_install_type == "internal" tags: - lmod - -- name: Included External LMOD Tasks - ansible.builtin.include_tasks: - file: external.yaml - when: NSP_LMOD_install_type == "external" - tags: - - lmod diff --git a/lmod/templates/DefApps.lua.j2 b/lmod/templates/DefApps.lua.j2 index 7ddcc84..e409748 100644 --- a/lmod/templates/DefApps.lua.j2 +++ b/lmod/templates/DefApps.lua.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} {% for module in NSP_LMOD_DefApps_modules %} try_load("{{ module }}") diff --git a/lmod/templates/NSPHierarchyHook.lua.j2 b/lmod/templates/NSPHierarchyHook.lua.j2 index f4da805..7a3aa28 100644 --- a/lmod/templates/NSPHierarchyHook.lua.j2 +++ b/lmod/templates/NSPHierarchyHook.lua.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} -------------------------------------------------------------------------- -- NSP provided hooks diff --git a/lmod/templates/NSPLoggingHook.lua.j2 b/lmod/templates/NSPLoggingHook.lua.j2 index 53289ec..0d369c8 100644 --- a/lmod/templates/NSPLoggingHook.lua.j2 +++ b/lmod/templates/NSPLoggingHook.lua.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} local json = require("json") local cosmic = require("Cosmic"):singleton() diff --git a/lmod/templates/SitePackage.lua.j2 b/lmod/templates/SitePackage.lua.j2 index c5b8d38..0ba39ed 100644 --- a/lmod/templates/SitePackage.lua.j2 +++ b/lmod/templates/SitePackage.lua.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} -------------------------------------------------------------------------- -- @module SitePackage diff --git a/lmod/templates/cshrc.j2 b/lmod/templates/cshrc.j2 new file mode 100644 index 0000000..d4bd30a --- /dev/null +++ b/lmod/templates/cshrc.j2 @@ -0,0 +1,30 @@ +#!/usr/bin/env csh +{{ NSP_template_header | comment(beginning='##', end='##', decoration='#', prefix_count=0, postfix_count=0) }} + +# common variables +setenv LMOD_SYSTEM_NAME {{ NSP_system_name }} +setenv LMOD_PACKAGE_PATH {{ [NSP_install_root, 'lmod/hooks'] | path_join }} +setenv LMOD_AVAIL_STYLE nsp-pretty:system +setenv LMOD_MODULERCFILE {{ [NSP_install_root, 'lmod/etc/rc.lua'] | path_join }} +setenv LMOD_ADMIN_FILE {{ [NSP_install_root, 'lmod/etc/admin.list'] | path_join }} +setenv LMOD_RC {{ [NSP_install_root, 'lmod/etc/lmodrc.lua'] | path_join }} + +{% if NSP_LMOD_install_type == "internal" %} +# LMOD configuration for internal install +setenv LMOD_SYSTEM_DEFAULT_MODULES DefApps + +type module >&/dev/null +if ($status == 0) then + clearLmod -q >&/dev/null + unset LMOD_MODULEPATH_INIT +endif + +source {{ [NSP_install_root, 'lmod/lmod/init/cshrc'] | path_join }} +module --initial_load --no_redirect restore +{% elif NSP_LMOD_install_type == "external" %} +# LMOD configuration for external install +type module >&/dev/null +if ($status == 0) then + module --initial_load --no_redirect restore +endif +{% endif %} diff --git a/lmod/templates/modulepath.default.j2 b/lmod/templates/modulepath.default.j2 index 48dfd1f..edbf2eb 100644 --- a/lmod/templates/modulepath.default.j2 +++ b/lmod/templates/modulepath.default.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning='##', end='##', decoration='#', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='##', end='##', decoration='#', prefix_count=0, postfix_count=0) }} {% for path in NSP_LMOD_default_module_paths %} {{ path }} diff --git a/lmod/templates/profile.j2 b/lmod/templates/profile.j2 new file mode 100644 index 0000000..c7b2151 --- /dev/null +++ b/lmod/templates/profile.j2 @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +{{ NSP_template_header | comment(beginning='##', end='##', decoration='#', prefix_count=0, postfix_count=0) }} + +# common variables +export LMOD_SYSTEM_NAME={{ NSP_system_name }} +export LMOD_PACKAGE_PATH={{ [NSP_install_root, 'lmod/hooks'] | path_join }} +export LMOD_AVAIL_STYLE=nsp-pretty:system +export LMOD_MODULERCFILE={{ [NSP_install_root, 'lmod/etc/rc.lua'] | path_join }} +export LMOD_ADMIN_FILE={{ [NSP_install_root, 'lmod/etc/admin.list'] | path_join }} +export LMOD_RC={{ [NSP_install_root, 'lmod/etc/lmodrc.lua'] | path_join }} + + +{% if NSP_LMOD_install_type == "internal" %} +# LMOD configuration for internal install +export LMOD_SYSTEM_DEFAULT_MODULES=DefApps + +type module > /dev/null 2>&1 +if [ "$?" -eq 0 ]; then + clearLmod -q > /dev/null 2>&1 + unset LMOD_MODULEPATH_INIT +fi + +source {{ [NSP_install_root, 'lmod/lmod/init/profile'] | path_join }} +module --initial_load --no_redirect restore +{% elif NSP_LMOD_install_type == "external" %} +# LMOD configuration for external install +type module > /dev/null 2>&1 +if [ "$?" -eq 0 ]; then + module --initial_load --no_redirect restore +fi +{% endif %} diff --git a/miniforge3/templates/condarc.j2 b/miniforge3/templates/condarc.j2 index a20a62f..925cd16 100644 --- a/miniforge3/templates/condarc.j2 +++ b/miniforge3/templates/condarc.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning='##', end='##', decoration='#', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='##', end='##', decoration='#', prefix_count=0, postfix_count=0) }} pkgs_dirs: - ~/.conda/pkgs diff --git a/miniforge3/templates/module.lua.j2 b/miniforge3/templates/module.lua.j2 index 54eacc4..f1de268 100644 --- a/miniforge3/templates/module.lua.j2 +++ b/miniforge3/templates/module.lua.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} family("python") diff --git a/nsp/defaults/main.yaml b/nsp/defaults/main.yaml index 762d979..7f5c9df 100644 --- a/nsp/defaults/main.yaml +++ b/nsp/defaults/main.yaml @@ -17,3 +17,17 @@ NSP_file_permissions: "644" NSP_executable_permissions: "755" NSP_architecture: "{{ ansible_architecture }}" + +NSP_template_header: |- + | WARNING! This file is managed by Ansible. + | Do NOT make manual changes to this file. + | Please email {{ NSP_help_email }} to request a change. + + | Info: + | Role: {{ ansible_role_name }} + {% if (template_path is defined) and (playbook_dir is defined) and (playbook_dir in template_path) %} + | {{ NSP_site_name }} Template: {{ template_path.replace(playbook_dir, '').lstrip('/') }} + {% elif template_path is defined %} + | NSP Template: {{ template_path }} + {% endif %} + | User: {{ ansible_user_id }} diff --git a/nsp/meta/argument_specs.yaml b/nsp/meta/argument_specs.yaml index 5d4c203..8d237a9 100644 --- a/nsp/meta/argument_specs.yaml +++ b/nsp/meta/argument_specs.yaml @@ -65,6 +65,23 @@ argument_specs: required: false default: "{{ ansible_architecture }}" description: Hardware architecture to target. + NSP_template_header: + type: str + required: false + default: |- + | WARNING! This file is managed by Ansible. + | Do NOT make manual changes to this file. + | Please email {{ NSP_help_email }} to request a change. + + | Info: + | Role: {{ ansible_role_name }} + {% if (template_path is defined) and (playbook_dir is defined) and (playbook_dir in template_path) %} + | {{ NSP_site_name }} Template: {{ template_path.replace(playbook_dir, '').lstrip('/') }} + {% elif template_path is defined %} + | NSP Template: {{ template_path }} + {% endif %} + | User: {{ ansible_user_id }} + description: A jinja string to use as the header in templates. clear_scratch: description: - "Clears the scratch directory." diff --git a/nsp/tasks/main.yaml b/nsp/tasks/main.yaml index a866e5b..79ec29e 100644 --- a/nsp/tasks/main.yaml +++ b/nsp/tasks/main.yaml @@ -8,6 +8,6 @@ recurse: false changed_when: false tags: - - nps + - nsp - meta - always diff --git a/nvhpc/templates/module.lua.j2 b/nvhpc/templates/module.lua.j2 index a9cbaa6..de2c0db 100644 --- a/nvhpc/templates/module.lua.j2 +++ b/nvhpc/templates/module.lua.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} family("compiler") diff --git a/oneapi/templates/module.lua.j2 b/oneapi/templates/module.lua.j2 index 5b6e175..4f9f769 100644 --- a/oneapi/templates/module.lua.j2 +++ b/oneapi/templates/module.lua.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} {% if "intel.oneapi.lin.dpcpp-cpp-compiler" in NSP_ONEAPI_base_toolkit_components or "intel.oneapi.lin.ifort-compiler" in NSP_ONEAPI_hpc_toolkit_components %} family("compiler") diff --git a/openmpi/templates/module.lua.j2 b/openmpi/templates/module.lua.j2 index ff567bb..429bd61 100644 --- a/openmpi/templates/module.lua.j2 +++ b/openmpi/templates/module.lua.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='--[[', end=']]--', decoration='', prefix_count=0, postfix_count=0) }} family("mpi") diff --git a/spack/templates/spacktivate.sh.j2 b/spack/templates/spacktivate.sh.j2 index 0804349..e216128 100644 --- a/spack/templates/spacktivate.sh.j2 +++ b/spack/templates/spacktivate.sh.j2 @@ -1,5 +1,5 @@ #!/bin/bash -{{ ansible_managed | comment(beginning='##', end='##', decoration='#', prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning='##', end='##', decoration='#', prefix_count=0, postfix_count=0) }} # Only run if the script is being sourced if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then diff --git a/xalt/templates/module.lua.j2 b/xalt/templates/module.lua.j2 index 5ddd644..3deb3b1 100644 --- a/xalt/templates/module.lua.j2 +++ b/xalt/templates/module.lua.j2 @@ -1,4 +1,4 @@ -{{ ansible_managed | comment(beginning="--[[", end="]]--", decoration="", prefix_count=0, postfix_count=0) }} +{{ NSP_template_header | comment(beginning="--[[", end="]]--", decoration="", prefix_count=0, postfix_count=0) }} local base = "{{ [NSP_install_root, 'xalt', NSP_XALT_git_reference] | path_join }}" local bin = pathJoin(base, "bin")