# Using envionment modules with cylc

**URL:** https://cylc.discourse.group/t/using-envionment-modules-with-cylc/321
**Category:** Cylc Support
**Created:** [April 9, 2021, 7:02pm UTC](https://cylc.discourse.group/t/using-envionment-modules-with-cylc/321 "2021-04-09T19:02:06Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Jim](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jim/32/60_2.png) [@Jim](https://cylc.discourse.group/u/Jim)
#### Post date: [April 9, 2021, 7:02pm UTC](https://cylc.discourse.group/t/using-envionment-modules-with-cylc/321/1 "2021-04-09T19:02:07Z")

</div>

I am using Modules ([https://lmod.readthedocs.io](https://lmod.readthedocs.io)) to load an environment that I would like to have available to the cylc suite.  
Can I do this in jinja2? or otherwise load the module in a way that the suite would use those values when run?

---

<div class="post-metadata">

### Author: ![Jim](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jim/32/60_2.png) [@Jim](https://cylc.discourse.group/u/Jim)
#### Post date: [April 9, 2021, 7:51pm UTC](https://cylc.discourse.group/t/using-envionment-modules-with-cylc/321/2 "2021-04-09T19:51:53Z")

</div>

I figured out how to set what I need in jinja2. But it leads to another question:

Or maybe I need to turn this on it’s head - can I register a cylc suite from a Module?

---

<div class="post-metadata">

### Author: ![hilary.j.oliver](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/hilary.j.oliver/32/4_2.png) [@hilary.j.oliver](https://cylc.discourse.group/u/hilary.j.oliver)
#### Post date: [April 11, 2021, 9:18pm UTC](https://cylc.discourse.group/t/using-envionment-modules-with-cylc/321/3 "2021-04-11T21:18:02Z")

</div>

I’m not sure I understand your last question (“can I register a cylc suite from a Module?”). As I understand it, Modules are put in place by system admins, to configure user environments by setting environment variables to provide access to particular software packages. Which doesn’t sound like an appropriate place to register Cylc suites.

Anyhow, do you want the environment modules to affect the behavior of your Cylc schedulers, or of the jobs that they execute? If the latter, you can use `module load` etc. in job scripting, just as you would in the terminal.

---

<div class="post-metadata">

### Author: ![Jim](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jim/32/60_2.png) [@Jim](https://cylc.discourse.group/u/Jim)
#### Post date: [April 14, 2021, 10:15pm UTC](https://cylc.discourse.group/t/using-envionment-modules-with-cylc/321/4 "2021-04-14T22:15:55Z")

</div>

Modules are not just for sys-admin types, you can write and use them as a user and they can be quite handy. We have several suites set up to use the same suite.rc file and just accept different inputs.  
Currently I have that set of inputs at the top of the suite.rc file as jinja variables but I would like to  
move them out of the suite file into there own file so that instead of editing the suite file the user can just load the module associated with the suite they want to run. So I want the Modules to affect both the scheduler and the jobs they execute. I just found the --set-file argument to cylc run which may be what I need.

---

<div class="post-metadata">

### Author: ![oliver.sanders](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/oliver.sanders/32/110_2.png) [@oliver.sanders](https://cylc.discourse.group/u/oliver.sanders)
#### Post date: [April 15, 2021, 8:31am UTC](https://cylc.discourse.group/t/using-envionment-modules-with-cylc/321/5 "2021-04-15T08:31:57Z")

</div>

Sounds like the problem is providing multiple alternative configurations of a workflow and an easy way of switching between them.

Having multiple “configurations” or “modes” for a single workflow is a common requirements and Cylc has some built-in ways of achieving this:

1. Cylc “set files”

2. Dynamic imports.

3. Rose optional configurations.

---

<div class="post-metadata">

### Author: ![Jim](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/jim/32/60_2.png) [@Jim](https://cylc.discourse.group/u/Jim)
#### Post date: [April 15, 2021, 3:20pm UTC](https://cylc.discourse.group/t/using-envionment-modules-with-cylc/321/6 "2021-04-15T15:20:57Z")

</div>

Thank you - I am trying to use method 2 but it only seems to use the default values. I get an error if I include a non-existent file so I think that the file is being read, but only the default values get set.

---

<div class="post-metadata">

### Author: ![oliver.sanders](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/oliver.sanders/32/110_2.png) [@oliver.sanders](https://cylc.discourse.group/u/oliver.sanders)
#### Post date: [April 16, 2021, 8:48am UTC](https://cylc.discourse.group/t/using-envionment-modules-with-cylc/321/7 "2021-04-16T08:48:10Z")

</div>

Whoops, sorry, I made a mistake in my code above, I meant imports not includes, fixed now.

- [Includes](https://jinja.palletsprojects.com/en/2.11.x/templates/#include) bring through the text (i.e. the Cylc configuration) from another file.

- [Imports](https://jinja.palletsprojects.com/en/2.11.x/templates/#import) bring through the Jinja2 things from another file.

There’s [one other quirk](https://jinja.palletsprojects.com/en/2.11.x/templates/#import-context-behavior) to Jinja2 includes/imports to be aware of:

- “with context” lets variables pass into the other file.

- “without context” (default) doesn’t.
